persistent-cache-cpp: /build/persistent-cache-cpp-git/src/persistent-cache-cpp/include/core/cache_events.h Source File

persistent-cache-cpp

cache_events.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Michi Henning <michi.henning@canonical.com>
17 */
18
19 #pragma once
20
21 #include <cstdint>
22 #include <type_traits>
23
28 namespace core
29 {
30
35 // Note: Any change here must have a corresponding change to
36 // CacheEventIndex in core/internal/cache_event_indexes.h!
37
38 enum class CacheEvent : uint32_t
39 {
40 get = 1 << 0,
41 put = 1 << 1,
42 invalidate = 1 << 2,
43 touch = 1 << 3,
44 miss = 1 << 4,
45 evict_ttl = 1 << 5,
46 evict_lru = 1 << 6,
48 END_ = 1 << 7
50 };
51
55 inline CacheEvent operator|(CacheEvent left, CacheEvent right)
56 {
57 auto l = std::underlying_type<CacheEvent>::type(left);
58 auto r = std::underlying_type<CacheEvent>::type(right);
59 return CacheEvent(l | r);
60 }
61
65 inline CacheEvent& operator|=(CacheEvent& left, CacheEvent right)
66 {
67 return left = left | right;
68 }
69
73 inline CacheEvent operator&(CacheEvent left, CacheEvent right)
74 {
75 auto l = std::underlying_type<CacheEvent>::type(left);
76 auto r = std::underlying_type<CacheEvent>::type(right);
77 return CacheEvent(l & r);
78 }
79
83 inline CacheEvent& operator&=(CacheEvent& left, CacheEvent right)
84 {
85 return left = left & right;
86 }
87
91 inline CacheEvent operator~(CacheEvent ev)
92 {
93 auto mask = std::underlying_type<CacheEvent>::type(CacheEvent::END_) - 1;
94 auto event = std::underlying_type<CacheEvent>::type(ev);
95 return CacheEvent(~event & mask);
96 }
97
101 static constexpr auto AllCacheEvents = CacheEvent(std::underlying_type<CacheEvent>::type(CacheEvent::END_) - 1);
102
103 } // namespace core
core::CacheEvent::touch
@ touch
An entry was refreshed by a call to touch().
core::CacheEvent::put
@ put
An entry was added by a call to put() or get_or_put().
core::operator|=
CacheEvent & operator|=(CacheEvent &left, CacheEvent right)
Assigns the bitwise OR of left and right to left.
Definition: cache_events.h:65
core::operator|
CacheEvent operator|(CacheEvent left, CacheEvent right)
Returns the bitwise OR of two event types.
Definition: cache_events.h:55
core::CacheEvent::invalidate
@ invalidate
An entry was removed by a call to invalidate(), take(), or take_data().
core
Top-level namespace for core functionality.
Definition: cache_codec.h:24
core::operator&=
CacheEvent & operator&=(CacheEvent &left, CacheEvent right)
Assigns the bitwise AND of left and right to left.
Definition: cache_events.h:83
core::operator&
CacheEvent operator&(CacheEvent left, CacheEvent right)
Returns the bitwise AND of two event types.
Definition: cache_events.h:73
core::CacheEvent::get
@ get
An entry was returned by a call to get(), get_or_put(), take(), or take_data().
core::operator~
CacheEvent operator~(CacheEvent ev)
Returns the bitwise NOT of ev. Unused bits are set to zero.
Definition: cache_events.h:91
core::CacheEvent
CacheEvent
Event types that can be monitored.
Definition: cache_events.h:39