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
28namespace core
29{
30
35// Note: Any change here must have a corresponding change to
36// CacheEventIndex in core/internal/cache_event_indexes.h!
37
38enum 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,
47 evict_lru = 1 << 6,
49 END_ = 1 << 7
50};
51
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
66{
67 return left = left | right;
68}
69
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
84{
85 return left = left & right;
86}
87
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
101static constexpr auto AllCacheEvents = CacheEvent(std::underlying_type<CacheEvent>::type(CacheEvent::END_) - 1);
102
103} // namespace core
Top-level namespace for core functionality.
Definition cache_codec.h:24
CacheEvent & operator&=(CacheEvent &left, CacheEvent right)
Assigns the bitwise AND of left and right to left.
Definition cache_events.h:83
CacheEvent & operator|=(CacheEvent &left, CacheEvent right)
Assigns the bitwise OR of left and right to left.
Definition cache_events.h:65
CacheEvent operator|(CacheEvent left, CacheEvent right)
Returns the bitwise OR of two event types.
Definition cache_events.h:55
CacheEvent operator&(CacheEvent left, CacheEvent right)
Returns the bitwise AND of two event types.
Definition cache_events.h:73
CacheEvent
Event types that can be monitored.
Definition cache_events.h:39
@ END_
End marker.
@ put
An entry was added by a call to put() or get_or_put().
@ get
An entry was returned by a call to get(), get_or_put(), take(), or take_data().
@ touch
An entry was refreshed by a call to touch().
@ invalidate
An entry was removed by a call to invalidate(), take(), or take_data().
@ miss
A call to get(), get_or_put(), take(), or take_data() failed to return an entry.
CacheEvent operator~(CacheEvent ev)
Returns the bitwise NOT of ev. Unused bits are set to zero.
Definition cache_events.h:91