summaryrefslogtreecommitdiff
path: root/man/10/ref
blob: 9a363f8cd0c9d5696f0ce8d6efae8a8b0563895f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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