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