eus_thr.h
Go to the documentation of this file.
1 /*
2  * EusLisp multithread support
3  *
4  * EusLisp is written using Solaris2's thread library.
5  * This file is provided to emulate the library in other environment.
6  *
7  * alpha porting team (APT) Jan.1996
8  */
9 
10 #include <errno.h>
11 
12 #if Solaris2
13 #include <synch.h>
14 #include <thread.h>
15 #endif
16 
17 #if SunOS4_1
18 #include <lwp/lwp.h>
19 #include <lwp/lwpmachdep.h>
20 #include <lwp/stackdep.h>
21 #define USYNC_THREAD 0
22 #endif
23 
24 #if alpha || PTHREAD
25 #include <pthread.h>
26 #undef CATCH
27 #define USYNC_THREAD 0
28 #endif
29 
30 struct thread_arg {
35 
36 
37 /*
38  * MT-library specific parts
39  */
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 /* SunOS4.1.x specific part */
45 
46 #if SunOS4_1
47 /* mthread type for SunOS 4.1.x added by H.Nakagaki */
48 typedef mon_t mutex_t;
49 typedef cv_t cond_t;
50 
51 /* lwp functions are redefined to mthread functions by H.Nakagaki */
52 #define USYNC_THREAD 0
53 #define THR_SUSPENDED LWPSUSPEND
54 #define thr_exit(x) pod_exit(x)
55 #define thr_join(x,y,z) lwp_join(x)
56 #define mutex_init(x,y,z) mon_create(x)
57 #define mutex_destroy(x) mon_destroy(*(x))
58 #define mutex_lock(x) mon_enter(*(x))
59 #define mutex_unlock(x) mon_exit(*(x))
60 #define mutex_trylock(x) mon_cond_enter(*(x))
61 #define cond_init(x,y) cv_create(x,*(y))
62 #define cond_destroy(x) cv_destroy(*(x))
63 #define cond_wait(x,y) cv_wait(*(x))
64 #define cond_signal(x) cv_notify(*(x))
65 #define cond_broadcast(x) cv_broadcast(*(x))
66 #endif /* SunOS4_1 */
67 
68 
69 /* Alpha specific part */
70 
71 #if alpha || PTHREAD
72 #ifndef __COLLECTOR_H /* R.Hanai */
73 typedef pthread_t thread_t;
74 typedef pthread_mutex_t mutex_t;
75 typedef pthread_cond_t cond_t;
76 #define thr_exit(x) pthread_exit(x)
77 #define thr_join(x,y,z) pthread_join(x,z)
78 #define mutex_init(x,y,z) pthread_mutex_init(x,y)
79 #define mutex_lock pthread_mutex_lock
80 #define mutex_trylock pthread_mutex_trylock
81 #define mutex_unlock pthread_mutex_unlock
82 #define cond_wait pthread_cond_wait
83 #define cond_signal pthread_cond_signal
84 #define cond_broadcast pthread_cond_broadcast
85 #endif
86 #endif /* alpha */
87 
88 
89 /*
90  * common part (for environment other than Solaris2)
91  */
92 
93 #if !Solaris2
94 
95 /* type definition */
96 typedef struct _sema {
97  unsigned int count;
98  mutex_t lock;
99  cond_t cond;
100  } sema_t;
101 typedef struct _rwlock {
102  unsigned int readers;
103  mutex_t lock;
104  cond_t r_cond;
105  cond_t w_cond;
106  } rwlock_t;
107 
108 /* function prototype */
109 /* lwp functions are redefined to mthread functions by H.Nakagaki */
110 extern unsigned int thr_self();
111 extern int thr_getprio(int tid, int *prio);
112 extern int thr_create(void *, size_t, void (*)(), void *, long, int *);
113 extern int thr_setprio(int, int);
114 extern int thr_continue(int);
115 extern int thr_suspend(int);
116 extern int thr_kill(int, int);
117 
118 /* readers/writer lock function definition added by H.Nakagaki */
119 extern int rwlock_init(rwlock_t *, int, void *);
120 extern int rwlock_destroy(rwlock_t *);
121 extern int rw_rdlock(rwlock_t *);
122 extern int rw_wrlock(rwlock_t *);
123 extern int rw_unlock(rwlock_t *);
124 
125 /* semaphore function defined at mthread.c added by H.Nakagaki */
126 extern int sema_init(sema_t *, unsigned int, int, void *);
127 extern int sema_destroy(sema_t *);
128 extern int sema_port(sema_t *);
129 extern int sema_wait(sema_t *);
130 extern int sema_trywait(sema_t *);
131 
132 extern int mthread(context *ctx, pointer mod);
133 #endif /* !Solaris2 */
134 #if PTHREAD
135 extern int sema_post(sema_t *sem);
136 extern void mthread_init( context *mainctx );
137 #endif
138 
139 /*
140  * EusLisp variables
141  */
142 
143 /* mutex locks*/
144 extern mutex_t mark_lock;
145 extern char *mark_locking;
146 extern int mark_lock_thread;
147 //extern mutex_t p_mark_lock;
148 extern rwlock_t gc_lock;
149 
150 extern mutex_t alloc_lock;
151 extern mutex_t free_thread_lock;
152 extern mutex_t qthread_lock;
153 extern mutex_t qsort_lock;
154 extern sema_t free_thread_sem;
155 #ifdef __cplusplus
156 }
157 #endif
_rwlock::w_cond
cond_t w_cond
Definition: eus_thr.h:105
gc_lock
rwlock_t gc_lock
Definition: mthread.c:18
context
Definition: eus.h:524
_rwlock::r_cond
cond_t r_cond
Definition: eus_thr.h:104
thr_kill
int thr_kill(int, int)
Definition: pthreads.c:70
rwlock_init
int rwlock_init(rwlock_t *, int, void *)
Definition: pthreads.c:164
thread_arg::arg
pointer arg
Definition: eus_thr.h:34
rwlock_destroy
int rwlock_destroy(rwlock_t *)
Definition: pthreads.c:172
sema_init
int sema_init(sema_t *, unsigned int, int, void *)
Definition: pthreads.c:111
mainctx
context * mainctx
Definition: eus.c:57
rw_wrlock
int rw_wrlock(rwlock_t *)
Definition: pthreads.c:188
thr_setprio
int thr_setprio(int, int)
Definition: pthreads.c:30
thr_suspend
int thr_suspend(int)
Definition: pthreads.c:64
_sema::lock
mutex_t lock
Definition: eus_thr.h:98
sema_trywait
int sema_trywait(sema_t *)
Definition: pthreads.c:133
rw_unlock
int rw_unlock(rwlock_t *)
Definition: pthreads.c:197
thr_getprio
int thr_getprio(int tid, int *prio)
Definition: pthreads.c:21
mark_lock_thread
int mark_lock_thread
Definition: mthread.c:27
_sema::cond
cond_t cond
Definition: eus_thr.h:99
qsort_lock
mutex_t qsort_lock
Definition: mthread.c:21
thread_arg::func
pointer func
Definition: eus_thr.h:33
free_thread_lock
mutex_t free_thread_lock
Definition: mthread.c:13
sema_wait
int sema_wait(sema_t *)
Definition: pthreads.c:124
_sema::count
unsigned int count
Definition: eus_thr.h:97
cell
Definition: eus.h:381
alloc_lock
mutex_t alloc_lock
Definition: memory.mutex.c:42
_sema
Definition: eus_thr.h:96
thr_self
unsigned int thr_self()
Definition: eus.c:25
sema_t
struct _sema sema_t
sema_destroy
int sema_destroy(sema_t *)
Definition: pthreads.c:118
thread_arg
Definition: eus_thr.h:30
free_thread_sem
sema_t free_thread_sem
Definition: mthread.c:11
thr_create
int thr_create(void *, size_t, void(*)(), void *, long, int *)
Definition: pthreads.c:43
thread_arg::form
pointer form
Definition: eus_thr.h:32
sema_post
int sema_post(sema_t *sem)
Definition: pthreads.c:148
rw_rdlock
int rw_rdlock(rwlock_t *)
Definition: pthreads.c:179
mark_locking
char * mark_locking
Definition: mthread.c:26
thread_arg::newctx
context * newctx
Definition: eus_thr.h:31
qthread_lock
mutex_t qthread_lock
Definition: mthread.c:14
_rwlock::readers
unsigned int readers
Definition: eus_thr.h:102
mthread
int mthread(context *ctx, pointer mod)
Definition: mthread.c:536
tid
thread_t tid
Definition: collector.c:50
_rwlock::lock
mutex_t lock
Definition: eus_thr.h:103
thr_continue
int thr_continue(int)
Definition: pthreads.c:58
rwlock_t
struct _rwlock rwlock_t
mark_lock
mutex_t mark_lock
Definition: mthread.c:25
sema_port
int sema_port(sema_t *)
_rwlock
Definition: eus_thr.h:101


euslisp
Author(s): Toshihiro Matsui
autogenerated on Thu Jun 15 2023 02:06:43