diff options
Diffstat (limited to 'man/10/ref')
| -rw-r--r-- | man/10/ref | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/man/10/ref b/man/10/ref new file mode 100644 index 00000000..9a363f8c --- /dev/null +++ b/man/10/ref @@ -0,0 +1,61 @@ +.TH REF 10.2 +.SH NAME +Ref, incref, decref \- reference counts +.SH SYNOPSIS +.ta \w'\fLchar* 'u +.PP +.B +int incref(Ref *r) +.PP +.B +int decref(Ref *r) +.SH DESCRIPTION +A +.B Ref +structure holds a reference count for a data structure: +.IP +.EX +typedef struct +struct Ref +{ + Lock; + long ref; +} Ref; +.EE +.PP +The reference count proper is found in +.BR ref ; +the +.B Lock +prevents concurrent updates +(see +.IR lock (10.2)). +.PP +.I Incref +atomically increments the reference count +.IR r , +and returns the new count. +.PP +.I Decref +atomically decrements the reference count +.IR r , +and returns the new count. +.SH EXAMPLES +Release a structure containing a +.B Ref +on last use. +.IP +.EX +if(decref(s) == 0) + free(s); +.EE +.SH DIAGNOSTICS +.I Decref +will +.IR panic (10.2) +if the count goes negative, +revealing a reference counting bug. +.SH SOURCE +.B /os/port/chan.c +.br +.B /emu/port/chan.c |
