diff options
author | Richard Braun <rbraun@sceen.net> | 2018-02-06 20:45:45 +0100 |
---|---|---|
committer | Richard Braun <rbraun@sceen.net> | 2018-02-07 01:08:53 +0100 |
commit | c04a26ee892d440979a84b891d6fac14cd4686f1 (patch) | |
tree | 0f59f0c1258f694d8a460e2ae6a874e8b002fa56 | |
parent | 6db72a1aeaddf038b12490fe9310a10693ffbf7a (diff) |
kern/sref: allow custom initial values
-rw-r--r-- | kern/sref.c | 5 | ||||
-rw-r--r-- | kern/sref.h | 5 |
2 files changed, 7 insertions, 3 deletions
diff --git a/kern/sref.c b/kern/sref.c index 404d993f..f145f80e 100644 --- a/kern/sref.c +++ b/kern/sref.c @@ -991,13 +991,16 @@ sref_report_periodic_event(void) void sref_counter_init(struct sref_counter *counter, + unsigned long init_value, struct sref_weakref *weakref, sref_noref_fn_t noref_fn) { + assert(init_value != 0); + counter->noref_fn = noref_fn; spinlock_init(&counter->lock); counter->flags = 0; - counter->value = 1; + counter->value = init_value; counter->weakref = weakref; if (weakref) { diff --git a/kern/sref.h b/kern/sref.h index 9cee283f..1d2a6356 100644 --- a/kern/sref.h +++ b/kern/sref.h @@ -77,10 +77,11 @@ void sref_report_periodic_event(void); /* * Initialize a scalable reference counter. * - * 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. + * 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, + unsigned long init_value, struct sref_weakref *weakref, sref_noref_fn_t noref_fn); |