儲存庫 vbox 的更動 18326
- 時間撮記:
- 2009-3-26 下午04:23:13 (16 年 以前)
- 檔案:
-
- 修改 1 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/GuestHost/OpenGL/util/threads.c
r15532 r18326 4 4 * See the file LICENSE.txt for information on redistributing this software. 5 5 */ 6 6 7 7 #include <stdio.h> 8 8 #include "cr_threads.h" … … 23 23 { 24 24 #ifdef WINDOWS 25 26 27 28 29 30 #else 31 32 33 34 35 #endif 36 25 tsd->key = TlsAlloc(); 26 if (tsd->key == 0xffffffff) { 27 crError("crInitTSD failed!"); 28 } 29 (void) destructor; 30 #else 31 if (pthread_key_create(&tsd->key, destructor) != 0) { 32 perror(INIT_TSD_ERROR); 33 crError("crInitTSD failed!"); 34 } 35 #endif 36 tsd->initMagic = INIT_MAGIC; 37 37 } 38 38 … … 47 47 { 48 48 #ifdef WINDOWS 49 50 51 52 53 #else 54 55 56 57 58 #endif 59 49 /* Windows returns true on success, 0 on failure */ 50 if (TlsFree(tsd->key) == 0) { 51 crError("crFreeTSD failed!"); 52 } 53 #else 54 if (pthread_key_delete(tsd->key) != 0) { 55 perror(FREE_TSD_ERROR); 56 crError("crFreeTSD failed!"); 57 } 58 #endif 59 tsd->initMagic = 0x0; 60 60 } 61 61 … … 64 64 void crSetTSD(CRtsd *tsd, void *ptr) 65 65 { 66 67 68 69 70 #ifdef WINDOWS 71 72 73 74 #else 75 76 77 66 if (tsd->initMagic != (int) INIT_MAGIC) { 67 /* initialize this CRtsd */ 68 crInitTSD(tsd); 69 } 70 #ifdef WINDOWS 71 if (TlsSetValue(tsd->key, ptr) == 0) { 72 crError("crSetTSD failed!"); 73 } 74 #else 75 if (pthread_setspecific(tsd->key, ptr) != 0) { 76 crError("crSetTSD failed!"); 77 } 78 78 #endif 79 79 } … … 84 84 { 85 85 #ifdef WINDOWS 86 87 88 89 #endif 90 91 92 93 #ifdef WINDOWS 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 #else 113 86 void * value; 87 DWORD err; 88 LPVOID lpMsgBuf; 89 #endif 90 if (tsd->initMagic != (int) INIT_MAGIC) { 91 crInitTSD(tsd); 92 } 93 #ifdef WINDOWS 94 value = TlsGetValue(tsd->key); 95 if (!value) { 96 err = GetLastError(); 97 if ( err != ERROR_SUCCESS ) { 98 FormatMessage( 99 FORMAT_MESSAGE_ALLOCATE_BUFFER | 100 FORMAT_MESSAGE_FROM_SYSTEM | 101 FORMAT_MESSAGE_IGNORE_INSERTS, 102 NULL, 103 err, 104 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 105 (LPTSTR) &lpMsgBuf, 106 0, NULL ); 107 crError("crGetTSD failed with %d: %s", err, lpMsgBuf); 108 LocalFree(lpMsgBuf); 109 } 110 } 111 return value; 112 #else 113 return pthread_getspecific(tsd->key); 114 114 #endif 115 115 } … … 121 121 { 122 122 #ifdef WINDOWS 123 124 #else 125 123 return (unsigned long) GetCurrentThreadId(); 124 #else 125 return (unsigned long) pthread_self(); 126 126 #endif 127 127 } … … 132 132 { 133 133 #ifdef WINDOWS 134 135 #else 136 134 InitializeCriticalSection(mutex); 135 #else 136 pthread_mutex_init(mutex, NULL); 137 137 #endif 138 138 } … … 142 142 { 143 143 #ifdef WINDOWS 144 145 #else 146 144 DeleteCriticalSection(mutex); 145 #else 146 pthread_mutex_destroy(mutex); 147 147 #endif 148 148 } … … 152 152 { 153 153 #ifdef WINDOWS 154 155 #else 156 154 EnterCriticalSection(mutex); 155 #else 156 pthread_mutex_lock(mutex); 157 157 #endif 158 158 } … … 162 162 { 163 163 #ifdef WINDOWS 164 165 #else 166 164 LeaveCriticalSection(mutex); 165 #else 166 pthread_mutex_unlock(mutex); 167 167 #endif 168 168 } … … 172 172 { 173 173 #ifdef WINDOWS 174 175 176 #else 177 178 179 180 174 /* XXX fix me */ 175 (void) cond; 176 #else 177 int err = pthread_cond_init(cond, NULL); 178 if (err) { 179 crError("crInitCondition failed"); 180 } 181 181 #endif 182 182 } … … 186 186 { 187 187 #ifdef WINDOWS 188 189 190 #else 191 192 193 194 188 /* XXX fix me */ 189 (void) cond; 190 #else 191 int err = pthread_cond_destroy(cond); 192 if (err) { 193 crError("crFreeCondition error (threads waiting on the condition?)"); 194 } 195 195 #endif 196 196 } … … 203 203 { 204 204 #ifdef WINDOWS 205 206 207 208 #else 209 205 /* XXX fix me */ 206 (void) cond; 207 (void) mutex; 208 #else 209 pthread_cond_wait(cond, mutex); 210 210 #endif 211 211 } … … 215 215 { 216 216 #ifdef WINDOWS 217 218 219 #else 220 217 /* XXX fix me */ 218 (void) cond; 219 #else 220 pthread_cond_signal(cond); 221 221 #endif 222 222 } … … 226 226 { 227 227 #ifdef WINDOWS 228 229 230 231 #else 232 233 234 235 228 unsigned int i; 229 for (i = 0; i < count; i++) 230 b->hEvents[i] = CreateEvent(NULL, FALSE, FALSE, NULL); 231 #else 232 b->count = count; 233 b->waiting = 0; 234 pthread_cond_init( &(b->cond), NULL ); 235 pthread_mutex_init( &(b->mutex), NULL ); 236 236 #endif 237 237 } … … 240 240 void crFreeBarrier(CRbarrier *b) 241 241 { 242 242 /* XXX anything to do? */ 243 243 } 244 244 … … 247 247 { 248 248 #ifdef WINDOWS 249 250 251 #else 252 253 254 255 256 257 258 259 260 261 249 DWORD dwEvent 250 = WaitForMultipleObjects( b->count, b->hEvents, FALSE, INFINITE ); 251 #else 252 pthread_mutex_lock( &(b->mutex) ); 253 b->waiting++; 254 if (b->waiting < b->count) { 255 pthread_cond_wait( &(b->cond), &(b->mutex) ); 256 } 257 else { 258 pthread_cond_broadcast( &(b->cond) ); 259 b->waiting = 0; 260 } 261 pthread_mutex_unlock( &(b->mutex) ); 262 262 #endif 263 263 } … … 267 267 { 268 268 #ifdef WINDOWS 269 270 #else 271 269 crWarning("CRsemaphore functions not implemented on Windows"); 270 #else 271 sem_init(s, 0, count); 272 272 #endif 273 273 } … … 277 277 { 278 278 #ifdef WINDOWS 279 280 #else 281 279 /* to do */ 280 #else 281 sem_wait(s); 282 282 #endif 283 283 } … … 287 287 { 288 288 #ifdef WINDOWS 289 290 #else 291 292 #endif 293 } 294 289 /* to do */ 290 #else 291 sem_post(s); 292 #endif 293 } 294
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器