|
|
1.1 root 1: /*
2: * Copyright (c) 1995-1993 The University of Utah and
3: * the Computer Systems Laboratory at the University of Utah (CSL).
4: * All rights reserved.
5: *
6: * Permission to use, copy, modify and distribute this software is hereby
7: * granted provided that (1) source code retains these copyright, permission,
8: * and disclaimer notices, and (2) redistributions including binaries
9: * reproduce the notices in supporting documentation, and (3) all advertising
10: * materials mentioning features or use of this software display the following
11: * acknowledgement: ``This product includes software developed by the
12: * Computer Systems Laboratory at the University of Utah.''
13: *
14: * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
15: * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
16: * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17: *
18: * CSL requests users of this software to return to [email protected] any
19: * improvements that they make and grant CSL redistribution rights.
20: *
21: * Author: Bryan Ford, University of Utah CSL
22: */
23: /*
24: * File: refcount.h
25: *
26: * This defines the system-independent atomic reference count data type.
27: * (This file will often be overridden
28: * by better machine-dependent implementations.)
29: *
30: */
31:
32: #ifndef _KERN_REF_COUNT_H_
33: #define _KERN_REF_COUNT_H_
34:
35: #include <mach/macro_help.h>
36:
37: #include "simple_lock.h"
38:
39:
40: struct ref_count {
41: decl_simple_lock_data(,lock) /* lock for reference count */
42: int count; /* number of references */
43: };
44:
45: #define ref_count_init(refcount, refs) \
46: MACRO_BEGIN \
47: simple_lock_init(&(refcount)->lock); \
48: ((refcount)->count = (refs)); \
49: MACRO_END
50:
51: #define ref_count_take(refcount) \
52: MACRO_BEGIN \
53: simple_lock(&(refcount)->lock); \
54: (refcount)->count++; \
55: simple_unlock(&(refcount)->lock); \
56: MACRO_END
57:
58: #define ref_count_drop(refcount, func) \
59: MACRO_BEGIN \
60: int new_value; \
61: simple_lock(&(refcount)->lock); \
62: new_value = --(refcount)->count; \
63: simple_unlock(&(refcount)->lock); \
64: if (new_value == 0) { func; } \
65: MACRO_END
66:
67:
68: #endif _KERN_REF_COUNT_H_
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.