[zion/glacier] Move RefCounted to glacier.
This commit is contained in:
parent
56eae3d4e5
commit
8bcb574677
|
@ -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
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/memory/ref_counted.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "lib/ref_ptr.h"
|
||||
|
@ -8,7 +9,7 @@
|
|||
class Process;
|
||||
class Thread;
|
||||
|
||||
class Capability : public RefCounted<Capability> {
|
||||
class Capability : public glcr::RefCounted<Capability> {
|
||||
public:
|
||||
Capability(const RefPtr<KernelObject>& obj, uint64_t permissions)
|
||||
: obj_(obj), permissions_(permissions) {}
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "debug/debug.h"
|
||||
|
||||
template <typename T>
|
||||
class RefCounted {
|
||||
public:
|
||||
RefCounted() {}
|
||||
~RefCounted() { dbgln("RefCounted object destroyed"); }
|
||||
void Adopt() {
|
||||
if (ref_count_ != -1) {
|
||||
panic("Adopting owned ptr");
|
||||
} else {
|
||||
ref_count_ = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void Acquire() {
|
||||
if (ref_count_ == -1) {
|
||||
panic("Acquiring unowned ptr");
|
||||
}
|
||||
ref_count_++;
|
||||
}
|
||||
bool Release() {
|
||||
if (ref_count_ == -1 || ref_count_ == 0) {
|
||||
panic("Releasing unowned ptr");
|
||||
}
|
||||
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;
|
||||
};
|
|
@ -1,8 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include "lib/ref_counted.h"
|
||||
#include <glacier/memory/ref_counted.h>
|
||||
|
||||
class KernelObject : public RefCounted<KernelObject> {
|
||||
class KernelObject : public glcr::RefCounted<KernelObject> {
|
||||
public:
|
||||
enum ObjectType {
|
||||
INVALID = 0x0,
|
||||
|
|
Loading…
Reference in New Issue