]>
git.proxmox.com Git - ceph.git/blob - ceph/src/common/item_history.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
11 Keep a history of item values so that readers can dereference the pointer to
12 the latest value and continue using it as long as they want. This container
13 is only appropriate for values that are updated a handful of times over their
19 class safe_item_history
{
27 history
.emplace_back(T());
28 current
= &history
.back();
31 // readers are lock-free
32 const T
& operator*() const {
35 const T
*operator->() const {
39 // writes are serialized
40 const T
& operator=(const T
& other
) {
41 std::lock_guard
l(lock
);
42 history
.push_back(other
);
43 current
= &history
.back();