diff options
Diffstat (limited to 'src/libthread/ref.c')
-rw-r--r-- | src/libthread/ref.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/libthread/ref.c b/src/libthread/ref.c new file mode 100644 index 00000000..30c932ed --- /dev/null +++ b/src/libthread/ref.c @@ -0,0 +1,27 @@ +#include "u.h" +#include "libc.h" +#include "thread.h" + +static long +refadd(Ref *r, long a) +{ + long ref; + + lock(&r->lock); + r->ref += a; + ref = r->ref; + unlock(&r->lock); + return ref; +} + +long +incref(Ref *r) +{ + return refadd(r, 1); +} + +long +decref(Ref *r) +{ + return refadd(r, -1); +} |