Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ (10.2) — Plan9 3rd Edition (Vita Nuova)

Media Vault

Software Library

Restoration Projects

Artifacts Sought

REF(10.2)

NAME

Ref, incref, decref − reference counts

SYNOPSIS

intincref(Ref ∗r);

intdecref(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/chan.c

Plan 9  —  June 09, 2000

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026