4 #include <lwp/stackdep.h>
6 #define STACKSIZE 1000 /* stacksize for a thread */
7 #define NSTACKS 2 /* # stacks to be put in cache initially */
19 static void PyThread__init_thread(void)
21 lwp_setstkcache(STACKSIZE
, NSTACKS
);
29 long PyThread_start_new_thread(void (*func
)(void *), void *arg
)
33 dprintf(("PyThread_start_new_thread called\n"));
35 PyThread_init_thread();
36 success
= lwp_create(&tid
, func
, MINPRIO
, 0, lwp_newstk(), 1, arg
);
37 return success
< 0 ? -1 : 0;
40 long PyThread_get_thread_ident(void)
44 PyThread_init_thread();
45 if (lwp_self(&tid
) < 0)
50 static void do_PyThread_exit_thread(int no_cleanup
)
52 dprintf(("PyThread_exit_thread called\n"));
61 void PyThread_exit_thread(void)
63 do_PyThread_exit_thread(0);
66 void PyThread__exit_thread(void)
68 do_PyThread_exit_thread(1);
72 static void do_PyThread_exit_prog(int status
, int no_cleanup
)
74 dprintf(("PyThread_exit_prog(%d) called\n", status
));
83 void PyThread_exit_prog(int status
)
85 do_PyThread_exit_prog(status
, 0);
88 void PyThread__exit_prog(int status
)
90 do_PyThread_exit_prog(status
, 1);
92 #endif /* NO_EXIT_PROG */
97 PyThread_type_lock
PyThread_allocate_lock(void)
100 extern char *malloc(size_t);
102 dprintf(("PyThread_allocate_lock called\n"));
104 PyThread_init_thread();
106 lock
= (struct lock
*) malloc(sizeof(struct lock
));
107 lock
->lock_locked
= 0;
108 (void) mon_create(&lock
->lock_monitor
);
109 (void) cv_create(&lock
->lock_condvar
, lock
->lock_monitor
);
110 dprintf(("PyThread_allocate_lock() -> %p\n", lock
));
111 return (PyThread_type_lock
) lock
;
114 void PyThread_free_lock(PyThread_type_lock lock
)
116 dprintf(("PyThread_free_lock(%p) called\n", lock
));
117 mon_destroy(((struct lock
*) lock
)->lock_monitor
);
121 int PyThread_acquire_lock(PyThread_type_lock lock
, int waitflag
)
125 dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock
, waitflag
));
128 (void) mon_enter(((struct lock
*) lock
)->lock_monitor
);
130 while (((struct lock
*) lock
)->lock_locked
)
131 cv_wait(((struct lock
*) lock
)->lock_condvar
);
132 if (!((struct lock
*) lock
)->lock_locked
) {
134 ((struct lock
*) lock
)->lock_locked
= 1;
136 cv_broadcast(((struct lock
*) lock
)->lock_condvar
);
137 mon_exit(((struct lock
*) lock
)->lock_monitor
);
138 dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock
, waitflag
, success
));
142 void PyThread_release_lock(PyThread_type_lock lock
)
144 dprintf(("PyThread_release_lock(%p) called\n", lock
));
145 (void) mon_enter(((struct lock
*) lock
)->lock_monitor
);
146 ((struct lock
*) lock
)->lock_locked
= 0;
147 cv_broadcast(((struct lock
*) lock
)->lock_condvar
);
148 mon_exit(((struct lock
*) lock
)->lock_monitor
);