Sections:

All contributions in this site reflect the authors' opinions and they are not necessarily endorsed by, or reflect the beliefs of, anarchyinthetubes, as neither do most of the opinions in other sites.

/sys/doc/ Documentation archive

[manual index][section index]

NAME

Ref, incref, decref - reference counts

SYNOPSIS

int incref(Ref *r)

int decref(Ref *r)

DESCRIPTION

A Ref structure holds a reference count for a data structure:

typedef struct
struct Ref
{
    Lock;
    long ref;
} Ref;

The reference count proper is found in ref; the Lock prevents concurrent updates (see lock(10.2)).

Incref atomically increments the reference count r, and returns the new count.

Decref atomically decrements the reference count r, and returns the new count.

EXAMPLES

Release a structure containing a Ref on last use.

if(decref(s) == 0)
	free(s);

DIAGNOSTICS

Decref will panic(10.2) if the count goes negative, revealing a reference counting bug.

SOURCE

/os/port/chan.c
/emu/port/chan.c

REF(10.2) Rev:  Tue Jan 29 13:11:34 GMT 2008
original page
cat.4l77.com