cache_events.h
Go to the documentation of this file.
/*
* Copyright (C) 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: Michi Henning <michi.henning@canonical.com>
*/
#pragma once
#include <cstdint>
#include <type_traits>
namespace core
{
// Note: Any change here must have a corresponding change to
// CacheEventIndex in core/internal/cache_event_indexes.h!
enum class CacheEvent : uint32_t
{
get = 1 << 0,
put = 1 << 1,
invalidate = 1 << 2,
touch = 1 << 3,
miss = 1 << 4,
evict_ttl = 1 << 5,
evict_lru = 1 << 6,
END_ = 1 << 7
};
inline CacheEvent operator|(CacheEvent left, CacheEvent right)
{
auto l = std::underlying_type<CacheEvent>::type(left);
auto r = std::underlying_type<CacheEvent>::type(right);
return CacheEvent(l | r);
}
inline CacheEvent& operator|=(CacheEvent& left, CacheEvent right)
{
return left = left | right;
}
inline CacheEvent operator&(CacheEvent left, CacheEvent right)
{
auto l = std::underlying_type<CacheEvent>::type(left);
auto r = std::underlying_type<CacheEvent>::type(right);
return CacheEvent(l & r);
}
inline CacheEvent& operator&=(CacheEvent& left, CacheEvent right)
{
return left = left & right;
}
inline CacheEvent operator~(CacheEvent ev)
{
auto mask = std::underlying_type<CacheEvent>::type(CacheEvent::END_) - 1;
auto event = std::underlying_type<CacheEvent>::type(ev);
return CacheEvent(~event & mask);
}
static constexpr auto AllCacheEvents = CacheEvent(std::underlying_type<CacheEvent>::type(CacheEvent::END_) - 1);
} // namespace core
core::CacheEvent::touch
An entry was refreshed by a call to touch().
core::operator &
CacheEvent operator &(CacheEvent left, CacheEvent right)
Returns the bitwise AND of two event types.
Definition: cache_events.h:73
core::operator &=
CacheEvent & operator &=(CacheEvent &left, CacheEvent right)
Assigns the bitwise AND of left and right to left.
Definition: cache_events.h:83
core::CacheEvent
CacheEvent
Event types that can be monitored.
Definition: cache_events.h:38
core::operator~
CacheEvent operator~(CacheEvent ev)
Returns the bitwise NOT of ev. Unused bits are set to zero.
Definition: cache_events.h:91
core
Top-level namespace for core functionality.
Definition: cache_codec.h:23
core::CacheEvent::put
An entry was added by a call to put() or get_or_put().
core::CacheEvent::END_
End marker.
core::operator|=
CacheEvent & operator|=(CacheEvent &left, CacheEvent right)
Assigns the bitwise OR of left and right to left.
Definition: cache_events.h:65
core::CacheEvent::invalidate
An entry was removed by a call to invalidate(), take(), or take_data().
core::CacheEvent::evict_ttl
core::operator|
CacheEvent operator|(CacheEvent left, CacheEvent right)
Returns the bitwise OR of two event types.
Definition: cache_events.h:55
core::CacheEvent::miss
A call to get(), get_or_put(), take(), or take_data() failed to return an entry.
core::CacheEvent::evict_lru