[zion/glacier] Move RefCounted to glacier.

This commit is contained in:
Drew Galbraith 2023-06-21 14:52:40 -07:00
parent 56eae3d4e5
commit 8bcb574677
4 changed files with 33 additions and 44 deletions

View file

@ -0,0 +1,29 @@
#pragma once
#include <stdint.h>
namespace glcr {
template <typename T>
class RefCounted {
public:
RefCounted() {}
virtual ~RefCounted() {}
// FIXME: Rethink error handling in these cases now that we can't panic the
// kernel.
void Adopt() { ref_count_ = 1; }
void Acquire() { ref_count_++; }
bool Release() { return (--ref_count_) == 0; }
private:
// FIXME: This should be an atomic type.
uint64_t ref_count_ = -1;
// Disallow copy and move.
RefCounted(RefCounted&) = delete;
RefCounted(RefCounted&&) = delete;
RefCounted& operator=(RefCounted&) = delete;
RefCounted& operator=(RefCounted&&) = delete;
};
} // namespace glcr