|
|
1.1 root 1: /*
2: * Copyright (c) 1993,1994 The University of Utah and
3: * the Computer Systems Laboratory (CSL). All rights reserved.
4: *
5: * Permission to use, copy, modify and distribute this software and its
6: * documentation is hereby granted, provided that both the copyright
7: * notice and this permission notice appear in all copies of the
8: * software, derivative works or modified versions, and any portions
9: * thereof, and that both notices appear in supporting documentation.
10: *
11: * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
12: * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
13: * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
14: *
15: * CSL requests users of this software to return to [email protected] any
16: * improvements that they make and grant CSL redistribution rights.
17: *
18: * Author: Bryan Ford, University of Utah CSL
19: */
20: /*
21: * File: refcount.h
22: *
23: * This defines the system-independent part of the atomic reference count data type.
24: *
25: */
26:
27: #ifndef _KERN_REFCOUNT_H_
28: #define _KERN_REFCOUNT_H_
29:
30: #include <kern/macro_help.h>
31:
32: #include "refcount.h" /*XXX*/
33:
34: /* Unless the above include file specified otherwise,
35: use the system-independent (unoptimized) atomic reference counter. */
36: #ifndef MACHINE_REFCOUNT
37:
38: #include <kern/lock.h>
39:
40: struct RefCount {
41: decl_simple_lock_data(,lock) /* lock for reference count */
42: int ref_count; /* number of references */
43: };
44: typedef struct RefCount RefCount;
45:
46: #define refcount_init(refcount, refs) \
47: MACRO_BEGIN \
48: simple_lock_init(&(refcount)->lock); \
49: ((refcount)->ref_count = (refs)); \
50: MACRO_END
51:
52: #define refcount_take(refcount) \
53: MACRO_BEGIN \
54: simple_lock(&(refcount)->lock); \
55: (refcount)->ref_count++; \
56: simple_unlock(&(refcount)->lock); \
57: MACRO_END
58:
59: #define refcount_drop(refcount, func) \
60: MACRO_BEGIN \
61: int new_value; \
62: simple_lock(&(refcount)->lock); \
63: new_value = --(refcount)->ref_count; \
64: simple_unlock(&(refcount)->lock); \
65: if (new_value == 0) { func; } \
66: MACRO_END
67:
68: #endif
69:
70: #endif _KERN_REFCOUNT_H_
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.