Annotation of sys/dev/raidframe/rf_threadstuff.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: rf_threadstuff.c,v 1.4 2002/12/16 07:01:05 tdeval Exp $ */
! 2: /* $NetBSD: rf_threadstuff.c,v 1.5 1999/12/07 02:13:28 oster Exp $ */
! 3:
! 4: /*
! 5: * rf_threadstuff.c
! 6: */
! 7:
! 8: /*
! 9: * Copyright (c) 1995 Carnegie-Mellon University.
! 10: * All rights reserved.
! 11: *
! 12: * Author: Jim Zelenka
! 13: *
! 14: * Permission to use, copy, modify and distribute this software and
! 15: * its documentation is hereby granted, provided that both the copyright
! 16: * notice and this permission notice appear in all copies of the
! 17: * software, derivative works or modified versions, and any portions
! 18: * thereof, and that both notices appear in supporting documentation.
! 19: *
! 20: * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
! 21: * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
! 22: * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
! 23: *
! 24: * Carnegie Mellon requests users of this software to return to
! 25: *
! 26: * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
! 27: * School of Computer Science
! 28: * Carnegie Mellon University
! 29: * Pittsburgh PA 15213-3890
! 30: *
! 31: * any improvements or extensions that they make and grant Carnegie the
! 32: * rights to redistribute these changes.
! 33: */
! 34:
! 35: #include "rf_types.h"
! 36: #include "rf_threadstuff.h"
! 37: #include "rf_general.h"
! 38: #include "rf_shutdown.h"
! 39:
! 40: void mutex_destroyer(void *);
! 41: void cond_destroyer(void *);
! 42:
! 43: /*
! 44: * Shared stuff.
! 45: */
! 46:
! 47: void
! 48: mutex_destroyer(void *arg)
! 49: {
! 50: int rc;
! 51:
! 52: rc = rf_mutex_destroy(arg);
! 53: if (rc) {
! 54: RF_ERRORMSG1("RAIDFRAME: Error %d auto-destroying mutex\n", rc);
! 55: }
! 56: }
! 57:
! 58: void
! 59: cond_destroyer(void *arg)
! 60: {
! 61: int rc;
! 62:
! 63: rc = rf_cond_destroy(arg);
! 64: if (rc) {
! 65: RF_ERRORMSG1("RAIDFRAME: Error %d auto-destroying condition\n",
! 66: rc);
! 67: }
! 68: }
! 69:
! 70: int
! 71: _rf_create_managed_mutex(RF_ShutdownList_t **listp, RF_DECLARE_MUTEX(*m),
! 72: char *file, int line)
! 73: {
! 74: int rc, rc1;
! 75:
! 76: rc = rf_mutex_init(m);
! 77: if (rc)
! 78: return (rc);
! 79:
! 80: rc = _rf_ShutdownCreate(listp, mutex_destroyer, (void *) m, file, line);
! 81: if (rc) {
! 82: RF_ERRORMSG1("RAIDFRAME: Error %d adding shutdown entry\n", rc);
! 83: rc1 = rf_mutex_destroy(m);
! 84: if (rc1) {
! 85: RF_ERRORMSG1("RAIDFRAME: Error %d destroying mutex\n",
! 86: rc1);
! 87: }
! 88: }
! 89:
! 90: return (rc);
! 91: }
! 92:
! 93: int
! 94: _rf_create_managed_cond(RF_ShutdownList_t **listp, RF_DECLARE_COND(*c),
! 95: char *file, int line)
! 96: {
! 97: int rc, rc1;
! 98:
! 99: rc = rf_cond_init(c);
! 100: if (rc)
! 101: return (rc);
! 102:
! 103: rc = _rf_ShutdownCreate(listp, cond_destroyer, (void *) c, file, line);
! 104: if (rc) {
! 105: RF_ERRORMSG1("RAIDFRAME: Error %d adding shutdown entry\n", rc);
! 106: rc1 = rf_cond_destroy(c);
! 107: if (rc1) {
! 108: RF_ERRORMSG1("RAIDFRAME: Error %d destroying cond\n",
! 109: rc1);
! 110: }
! 111: }
! 112: return (rc);
! 113: }
! 114:
! 115: int
! 116: _rf_init_managed_threadgroup(RF_ShutdownList_t **listp, RF_ThreadGroup_t *g,
! 117: char *file, int line)
! 118: {
! 119: int rc;
! 120:
! 121: rc = _rf_create_managed_mutex(listp, &g->mutex, file, line);
! 122: if (rc)
! 123: return (rc);
! 124:
! 125: rc = _rf_create_managed_cond(listp, &g->cond, file, line);
! 126: if (rc)
! 127: return (rc);
! 128:
! 129: g->created = g->running = g->shutdown = 0;
! 130: return (0);
! 131: }
! 132:
! 133: int
! 134: _rf_destroy_threadgroup(RF_ThreadGroup_t *g, char *file, int line)
! 135: {
! 136: int rc1, rc2;
! 137:
! 138: rc1 = rf_mutex_destroy(&g->mutex);
! 139: rc2 = rf_cond_destroy(&g->cond);
! 140:
! 141: if (rc1)
! 142: return (rc1);
! 143:
! 144: return (rc2);
! 145: }
! 146:
! 147: int
! 148: _rf_init_threadgroup(RF_ThreadGroup_t *g, char *file, int line)
! 149: {
! 150: int rc;
! 151:
! 152: rc = rf_mutex_init(&g->mutex);
! 153: if (rc)
! 154: return (rc);
! 155:
! 156: rc = rf_cond_init(&g->cond);
! 157: if (rc) {
! 158: rf_mutex_destroy(&g->mutex);
! 159: return (rc);
! 160: }
! 161:
! 162: g->created = g->running = g->shutdown = 0;
! 163: return (0);
! 164: }
! 165:
! 166:
! 167: /*
! 168: * Kernel.
! 169: */
! 170:
! 171: int
! 172: rf_mutex_init(decl_simple_lock_data(, *m))
! 173: {
! 174: simple_lock_init(m);
! 175: return (0);
! 176: }
! 177:
! 178: int
! 179: rf_mutex_destroy(decl_simple_lock_data(, *m))
! 180: {
! 181: return (0);
! 182: }
! 183:
! 184: int
! 185: rf_cond_init(RF_DECLARE_COND(*c))
! 186: {
! 187: *c = 0; /* No reason. */
! 188: return (0);
! 189: }
! 190:
! 191: int
! 192: rf_cond_destroy(RF_DECLARE_COND(*c))
! 193: {
! 194: return (0);
! 195: }
CVSweb