6 #include </usr/include/thread.h>
13 static void PyThread__init_thread(void)
26 new_func(void *funcarg
)
31 func
= ((struct func_arg
*) funcarg
)->func
;
32 arg
= ((struct func_arg
*) funcarg
)->arg
;
40 PyThread_start_new_thread(void (*func
)(void *), void *arg
)
42 struct func_arg
*funcarg
;
43 int success
= 0; /* init not needed when SOLARIS_THREADS and */
44 /* C_THREADS implemented properly */
46 dprintf(("PyThread_start_new_thread called\n"));
48 PyThread_init_thread();
49 funcarg
= (struct func_arg
*) malloc(sizeof(struct func_arg
));
52 if (thr_create(0, 0, new_func
, funcarg
,
53 THR_DETACHED
| THR_NEW_LWP
, 0)) {
55 free((void *) funcarg
);
58 return success
< 0 ? 0 : 1;
62 PyThread_get_thread_ident(void)
65 PyThread_init_thread();
70 do_PyThread_exit_thread(int no_cleanup
)
72 dprintf(("PyThread_exit_thread called\n"));
82 PyThread_exit_thread(void)
84 do_PyThread_exit_thread(0);
88 PyThread__exit_thread(void)
90 do_PyThread_exit_thread(1);
95 do_PyThread_exit_prog(int status
, int no_cleanup
)
97 dprintf(("PyThread_exit_prog(%d) called\n", status
));
110 PyThread_exit_prog(int status
)
112 do_PyThread_exit_prog(status
, 0);
116 PyThread__exit_prog(int status
)
118 do_PyThread_exit_prog(status
, 1);
120 #endif /* NO_EXIT_PROG */
126 PyThread_allocate_lock(void)
130 dprintf(("PyThread_allocate_lock called\n"));
132 PyThread_init_thread();
134 lock
= (mutex_t
*) malloc(sizeof(mutex_t
));
135 if (mutex_init(lock
, USYNC_THREAD
, 0)) {
136 perror("mutex_init");
140 dprintf(("PyThread_allocate_lock() -> %p\n", lock
));
141 return (PyThread_type_lock
) lock
;
145 PyThread_free_lock(PyThread_type_lock lock
)
147 dprintf(("PyThread_free_lock(%p) called\n", lock
));
148 mutex_destroy((mutex_t
*) lock
);
153 PyThread_acquire_lock(PyThread_type_lock lock
, int waitflag
)
157 dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock
, waitflag
));
159 success
= mutex_lock((mutex_t
*) lock
);
161 success
= mutex_trylock((mutex_t
*) lock
);
163 perror(waitflag
? "mutex_lock" : "mutex_trylock");
165 success
= !success
; /* solaris does it the other way round */
166 dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock
, waitflag
, success
));
171 PyThread_release_lock(PyThread_type_lock lock
)
173 dprintf(("PyThread_release_lock(%p) called\n", lock
));
174 if (mutex_unlock((mutex_t
*) lock
))
175 perror("mutex_unlock");
182 PyThread_allocate_sema(int value
)
185 dprintf(("PyThread_allocate_sema called\n"));
187 PyThread_init_thread();
189 sema
= (sema_t
*) malloc(sizeof(sema_t
));
190 if (sema_init(sema
, value
, USYNC_THREAD
, 0)) {
195 dprintf(("PyThread_allocate_sema() -> %p\n", sema
));
196 return (PyThread_type_sema
) sema
;
200 PyThread_free_sema(PyThread_type_sema sema
)
202 dprintf(("PyThread_free_sema(%p) called\n", sema
));
203 if (sema_destroy((sema_t
*) sema
))
204 perror("sema_destroy");
209 PyThread_down_sema(PyThread_type_sema sema
, int waitflag
)
213 dprintf(("PyThread_down_sema(%p) called\n", sema
));
215 success
= sema_wait((sema_t
*) sema
);
217 success
= sema_trywait((sema_t
*) sema
);
226 dprintf(("PyThread_down_sema(%p) return %d\n", sema
, success
));
231 PyThread_up_sema(PyThread_type_sema sema
)
233 dprintf(("PyThread_up_sema(%p)\n", sema
));
234 if (sema_post((sema_t
*) sema
))