Changeset 391 for python/trunk/Python/thread_solaris.h
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Python/thread_solaris.h
r2 r391 18 18 */ 19 19 struct func_arg { 20 21 20 void (*func)(void *); 21 void *arg; 22 22 }; 23 23 … … 25 25 new_func(void *funcarg) 26 26 { 27 28 27 void (*func)(void *); 28 void *arg; 29 29 30 31 32 33 34 30 func = ((struct func_arg *) funcarg)->func; 31 arg = ((struct func_arg *) funcarg)->arg; 32 free(funcarg); 33 (*func)(arg); 34 return 0; 35 35 } 36 36 … … 39 39 PyThread_start_new_thread(void (*func)(void *), void *arg) 40 40 { 41 42 41 thread_t tid; 42 struct func_arg *funcarg; 43 43 44 45 46 47 48 49 50 51 52 53 54 55 56 44 dprintf(("PyThread_start_new_thread called\n")); 45 if (!initialized) 46 PyThread_init_thread(); 47 funcarg = (struct func_arg *) malloc(sizeof(struct func_arg)); 48 funcarg->func = func; 49 funcarg->arg = arg; 50 if (thr_create(0, 0, new_func, funcarg, 51 THR_DETACHED | THR_NEW_LWP, &tid)) { 52 perror("thr_create"); 53 free((void *) funcarg); 54 return -1; 55 } 56 return tid; 57 57 } 58 58 … … 60 60 PyThread_get_thread_ident(void) 61 61 { 62 63 64 62 if (!initialized) 63 PyThread_init_thread(); 64 return thr_self(); 65 65 } 66 66 67 static void 68 do_PyThread_exit_thread(int no_cleanup) 69 { 70 dprintf(("PyThread_exit_thread called\n")); 71 if (!initialized) 72 if (no_cleanup) 73 _exit(0); 74 else 75 exit(0); 76 thr_exit(0); 77 } 78 79 void 67 void 80 68 PyThread_exit_thread(void) 81 69 { 82 do_PyThread_exit_thread(0); 70 dprintf(("PyThread_exit_thread called\n")); 71 if (!initialized) 72 exit(0); 73 thr_exit(0); 83 74 } 84 85 void86 PyThread__exit_thread(void)87 {88 do_PyThread_exit_thread(1);89 }90 91 #ifndef NO_EXIT_PROG92 static void93 do_PyThread_exit_prog(int status, int no_cleanup)94 {95 dprintf(("PyThread_exit_prog(%d) called\n", status));96 if (!initialized)97 if (no_cleanup)98 _exit(status);99 else100 exit(status);101 if (no_cleanup)102 _exit(status);103 else104 exit(status);105 }106 107 void108 PyThread_exit_prog(int status)109 {110 do_PyThread_exit_prog(status, 0);111 }112 113 void114 PyThread__exit_prog(int status)115 {116 do_PyThread_exit_prog(status, 1);117 }118 #endif /* NO_EXIT_PROG */119 75 120 76 /* 121 77 * Lock support. 122 78 */ 123 PyThread_type_lock 79 PyThread_type_lock 124 80 PyThread_allocate_lock(void) 125 81 { 126 82 mutex_t *lock; 127 83 128 129 130 84 dprintf(("PyThread_allocate_lock called\n")); 85 if (!initialized) 86 PyThread_init_thread(); 131 87 132 133 134 135 136 137 138 139 88 lock = (mutex_t *) malloc(sizeof(mutex_t)); 89 if (mutex_init(lock, USYNC_THREAD, 0)) { 90 perror("mutex_init"); 91 free((void *) lock); 92 lock = 0; 93 } 94 dprintf(("PyThread_allocate_lock() -> %p\n", lock)); 95 return (PyThread_type_lock) lock; 140 96 } 141 97 142 void 98 void 143 99 PyThread_free_lock(PyThread_type_lock lock) 144 100 { 145 146 147 101 dprintf(("PyThread_free_lock(%p) called\n", lock)); 102 mutex_destroy((mutex_t *) lock); 103 free((void *) lock); 148 104 } 149 105 150 int 106 int 151 107 PyThread_acquire_lock(PyThread_type_lock lock, int waitflag) 152 108 { 153 109 int success; 154 110 155 156 157 158 159 160 161 162 163 164 165 111 dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag)); 112 if (waitflag) 113 success = mutex_lock((mutex_t *) lock); 114 else 115 success = mutex_trylock((mutex_t *) lock); 116 if (success < 0) 117 perror(waitflag ? "mutex_lock" : "mutex_trylock"); 118 else 119 success = !success; /* solaris does it the other way round */ 120 dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success)); 121 return success; 166 122 } 167 123 168 void 124 void 169 125 PyThread_release_lock(PyThread_type_lock lock) 170 126 { 171 172 173 127 dprintf(("PyThread_release_lock(%p) called\n", lock)); 128 if (mutex_unlock((mutex_t *) lock)) 129 perror("mutex_unlock"); 174 130 }
Note:
See TracChangeset
for help on using the changeset viewer.