1 1.34 skrll /* $NetBSD: rf_threadstuff.h,v 1.34 2014/02/28 10:16:51 skrll Exp $ */ 2 1.1 oster /* 3 1.1 oster * Copyright (c) 1995 Carnegie-Mellon University. 4 1.1 oster * All rights reserved. 5 1.1 oster * 6 1.1 oster * Author: Mark Holland, Daniel Stodolsky, Jim Zelenka 7 1.1 oster * 8 1.1 oster * Permission to use, copy, modify and distribute this software and 9 1.1 oster * its documentation is hereby granted, provided that both the copyright 10 1.1 oster * notice and this permission notice appear in all copies of the 11 1.1 oster * software, derivative works or modified versions, and any portions 12 1.1 oster * thereof, and that both notices appear in supporting documentation. 13 1.1 oster * 14 1.1 oster * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 15 1.1 oster * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 16 1.1 oster * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 17 1.1 oster * 18 1.1 oster * Carnegie Mellon requests users of this software to return to 19 1.1 oster * 20 1.1 oster * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU 21 1.1 oster * School of Computer Science 22 1.1 oster * Carnegie Mellon University 23 1.1 oster * Pittsburgh PA 15213-3890 24 1.1 oster * 25 1.1 oster * any improvements or extensions that they make and grant Carnegie the 26 1.1 oster * rights to redistribute these changes. 27 1.1 oster */ 28 1.1 oster 29 1.1 oster /* 30 1.1 oster * threadstuff.h -- definitions for threads, locks, and synchronization 31 1.1 oster * 32 1.1 oster * The purpose of this file is provide some illusion of portability. 33 1.1 oster * If the functions below can be implemented with the same semantics on 34 1.1 oster * some new system, then at least the synchronization and thread control 35 1.1 oster * part of the code should not require modification to port to a new machine. 36 1.1 oster * the only other place where the pthread package is explicitly used is 37 1.1 oster * threadid.h 38 1.1 oster * 39 1.1 oster * this file should be included above stdio.h to get some necessary defines. 40 1.1 oster * 41 1.1 oster */ 42 1.1 oster 43 1.1 oster #ifndef _RF__RF_THREADSTUFF_H_ 44 1.1 oster #define _RF__RF_THREADSTUFF_H_ 45 1.1 oster 46 1.2 oster #include <sys/types.h> 47 1.2 oster #include <sys/param.h> 48 1.2 oster #include <sys/systm.h> 49 1.2 oster #include <sys/proc.h> 50 1.2 oster #include <sys/kthread.h> 51 1.24 ad #include <sys/mutex.h> 52 1.11 oster 53 1.11 oster #include <dev/raidframe/raidframevar.h> 54 1.1 oster 55 1.1 oster 56 1.23 ad typedef struct lwp *RF_Thread_t; 57 1.1 oster typedef void *RF_ThreadArg_t; 58 1.1 oster 59 1.29 mrg #define rf_declare_mutex2(_m_) kmutex_t _m_ 60 1.29 mrg #define rf_declare_cond2(_c_) kcondvar_t _c_ 61 1.25 mrg 62 1.29 mrg #define rf_lock_mutex2(_m_) mutex_enter(&(_m_)) 63 1.29 mrg #define rf_unlock_mutex2(_m_) mutex_exit(&(_m_)) 64 1.25 mrg 65 1.29 mrg #define rf_init_mutex2(_m_, _p_) mutex_init(&(_m_), MUTEX_DEFAULT, (_p_)) 66 1.29 mrg #define rf_destroy_mutex2(_m_) mutex_destroy(&(_m_)) 67 1.25 mrg 68 1.32 mrg #define rf_owned_mutex2(_m_) mutex_owned(&(_m_)) 69 1.32 mrg 70 1.29 mrg #define rf_init_cond2(_c_, _w_) cv_init(&(_c_), (_w_)) 71 1.29 mrg #define rf_destroy_cond2(_c_) cv_destroy(&(_c_)) 72 1.29 mrg 73 1.29 mrg #define rf_wait_cond2(_c_,_m_) cv_wait(&(_c_), &(_m_)) 74 1.29 mrg #define rf_timedwait_cond2(_c_,_m_,_t_) cv_timedwait(&(_c_), &(_m_), (_t_)) 75 1.29 mrg #define rf_signal_cond2(_c_) cv_signal(&(_c_)) 76 1.29 mrg #define rf_broadcast_cond2(_c_) cv_broadcast(&(_c_)) 77 1.25 mrg 78 1.29 mrg #define rf_sleep(_w_,_t_,_m_) kpause((_w_), false, (_t_), &(_m_)) 79 1.12 oster 80 1.1 oster /* 81 1.1 oster * In NetBSD, kernel threads are simply processes which share several 82 1.1 oster * substructures and never run in userspace. 83 1.1 oster */ 84 1.25 mrg 85 1.6 oster #define RF_CREATE_THREAD(_handle_, _func_, _arg_, _name_) \ 86 1.30 mrg kthread_create(PRI_SOFTBIO, 0, NULL, (void (*)(void *))(_func_), \ 87 1.23 ad (void *)(_arg_), &(_handle_), _name_) 88 1.13 oster 89 1.13 oster #define RF_CREATE_ENGINE_THREAD(_handle_, _func_, _arg_, _fmt_, _fmt_arg_) \ 90 1.30 mrg kthread_create(PRI_SOFTBIO, 0, NULL, (void (*)(void *))(_func_), \ 91 1.23 ad (void *)(_arg_), &(_handle_), _fmt_, _fmt_arg_) 92 1.1 oster 93 1.3 oster #endif /* !_RF__RF_THREADSTUFF_H_ */ 94