Changeset 1391 for branches/GNU/src/gcc/libjava/win32-threads.cc
- Timestamp:
- Apr 27, 2004, 8:39:34 PM (21 years ago)
- Location:
- branches/GNU/src/gcc
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/gcc
- Property svn:ignore
-
old new 26 26 configure.vr 27 27 configure.vrs 28 dir.info 28 29 Makefile 29 dir.info30 30 lost+found 31 31 update.out
-
- Property svn:ignore
-
branches/GNU/src/gcc/libjava/win32-threads.cc
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r1390 r1391 1 1 // win32-threads.cc - interface between libjava and Win32 threads. 2 2 3 /* Copyright (C) 1998, 1999 Free Software Foundation, Inc. 3 /* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software 4 Foundation, Inc. 4 5 5 6 This file is part of libgcj. … … 71 72 ensure_condvar_initialized(_Jv_ConditionVariable_t *cv) 72 73 { 73 if (cv->ev[0] == 0) { 74 cv->ev[0] = CreateEvent (NULL, 0, 0, NULL); 75 if (cv->ev[0] == 0) JvFail("CreateEvent() failed"); 76 cv->ev[1] = CreateEvent (NULL, 1, 0, NULL); 77 if (cv->ev[1] == 0) JvFail("CreateEvent() failed"); 78 } 74 if (cv->ev[0] == 0) 75 { 76 cv->ev[0] = CreateEvent (NULL, 0, 0, NULL); 77 if (cv->ev[0] == 0) JvFail("CreateEvent() failed"); 78 79 cv->ev[1] = CreateEvent (NULL, 1, 0, NULL); 80 if (cv->ev[1] == 0) JvFail("CreateEvent() failed"); 81 } 79 82 } 80 83 … … 86 89 _Jv_CondWait(_Jv_ConditionVariable_t *cv, _Jv_Mutex_t *mu, jlong millis, jint nanos) 87 90 { 88 89 EnterCriticalSection(&cv->count_mutex); 90 ensure_condvar_initialized(cv); 91 if (mu->owner != GetCurrentThreadId ( )) 92 return _JV_NOT_OWNER; 93 94 EnterCriticalSection (&cv->count_mutex); 95 ensure_condvar_initialized (cv); 91 96 cv->blocked_count++; 92 LeaveCriticalSection (&cv->count_mutex);97 LeaveCriticalSection (&cv->count_mutex); 93 98 94 99 DWORD time; … … 103 108 EnterCriticalSection(&cv->count_mutex); 104 109 cv->blocked_count--; 105 // If we were unblocked by the second event (the broadcast one) and nobody is106 // left, then reset the signal.107 int last_waiter = rval == WAIT_OBJECT_0 + 1 && cv->blocked_count == 0;110 // If we were unblocked by the second event (the broadcast one) 111 // and nobody is left, then reset the event. 112 int last_waiter = (rval == (WAIT_OBJECT_0 + 1)) && (cv->blocked_count == 0); 108 113 LeaveCriticalSection(&cv->count_mutex); 109 114 110 if (last_waiter) ResetEvent(&cv->ev[1]); 115 if (last_waiter) 116 ResetEvent (cv->ev[1]); 111 117 112 118 _Jv_MutexLock (mu); 113 119 114 if (rval == WAIT_FAILED) return GetLastError(); 115 else if (rval == WAIT_TIMEOUT) return ETIMEDOUT; 116 else return 0; 120 return 0; 117 121 } 118 122 … … 122 126 // we do lazy creation of Events since CreateEvent() is insanely expensive 123 127 cv->ev[0] = 0; 124 InitializeCriticalSection (&cv->count_mutex);128 InitializeCriticalSection (&cv->count_mutex); 125 129 cv->blocked_count = 0; 126 130 } … … 129 133 _Jv_CondDestroy (_Jv_ConditionVariable_t *cv) 130 134 { 131 if (cv->ev[0] != 0) CloseHandle(cv->ev[0]); 132 cv = NULL; 135 if (cv->ev[0] != 0) 136 { 137 CloseHandle (cv->ev[0]); 138 CloseHandle (cv->ev[1]); 139 140 cv->ev[0] = 0; 141 } 142 143 DeleteCriticalSection (&cv->count_mutex); 133 144 } 134 145 135 146 int 136 _Jv_CondNotify (_Jv_ConditionVariable_t *cv, _Jv_Mutex_t *) 137 { 138 EnterCriticalSection(&cv->count_mutex); 139 ensure_condvar_initialized(cv); 147 _Jv_CondNotify (_Jv_ConditionVariable_t *cv, _Jv_Mutex_t *mu) 148 { 149 if (mu->owner != GetCurrentThreadId ( )) 150 return _JV_NOT_OWNER; 151 152 EnterCriticalSection (&cv->count_mutex); 153 ensure_condvar_initialized (cv); 140 154 int somebody_is_blocked = cv->blocked_count > 0; 141 LeaveCriticalSection(&cv->count_mutex); 142 143 if (somebody_is_blocked) return SetEvent (cv->ev[0]) ? 0 : GetLastError(); 144 else return 0; 155 LeaveCriticalSection (&cv->count_mutex); 156 157 if (somebody_is_blocked) 158 SetEvent (cv->ev[0]); 159 160 return 0; 145 161 } 146 162 147 163 int 148 _Jv_CondNotifyAll (_Jv_ConditionVariable_t *cv, _Jv_Mutex_t *) 149 { 150 EnterCriticalSection(&cv->count_mutex); 151 ensure_condvar_initialized(cv); 164 _Jv_CondNotifyAll (_Jv_ConditionVariable_t *cv, _Jv_Mutex_t *mu) 165 { 166 if (mu->owner != GetCurrentThreadId ( )) 167 return _JV_NOT_OWNER; 168 169 EnterCriticalSection (&cv->count_mutex); 170 ensure_condvar_initialized (cv); 152 171 int somebody_is_blocked = cv->blocked_count > 0; 153 LeaveCriticalSection(&cv->count_mutex); 154 155 if (somebody_is_blocked) return SetEvent (cv->ev[1]) ? 0 : GetLastError(); 156 else return 0; 172 LeaveCriticalSection (&cv->count_mutex); 173 174 if (somebody_is_blocked) 175 SetEvent (cv->ev[1]); 176 177 return 0; 157 178 } 158 179 … … 166 187 _Jv_ThreadKey = TlsAlloc(); 167 188 _Jv_ThreadDataKey = TlsAlloc(); 168 daemon_mutex = CreateMutex (NULL, 0, NULL);169 daemon_cond = CreateEvent (NULL, 0, 0, NULL);189 daemon_mutex = CreateMutex (NULL, 0, NULL); 190 daemon_cond = CreateEvent (NULL, 1, 0, NULL); 170 191 non_daemon_count = 0; 171 192 } … … 256 277 non_daemon_count--; 257 278 if (! non_daemon_count) 258 PulseEvent (daemon_cond);279 SetEvent (daemon_cond); 259 280 ReleaseMutex (daemon_mutex); 260 281 } … … 298 319 _Jv_ThreadWait (void) 299 320 { 300 WaitForSingleObject(daemon_mutex, INFINITE); 301 if(non_daemon_count) 302 SignalObjectAndWait(daemon_mutex, daemon_cond, INFINITE, 0); 303 ReleaseMutex(daemon_mutex); 321 WaitForSingleObject (daemon_mutex, INFINITE); 322 if (non_daemon_count) 323 { 324 ReleaseMutex (daemon_mutex); 325 WaitForSingleObject (daemon_cond, INFINITE); 326 } 304 327 } 305 328 -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.