diff options
author | Richard Braun <rbraun@sceen.net> | 2017-01-25 00:36:45 +0100 |
---|---|---|
committer | Richard Braun <rbraun@sceen.net> | 2017-01-25 00:36:45 +0100 |
commit | c204a2eacf870a05f1ccde63e4da452017b6e2f5 (patch) | |
tree | 69e99afad23e633d3053851d661264a597e9285b /kern/sref.h | |
parent | a4746bfe8f174bf90777419a539b49914942b20d (diff) |
kern/sref: implement weak references
Diffstat (limited to 'kern/sref.h')
-rw-r--r-- | kern/sref.h | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/kern/sref.h b/kern/sref.h index 3f6e39ad..ac16b13d 100644 --- a/kern/sref.h +++ b/kern/sref.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 @@ -31,9 +31,17 @@ #ifndef _KERN_SREF_H #define _KERN_SREF_H +/* + * Scalable reference counter. + */ struct sref_counter; /* + * Weak reference. + */ +struct sref_weakref; + +/* * Type for no-reference functions. */ typedef void (*sref_noref_fn_t)(struct sref_counter *); @@ -86,7 +94,9 @@ void sref_report_periodic_event(void); * The counter is set to 1. The no-reference function is called (from thread * context) when it is certain that the true number of references is 0. */ -void sref_counter_init(struct sref_counter *counter, sref_noref_fn_t noref_fn); +void sref_counter_init(struct sref_counter *counter, + struct sref_weakref *weakref, + sref_noref_fn_t noref_fn); /* * Counter operations. @@ -94,4 +104,12 @@ void sref_counter_init(struct sref_counter *counter, sref_noref_fn_t noref_fn); void sref_counter_inc(struct sref_counter *counter); void sref_counter_dec(struct sref_counter *counter); +/* + * Attempt to get a reference from a weak reference. + * + * If successful, increment the reference counter before returning it. + * Otherwise return NULL. + */ +struct sref_counter * sref_weakref_get(struct sref_weakref *weakref); + #endif /* _KERN_SREF_H */ |