From f07a4c844da9f0ecae5bbee1ab94be56505f26f7 Mon Sep 17 00:00:00 2001 From: Thomas Bushnell Date: Tue, 25 Feb 1997 21:28:37 +0000 Subject: Initial source --- util/Makerules | 32 +++++++++++++++++++++ util/about_to_die.c | 34 ++++++++++++++++++++++ util/config.h | 23 +++++++++++++++ util/cpu.c | 27 ++++++++++++++++++ util/cpu.h | 41 +++++++++++++++++++++++++++ util/cpu_init.c | 40 ++++++++++++++++++++++++++ util/cpu_subs.h | 23 +++++++++++++++ util/cpus.h | 27 ++++++++++++++++++ util/debug.h | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++ util/die.c | 54 +++++++++++++++++++++++++++++++++++ util/panic.c | 48 +++++++++++++++++++++++++++++++ util/phys_mem.h | 34 ++++++++++++++++++++++ util/putchar.c | 28 ++++++++++++++++++ util/puts.c | 37 ++++++++++++++++++++++++ util/ref_count.h | 68 ++++++++++++++++++++++++++++++++++++++++++++ 15 files changed, 597 insertions(+) create mode 100644 util/Makerules create mode 100644 util/about_to_die.c create mode 100644 util/config.h create mode 100644 util/cpu.c create mode 100644 util/cpu.h create mode 100644 util/cpu_init.c create mode 100644 util/cpu_subs.h create mode 100644 util/cpus.h create mode 100644 util/debug.h create mode 100644 util/die.c create mode 100644 util/panic.c create mode 100644 util/phys_mem.h create mode 100644 util/putchar.c create mode 100644 util/puts.c create mode 100644 util/ref_count.h (limited to 'util') diff --git a/util/Makerules b/util/Makerules new file mode 100644 index 0000000..0d6a231 --- /dev/null +++ b/util/Makerules @@ -0,0 +1,32 @@ +# +# Copyright (c) 1994 The University of Utah and +# the Computer Systems Laboratory (CSL). All rights reserved. +# +# Permission to use, copy, modify and distribute this software and its +# documentation is hereby granted, provided that both the copyright +# notice and this permission notice appear in all copies of the +# software, derivative works or modified versions, and any portions +# thereof, and that both notices appear in supporting documentation. +# +# THE UNIVERSITY OF UTAH AND CSS ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS +# IS" CONDITION. THE UNIVERSITY OF UTAH AND CSS DISCLAIM ANY LIABILITY OF +# ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. +# +# CSS requests users of this software to return to css-dist@cs.utah.edu any +# improvements that they make and grant CSS redistribution rights. +# +# Author: Bryan Ford, University of Utah CSS +# +ifndef _kernel_util_makerules_ +_kernel_util_makerules = yes + + +# Old defines that I hope to phase out +DEFINES += -DMACH_KERNEL + + +# Include the makefile containing the generic rules. +include $(GSRCDIR)/Makerules + + +endif diff --git a/util/about_to_die.c b/util/about_to_die.c new file mode 100644 index 0000000..9b039cc --- /dev/null +++ b/util/about_to_die.c @@ -0,0 +1,34 @@ +/* + * Copyright (c) 1995 The University of Utah and + * the Computer Systems Laboratory at the University of Utah (CSL). + * All rights reserved. + * + * Permission to use, copy, modify and distribute this software is hereby + * granted provided that (1) source code retains these copyright, permission, + * and disclaimer notices, and (2) redistributions including binaries + * reproduce the notices in supporting documentation, and (3) all advertising + * materials mentioning features or use of this software display the following + * acknowledgement: ``This product includes software developed by the + * Computer Systems Laboratory at the University of Utah.'' + * + * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS + * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF + * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * CSL requests users of this software to return to csl-dist@cs.utah.edu any + * improvements that they make and grant CSL redistribution rights. + * + * Author: Bryan Ford, University of Utah CSL + */ + +/* Call this to declare intention to die, + before doing final printfs and such. + The default implementation does nothing, + but typical actions might be to restore the video mode + to a standard setting, or stop other processors. + Note that this might very well be called several times + before die() is finally called. */ +void about_to_die(int exit_code) +{ +} + diff --git a/util/config.h b/util/config.h new file mode 100644 index 0000000..23b2bf6 --- /dev/null +++ b/util/config.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 1995 The University of Utah and + * the Computer Systems Laboratory at the University of Utah (CSL). + * All rights reserved. + * + * Permission to use, copy, modify and distribute this software is hereby + * granted provided that (1) source code retains these copyright, permission, + * and disclaimer notices, and (2) redistributions including binaries + * reproduce the notices in supporting documentation, and (3) all advertising + * materials mentioning features or use of this software display the following + * acknowledgement: ``This product includes software developed by the + * Computer Systems Laboratory at the University of Utah.'' + * + * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS + * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF + * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * CSL requests users of this software to return to csl-dist@cs.utah.edu any + * improvements that they make and grant CSL redistribution rights. + * + * Author: Bryan Ford, University of Utah CSL + */ +/* This file is just an empty default config.h file. */ diff --git a/util/cpu.c b/util/cpu.c new file mode 100644 index 0000000..0e45ac4 --- /dev/null +++ b/util/cpu.c @@ -0,0 +1,27 @@ +/* + * Copyright (c) 1995 The University of Utah and + * the Computer Systems Laboratory at the University of Utah (CSL). + * All rights reserved. + * + * Permission to use, copy, modify and distribute this software is hereby + * granted provided that (1) source code retains these copyright, permission, + * and disclaimer notices, and (2) redistributions including binaries + * reproduce the notices in supporting documentation, and (3) all advertising + * materials mentioning features or use of this software display the following + * acknowledgement: ``This product includes software developed by the + * Computer Systems Laboratory at the University of Utah.'' + * + * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS + * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF + * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * CSL requests users of this software to return to csl-dist@cs.utah.edu any + * improvements that they make and grant CSL redistribution rights. + * + * Author: Bryan Ford, University of Utah CSL + */ + +#include "cpu.h" + +struct cpu cpu[NCPUS]; + diff --git a/util/cpu.h b/util/cpu.h new file mode 100644 index 0000000..357f6d7 --- /dev/null +++ b/util/cpu.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 1995 The University of Utah and + * the Computer Systems Laboratory at the University of Utah (CSL). + * All rights reserved. + * + * Permission to use, copy, modify and distribute this software is hereby + * granted provided that (1) source code retains these copyright, permission, + * and disclaimer notices, and (2) redistributions including binaries + * reproduce the notices in supporting documentation, and (3) all advertising + * materials mentioning features or use of this software display the following + * acknowledgement: ``This product includes software developed by the + * Computer Systems Laboratory at the University of Utah.'' + * + * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS + * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF + * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * CSL requests users of this software to return to csl-dist@cs.utah.edu any + * improvements that they make and grant CSL redistribution rights. + * + * Author: Bryan Ford, University of Utah CSL + */ +#ifndef _UTIL_CPU_H_ +#define _UTIL_CPU_H_ + +#include "cpus.h" + + +/* There's one of these data structures per processor. */ +struct cpu +{ +#define cpu_sub(name) struct cpu_##name name; +#include "cpu_subs.h" +#undef cpu_sub +int dummy; +}; + +extern struct cpu cpu[NCPUS]; + + +#endif _UTIL_CPU_H_ diff --git a/util/cpu_init.c b/util/cpu_init.c new file mode 100644 index 0000000..c59824b --- /dev/null +++ b/util/cpu_init.c @@ -0,0 +1,40 @@ +/* + * Copyright (c) 1995 The University of Utah and + * the Computer Systems Laboratory at the University of Utah (CSL). + * All rights reserved. + * + * Permission to use, copy, modify and distribute this software is hereby + * granted provided that (1) source code retains these copyright, permission, + * and disclaimer notices, and (2) redistributions including binaries + * reproduce the notices in supporting documentation, and (3) all advertising + * materials mentioning features or use of this software display the following + * acknowledgement: ``This product includes software developed by the + * Computer Systems Laboratory at the University of Utah.'' + * + * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS + * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF + * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * CSL requests users of this software to return to csl-dist@cs.utah.edu any + * improvements that they make and grant CSL redistribution rights. + * + * Author: Bryan Ford, University of Utah CSL + */ + +#include "cpu.h" + +void cpu_init(struct cpu *cpu) +{ +#define cpu_sub(name) cpu_##name##_init(cpu); +#include "cpu_subs.h" +#undef cpu_sub +} + +void cpus_init() +{ + int n; + + for (n = 0; n < NCPUS; n++) + cpu_init(&cpu[n]); +} + diff --git a/util/cpu_subs.h b/util/cpu_subs.h new file mode 100644 index 0000000..850ef38 --- /dev/null +++ b/util/cpu_subs.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 1995 The University of Utah and + * the Computer Systems Laboratory at the University of Utah (CSL). + * All rights reserved. + * + * Permission to use, copy, modify and distribute this software is hereby + * granted provided that (1) source code retains these copyright, permission, + * and disclaimer notices, and (2) redistributions including binaries + * reproduce the notices in supporting documentation, and (3) all advertising + * materials mentioning features or use of this software display the following + * acknowledgement: ``This product includes software developed by the + * Computer Systems Laboratory at the University of Utah.'' + * + * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS + * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF + * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * CSL requests users of this software to return to csl-dist@cs.utah.edu any + * improvements that they make and grant CSL redistribution rights. + * + * Author: Bryan Ford, University of Utah CSL + */ +/* This file is just a terminator for the set of cpu_subs.h headers. */ diff --git a/util/cpus.h b/util/cpus.h new file mode 100644 index 0000000..355ecdb --- /dev/null +++ b/util/cpus.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 1995 The University of Utah and + * the Computer Systems Laboratory at the University of Utah (CSL). + * All rights reserved. + * + * Permission to use, copy, modify and distribute this software is hereby + * granted provided that (1) source code retains these copyright, permission, + * and disclaimer notices, and (2) redistributions including binaries + * reproduce the notices in supporting documentation, and (3) all advertising + * materials mentioning features or use of this software display the following + * acknowledgement: ``This product includes software developed by the + * Computer Systems Laboratory at the University of Utah.'' + * + * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS + * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF + * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * CSL requests users of this software to return to csl-dist@cs.utah.edu any + * improvements that they make and grant CSL redistribution rights. + * + * Author: Bryan Ford, University of Utah CSL + */ + +/* Default cpus.h sets things up for a uniprocessor. */ +#define NCPUS 1 +#undef MULTIPROCESSOR + diff --git a/util/debug.h b/util/debug.h new file mode 100644 index 0000000..d61502b --- /dev/null +++ b/util/debug.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) 1995-1993 The University of Utah and + * the Computer Systems Laboratory at the University of Utah (CSL). + * All rights reserved. + * + * Permission to use, copy, modify and distribute this software is hereby + * granted provided that (1) source code retains these copyright, permission, + * and disclaimer notices, and (2) redistributions including binaries + * reproduce the notices in supporting documentation, and (3) all advertising + * materials mentioning features or use of this software display the following + * acknowledgement: ``This product includes software developed by the + * Computer Systems Laboratory at the University of Utah.'' + * + * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS + * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF + * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * CSL requests users of this software to return to csl-dist@cs.utah.edu any + * improvements that they make and grant CSL redistribution rights. + * + * Author: Bryan Ford, University of Utah CSL + */ +/* + * File: debug.h + * Author: Bryan Ford + * + * This file contains definitions for kernel debugging, + * which are compiled in on the DEBUG symbol. + * + */ +#ifndef _MACH_UTIL_DEBUG_H_ +#define _MACH_UTIL_DEBUG_H_ + +#include + + +#ifdef DEBUG + +extern void panic(const char *fmt, ...); + +#define here() printf("@ %s:%d\n", __FILE__, __LINE__) +#define message(args) ({ printf("@ %s:%d: ", __FILE__, __LINE__); printf args; printf("\n"); }) + +#define otsan() panic("%s:%d: off the straight and narrow!", __FILE__, __LINE__) + +#define assert(v) \ + MACRO_BEGIN \ + if (!(v)) \ + panic("%s:%d: failed assertion `"#v"'\n", \ + __FILE__, __LINE__); \ + MACRO_END + +#define do_debug(stmt) stmt + +#define debugmsg(args) \ + ({ printf("%s:%d: ", __FILE__, __LINE__); printf args; printf("\n"); }) + +#define struct_id_decl unsigned struct_id; +#define struct_id_init(p,id) ((p)->struct_id = (id)) +#define struct_id_denit(p) ((p)->struct_id = 0) +#define struct_id_verify(p,id) \ + ({ if ((p)->struct_id != (id)) \ + panic("%s:%d: "#p" (%08x) struct_id should be "#id" (%08x), is %08x\n", \ + __FILE__, __LINE__, (p), (id), (p->struct_id)); \ + }) + +#else !DEBUG + +#define otsan() +#define assert(v) +#define do_debug(stmt) +#define debugmsg(args) + +#define struct_id_decl +#define struct_id_init(p,id) +#define struct_id_denit(p) +#define struct_id_verify(p,id) + +#endif !DEBUG + +#endif _MACH_UTIL_DEBUG_H_ diff --git a/util/die.c b/util/die.c new file mode 100644 index 0000000..c2eeeaf --- /dev/null +++ b/util/die.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 1995-1994 The University of Utah and + * the Computer Systems Laboratory at the University of Utah (CSL). + * All rights reserved. + * + * Permission to use, copy, modify and distribute this software is hereby + * granted provided that (1) source code retains these copyright, permission, + * and disclaimer notices, and (2) redistributions including binaries + * reproduce the notices in supporting documentation, and (3) all advertising + * materials mentioning features or use of this software display the following + * acknowledgement: ``This product includes software developed by the + * Computer Systems Laboratory at the University of Utah.'' + * + * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS + * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF + * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * CSL requests users of this software to return to csl-dist@cs.utah.edu any + * improvements that they make and grant CSL redistribution rights. + * + * Author: Bryan Ford, University of Utah CSL + */ + +#include + +/* Note: These routines are deprecated and should not be used anymore. + Use panic() instead. */ +void die(const char *fmt, ...) +{ + int exit_code = fmt != 0; + + about_to_die(exit_code); + + if (fmt) + { + va_list vl; + + va_start(vl, fmt); + vprintf(fmt, vl); + va_end(vl); + + putchar('\n'); + + exit(exit_code); + } + else + exit(exit_code); +} + +void die_no_mem(void) +{ + die("Not enough memory."); +} + diff --git a/util/panic.c b/util/panic.c new file mode 100644 index 0000000..2df8839 --- /dev/null +++ b/util/panic.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 1995 The University of Utah and + * the Computer Systems Laboratory at the University of Utah (CSL). + * All rights reserved. + * + * Permission to use, copy, modify and distribute this software is hereby + * granted provided that (1) source code retains these copyright, permission, + * and disclaimer notices, and (2) redistributions including binaries + * reproduce the notices in supporting documentation, and (3) all advertising + * materials mentioning features or use of this software display the following + * acknowledgement: ``This product includes software developed by the + * Computer Systems Laboratory at the University of Utah.'' + * + * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS + * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF + * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * CSL requests users of this software to return to csl-dist@cs.utah.edu any + * improvements that they make and grant CSL redistribution rights. + * + * Author: Bryan Ford, University of Utah CSL + */ + +#include +#include + +void panic(const char *fmt, ...) +{ + int exit_code = fmt != 0; + + about_to_die(exit_code); + + if (fmt) + { + va_list vl; + + va_start(vl, fmt); + vprintf(fmt, vl); + va_end(vl); + + putchar('\n'); + + exit(exit_code); + } + else + exit(exit_code); +} + diff --git a/util/phys_mem.h b/util/phys_mem.h new file mode 100644 index 0000000..2e18a6b --- /dev/null +++ b/util/phys_mem.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 1995 The University of Utah and + * the Computer Systems Laboratory at the University of Utah (CSL). + * All rights reserved. + * + * Permission to use, copy, modify and distribute this software is hereby + * granted provided that (1) source code retains these copyright, permission, + * and disclaimer notices, and (2) redistributions including binaries + * reproduce the notices in supporting documentation, and (3) all advertising + * materials mentioning features or use of this software display the following + * acknowledgement: ``This product includes software developed by the + * Computer Systems Laboratory at the University of Utah.'' + * + * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS + * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF + * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * CSL requests users of this software to return to csl-dist@cs.utah.edu any + * improvements that they make and grant CSL redistribution rights. + * + * Author: Bryan Ford, University of Utah CSL + */ +#ifndef _UTIL_PHYS_MEM_H_ +#define _UTIL_PHYS_MEM_H_ + +#include + + +/* This always holds the physical address + of the top of known physical memory. */ +extern vm_offset_t phys_mem_max; + + +#endif _UTIL_PHYS_MEM_H_ diff --git a/util/putchar.c b/util/putchar.c new file mode 100644 index 0000000..18f0f06 --- /dev/null +++ b/util/putchar.c @@ -0,0 +1,28 @@ +/* + * Copyright (c) 1995 The University of Utah and + * the Computer Systems Laboratory at the University of Utah (CSL). + * All rights reserved. + * + * Permission to use, copy, modify and distribute this software is hereby + * granted provided that (1) source code retains these copyright, permission, + * and disclaimer notices, and (2) redistributions including binaries + * reproduce the notices in supporting documentation, and (3) all advertising + * materials mentioning features or use of this software display the following + * acknowledgement: ``This product includes software developed by the + * Computer Systems Laboratory at the University of Utah.'' + * + * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS + * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF + * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * CSL requests users of this software to return to csl-dist@cs.utah.edu any + * improvements that they make and grant CSL redistribution rights. + * + * Author: Bryan Ford, University of Utah CSL + */ + +int putchar(int c) +{ + cnputc(c); +} + diff --git a/util/puts.c b/util/puts.c new file mode 100644 index 0000000..c0eec03 --- /dev/null +++ b/util/puts.c @@ -0,0 +1,37 @@ +/* + * Copyright (c) 1995 The University of Utah and + * the Computer Systems Laboratory at the University of Utah (CSL). + * All rights reserved. + * + * Permission to use, copy, modify and distribute this software is hereby + * granted provided that (1) source code retains these copyright, permission, + * and disclaimer notices, and (2) redistributions including binaries + * reproduce the notices in supporting documentation, and (3) all advertising + * materials mentioning features or use of this software display the following + * acknowledgement: ``This product includes software developed by the + * Computer Systems Laboratory at the University of Utah.'' + * + * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS + * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF + * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * CSL requests users of this software to return to csl-dist@cs.utah.edu any + * improvements that they make and grant CSL redistribution rights. + * + * Author: Bryan Ford, University of Utah CSL + */ + +/* Simple puts() implementation that just uses putchar(). + Note that our libc's printf() is implemented + in terms of only puts() and putchar(), so that's all we need. */ +int puts(const char *s) +{ + while (*s) + { + putchar(*s); + s++; + } + putchar('\n'); + return 0; +} + diff --git a/util/ref_count.h b/util/ref_count.h new file mode 100644 index 0000000..b6d3404 --- /dev/null +++ b/util/ref_count.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 1995-1993 The University of Utah and + * the Computer Systems Laboratory at the University of Utah (CSL). + * All rights reserved. + * + * Permission to use, copy, modify and distribute this software is hereby + * granted provided that (1) source code retains these copyright, permission, + * and disclaimer notices, and (2) redistributions including binaries + * reproduce the notices in supporting documentation, and (3) all advertising + * materials mentioning features or use of this software display the following + * acknowledgement: ``This product includes software developed by the + * Computer Systems Laboratory at the University of Utah.'' + * + * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS + * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF + * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * CSL requests users of this software to return to csl-dist@cs.utah.edu any + * improvements that they make and grant CSL redistribution rights. + * + * Author: Bryan Ford, University of Utah CSL + */ +/* + * File: refcount.h + * + * This defines the system-independent atomic reference count data type. + * (This file will often be overridden + * by better machine-dependent implementations.) + * + */ + +#ifndef _KERN_REF_COUNT_H_ +#define _KERN_REF_COUNT_H_ + +#include + +#include "simple_lock.h" + + +struct ref_count { + decl_simple_lock_data(,lock) /* lock for reference count */ + int count; /* number of references */ +}; + +#define ref_count_init(refcount, refs) \ + MACRO_BEGIN \ + simple_lock_init(&(refcount)->lock); \ + ((refcount)->count = (refs)); \ + MACRO_END + +#define ref_count_take(refcount) \ + MACRO_BEGIN \ + simple_lock(&(refcount)->lock); \ + (refcount)->count++; \ + simple_unlock(&(refcount)->lock); \ + MACRO_END + +#define ref_count_drop(refcount, func) \ + MACRO_BEGIN \ + int new_value; \ + simple_lock(&(refcount)->lock); \ + new_value = --(refcount)->count; \ + simple_unlock(&(refcount)->lock); \ + if (new_value == 0) { func; } \ + MACRO_END + + +#endif _KERN_REF_COUNT_H_ -- cgit v1.2.3