+++ /dev/null
-\r
-#include <stdlib.h>\r
-#include <stdio.h>\r
-#include <errno.h>\r
-#include </usr/include/thread.h>\r
-#undef _POSIX_THREADS\r
-\r
-\r
-/*\r
- * Initialization.\r
- */\r
-static void PyThread__init_thread(void)\r
-{\r
-}\r
-\r
-/*\r
- * Thread support.\r
- */\r
-struct func_arg {\r
- void (*func)(void *);\r
- void *arg;\r
-};\r
-\r
-static void *\r
-new_func(void *funcarg)\r
-{\r
- void (*func)(void *);\r
- void *arg;\r
-\r
- func = ((struct func_arg *) funcarg)->func;\r
- arg = ((struct func_arg *) funcarg)->arg;\r
- free(funcarg);\r
- (*func)(arg);\r
- return 0;\r
-}\r
-\r
-\r
-long\r
-PyThread_start_new_thread(void (*func)(void *), void *arg)\r
-{\r
- thread_t tid;\r
- struct func_arg *funcarg;\r
-\r
- dprintf(("PyThread_start_new_thread called\n"));\r
- if (!initialized)\r
- PyThread_init_thread();\r
- funcarg = (struct func_arg *) malloc(sizeof(struct func_arg));\r
- funcarg->func = func;\r
- funcarg->arg = arg;\r
- if (thr_create(0, 0, new_func, funcarg,\r
- THR_DETACHED | THR_NEW_LWP, &tid)) {\r
- perror("thr_create");\r
- free((void *) funcarg);\r
- return -1;\r
- }\r
- return tid;\r
-}\r
-\r
-long\r
-PyThread_get_thread_ident(void)\r
-{\r
- if (!initialized)\r
- PyThread_init_thread();\r
- return thr_self();\r
-}\r
-\r
-void\r
-PyThread_exit_thread(void)\r
-{\r
- dprintf(("PyThread_exit_thread called\n"));\r
- if (!initialized)\r
- exit(0);\r
- thr_exit(0);\r
-}\r
-\r
-/*\r
- * Lock support.\r
- */\r
-PyThread_type_lock\r
-PyThread_allocate_lock(void)\r
-{\r
- mutex_t *lock;\r
-\r
- dprintf(("PyThread_allocate_lock called\n"));\r
- if (!initialized)\r
- PyThread_init_thread();\r
-\r
- lock = (mutex_t *) malloc(sizeof(mutex_t));\r
- if (mutex_init(lock, USYNC_THREAD, 0)) {\r
- perror("mutex_init");\r
- free((void *) lock);\r
- lock = 0;\r
- }\r
- dprintf(("PyThread_allocate_lock() -> %p\n", lock));\r
- return (PyThread_type_lock) lock;\r
-}\r
-\r
-void\r
-PyThread_free_lock(PyThread_type_lock lock)\r
-{\r
- dprintf(("PyThread_free_lock(%p) called\n", lock));\r
- mutex_destroy((mutex_t *) lock);\r
- free((void *) lock);\r
-}\r
-\r
-int\r
-PyThread_acquire_lock(PyThread_type_lock lock, int waitflag)\r
-{\r
- int success;\r
-\r
- dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag));\r
- if (waitflag)\r
- success = mutex_lock((mutex_t *) lock);\r
- else\r
- success = mutex_trylock((mutex_t *) lock);\r
- if (success < 0)\r
- perror(waitflag ? "mutex_lock" : "mutex_trylock");\r
- else\r
- success = !success; /* solaris does it the other way round */\r
- dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success));\r
- return success;\r
-}\r
-\r
-void\r
-PyThread_release_lock(PyThread_type_lock lock)\r
-{\r
- dprintf(("PyThread_release_lock(%p) called\n", lock));\r
- if (mutex_unlock((mutex_t *) lock))\r
- perror("mutex_unlock");\r
-}\r