Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 1 | /*********************************************************** |
| 2 | Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum, |
| 3 | Amsterdam, The Netherlands. |
| 4 | |
| 5 | All Rights Reserved |
| 6 | |
| 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
| 9 | provided that the above copyright notice appear in all copies and that |
| 10 | both that copyright notice and this permission notice appear in |
| 11 | supporting documentation, and that the names of Stichting Mathematisch |
| 12 | Centrum or CWI not be used in advertising or publicity pertaining to |
| 13 | distribution of the software without specific, written prior permission. |
| 14 | |
| 15 | STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO |
| 16 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 17 | FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE |
| 18 | FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 19 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 20 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 21 | OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 22 | |
| 23 | ******************************************************************/ |
| 24 | |
| 25 | #include <cthreads.h> |
| 26 | |
| 27 | |
| 28 | /* |
| 29 | * Initialization. |
| 30 | */ |
| 31 | static void _init_thread _P0() |
| 32 | { |
| 33 | cthread_init(); |
| 34 | } |
| 35 | |
| 36 | /* |
| 37 | * Thread support. |
| 38 | */ |
| 39 | int start_new_thread _P2(func, void (*func) _P((void *)), arg, void *arg) |
| 40 | { |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 41 | int success = 0; /* init not needed when SOLARIS_THREADS and */ |
| 42 | /* C_THREADS implemented properly */ |
| 43 | |
| 44 | dprintf(("start_new_thread called\n")); |
| 45 | if (!initialized) |
| 46 | init_thread(); |
| 47 | (void) cthread_fork(func, arg); |
| 48 | return success < 0 ? 0 : 1; |
| 49 | } |
| 50 | |
Guido van Rossum | e944da8 | 1994-05-23 12:43:41 +0000 | [diff] [blame] | 51 | long get_thread_ident _P0() |
| 52 | { |
| 53 | if (!initialized) |
| 54 | init_thread(); |
| 55 | } |
| 56 | |
Guido van Rossum | 2c8cb9f | 1994-05-09 15:12:46 +0000 | [diff] [blame] | 57 | static void do_exit_thread _P1(no_cleanup, int no_cleanup) |
| 58 | { |
| 59 | dprintf(("exit_thread called\n")); |
| 60 | if (!initialized) |
| 61 | if (no_cleanup) |
| 62 | _exit(0); |
| 63 | else |
| 64 | exit(0); |
| 65 | cthread_exit(0); |
| 66 | } |
| 67 | |
| 68 | void exit_thread _P0() |
| 69 | { |
| 70 | do_exit_thread(0); |
| 71 | } |
| 72 | |
| 73 | void _exit_thread _P0() |
| 74 | { |
| 75 | do_exit_thread(1); |
| 76 | } |
| 77 | |
| 78 | #ifndef NO_EXIT_PROG |
| 79 | static void do_exit_prog _P2(status, int status, no_cleanup, int no_cleanup) |
| 80 | { |
| 81 | dprintf(("exit_prog(%d) called\n", status)); |
| 82 | if (!initialized) |
| 83 | if (no_cleanup) |
| 84 | _exit(status); |
| 85 | else |
| 86 | exit(status); |
| 87 | } |
| 88 | |
| 89 | void exit_prog _P1(status, int status) |
| 90 | { |
| 91 | do_exit_prog(status, 0); |
| 92 | } |
| 93 | |
| 94 | void _exit_prog _P1(status, int status) |
| 95 | { |
| 96 | do_exit_prog(status, 1); |
| 97 | } |
| 98 | #endif /* NO_EXIT_PROG */ |
| 99 | |
| 100 | /* |
| 101 | * Lock support. |
| 102 | */ |
| 103 | type_lock allocate_lock _P0() |
| 104 | { |
| 105 | |
| 106 | dprintf(("allocate_lock called\n")); |
| 107 | if (!initialized) |
| 108 | init_thread(); |
| 109 | |
| 110 | dprintf(("allocate_lock() -> %lx\n", (long)lock)); |
| 111 | return (type_lock) lock; |
| 112 | } |
| 113 | |
| 114 | void free_lock _P1(lock, type_lock lock) |
| 115 | { |
| 116 | dprintf(("free_lock(%lx) called\n", (long)lock)); |
| 117 | } |
| 118 | |
| 119 | int acquire_lock _P2(lock, type_lock lock, waitflag, int waitflag) |
| 120 | { |
| 121 | int success; |
| 122 | |
| 123 | dprintf(("acquire_lock(%lx, %d) called\n", (long)lock, waitflag)); |
| 124 | dprintf(("acquire_lock(%lx, %d) -> %d\n", (long)lock, waitflag, success)); |
| 125 | return success; |
| 126 | } |
| 127 | |
| 128 | void release_lock _P1(lock, type_lock lock) |
| 129 | { |
| 130 | dprintf(("release_lock(%lx) called\n", (long)lock)); |
| 131 | } |
| 132 | |
| 133 | /* |
| 134 | * Semaphore support. |
| 135 | */ |
| 136 | type_sema allocate_sema _P1(value, int value) |
| 137 | { |
| 138 | dprintf(("allocate_sema called\n")); |
| 139 | if (!initialized) |
| 140 | init_thread(); |
| 141 | |
| 142 | dprintf(("allocate_sema() -> %lx\n", (long) sema)); |
| 143 | return (type_sema) sema; |
| 144 | } |
| 145 | |
| 146 | void free_sema _P1(sema, type_sema sema) |
| 147 | { |
| 148 | dprintf(("free_sema(%lx) called\n", (long) sema)); |
| 149 | } |
| 150 | |
| 151 | void down_sema _P1(sema, type_sema sema) |
| 152 | { |
| 153 | dprintf(("down_sema(%lx) called\n", (long) sema)); |
| 154 | dprintf(("down_sema(%lx) return\n", (long) sema)); |
| 155 | } |
| 156 | |
| 157 | void up_sema _P1(sema, type_sema sema) |
| 158 | { |
| 159 | dprintf(("up_sema(%lx)\n", (long) sema)); |
| 160 | } |