summaryrefslogtreecommitdiff
path: root/kern/sref_i.h
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2017-01-25 00:36:45 +0100
committerRichard Braun <rbraun@sceen.net>2017-01-25 00:36:45 +0100
commitc204a2eacf870a05f1ccde63e4da452017b6e2f5 (patch)
tree69e99afad23e633d3053851d661264a597e9285b /kern/sref_i.h
parenta4746bfe8f174bf90777419a539b49914942b20d (diff)
kern/sref: implement weak references
Diffstat (limited to 'kern/sref_i.h')
-rw-r--r--kern/sref_i.h19
1 files changed, 18 insertions, 1 deletions
diff --git a/kern/sref_i.h b/kern/sref_i.h
index 158ad42..1452bbc 100644
--- a/kern/sref_i.h
+++ b/kern/sref_i.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014 Richard Braun.
+ * Copyright (c) 2014-2017 Richard Braun.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,8 +19,24 @@
#define _KERN_SREF_I_H
#include <kern/spinlock.h>
+#include <kern/stdint.h>
#include <kern/work.h>
+#define SREF_WEAKREF_DYING ((uintptr_t)1)
+#define SREF_WEAKREF_MASK (~SREF_WEAKREF_DYING)
+
+/*
+ * Weak reference.
+ *
+ * A weak reference is a pointer to a reference counter in which the
+ * least-significant bit is used to indicate whether the counter is
+ * "dying", i.e. about to be destroyed. It must be accessed with atomic
+ * instructions.
+ */
+struct sref_weakref {
+ uintptr_t addr;
+};
+
#define SREF_QUEUED 0x1
#define SREF_DIRTY 0x2
@@ -39,6 +55,7 @@ struct sref_counter {
struct spinlock lock;
int flags;
unsigned long value;
+ struct sref_weakref *weakref;
};
struct work work;