Annotation of Gnu-Mach/kern/refcount.h, revision 1.1.1.2

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: /* Unless the above include file specified otherwise,
                     33:    use the system-independent (unoptimized) atomic reference counter.  */
                     34: #ifndef MACHINE_REFCOUNT
                     35: 
                     36: #include <kern/lock.h>
                     37: 
                     38: struct RefCount {
                     39:        decl_simple_lock_data(,lock)    /* lock for reference count */
                     40:        int             ref_count;      /* number of references */
                     41: };
                     42: typedef struct RefCount RefCount;
                     43: 
                     44: #define refcount_init(refcount, refs)                  \
                     45:        MACRO_BEGIN                                     \
                     46:                simple_lock_init(&(refcount)->lock);    \
                     47:                ((refcount)->ref_count = (refs));       \
                     48:        MACRO_END
                     49: 
                     50: #define refcount_take(refcount)                                \
                     51:        MACRO_BEGIN                                     \
                     52:                simple_lock(&(refcount)->lock);         \
                     53:                (refcount)->ref_count++;                \
                     54:                simple_unlock(&(refcount)->lock);       \
                     55:        MACRO_END
                     56: 
                     57: #define refcount_drop(refcount, func)                  \
                     58:        MACRO_BEGIN                                     \
                     59:                int new_value;                          \
                     60:                simple_lock(&(refcount)->lock);         \
                     61:                new_value = --(refcount)->ref_count;    \
                     62:                simple_unlock(&(refcount)->lock);       \
                     63:                if (new_value == 0) { func; }           \
                     64:        MACRO_END
                     65: 
1.1.1.2 ! root       66: #endif /* MACHINE_REFCOUNT */
1.1       root       67: 
1.1.1.2 ! root       68: #endif /* _KERN_REFCOUNT_H_ */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.