5 #include </usr/include/thread.h>
12 static void PyThread__init_thread(void)
25 new_func(void *funcarg
)
30 func
= ((struct func_arg
*) funcarg
)->func
;
31 arg
= ((struct func_arg
*) funcarg
)->arg
;
39 PyThread_start_new_thread(void (*func
)(void *), void *arg
)
42 struct func_arg
*funcarg
;
44 dprintf(("PyThread_start_new_thread called\n"));
46 PyThread_init_thread();
47 funcarg
= (struct func_arg
*) malloc(sizeof(struct func_arg
));
50 if (thr_create(0, 0, new_func
, funcarg
,
51 THR_DETACHED
| THR_NEW_LWP
, &tid
)) {
53 free((void *) funcarg
);
60 PyThread_get_thread_ident(void)
63 PyThread_init_thread();
68 do_PyThread_exit_thread(int no_cleanup
)
70 dprintf(("PyThread_exit_thread called\n"));
80 PyThread_exit_thread(void)
82 do_PyThread_exit_thread(0);
86 PyThread__exit_thread(void)
88 do_PyThread_exit_thread(1);
93 do_PyThread_exit_prog(int status
, int no_cleanup
)
95 dprintf(("PyThread_exit_prog(%d) called\n", status
));
108 PyThread_exit_prog(int status
)
110 do_PyThread_exit_prog(status
, 0);
114 PyThread__exit_prog(int status
)
116 do_PyThread_exit_prog(status
, 1);
118 #endif /* NO_EXIT_PROG */
124 PyThread_allocate_lock(void)
128 dprintf(("PyThread_allocate_lock called\n"));
130 PyThread_init_thread();
132 lock
= (mutex_t
*) malloc(sizeof(mutex_t
));
133 if (mutex_init(lock
, USYNC_THREAD
, 0)) {
134 perror("mutex_init");
138 dprintf(("PyThread_allocate_lock() -> %p\n", lock
));
139 return (PyThread_type_lock
) lock
;
143 PyThread_free_lock(PyThread_type_lock lock
)
145 dprintf(("PyThread_free_lock(%p) called\n", lock
));
146 mutex_destroy((mutex_t
*) lock
);
151 PyThread_acquire_lock(PyThread_type_lock lock
, int waitflag
)
155 dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock
, waitflag
));
157 success
= mutex_lock((mutex_t
*) lock
);
159 success
= mutex_trylock((mutex_t
*) lock
);
161 perror(waitflag
? "mutex_lock" : "mutex_trylock");
163 success
= !success
; /* solaris does it the other way round */
164 dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock
, waitflag
, success
));
169 PyThread_release_lock(PyThread_type_lock lock
)
171 dprintf(("PyThread_release_lock(%p) called\n", lock
));
172 if (mutex_unlock((mutex_t
*) lock
))
173 perror("mutex_unlock");