< prev index next >

src/hotspot/os/windows/os_windows.cpp

Print this page




5219   guarantee(_Event >= 0, "invariant");
5220 }
5221 
5222 void os::PlatformEvent::unpark() {
5223   guarantee(_ParkHandle != NULL, "Invariant");
5224 
5225   // Transitions for _Event:
5226   //    0 => 1 : just return
5227   //    1 => 1 : just return
5228   //   -1 => either 0 or 1; must signal target thread
5229   //         That is, we can safely transition _Event from -1 to either
5230   //         0 or 1.
5231   // See also: "Semaphores in Plan 9" by Mullender & Cox
5232   //
5233   // Note: Forcing a transition from "-1" to "1" on an unpark() means
5234   // that it will take two back-to-back park() calls for the owning
5235   // thread to block. This has the benefit of forcing a spurious return
5236   // from the first park() call after an unpark() call which will help
5237   // shake out uses of park() and unpark() without condition variables.
5238 
5239   if (Atomic::xchg(1, &_Event) >= 0) return;
5240 
5241   ::SetEvent(_ParkHandle);
5242 }
5243 
5244 
5245 // JSR166
5246 // -------------------------------------------------------
5247 
5248 // The Windows implementation of Park is very straightforward: Basic
5249 // operations on Win32 Events turn out to have the right semantics to
5250 // use them directly. We opportunistically resuse the event inherited
5251 // from Monitor.
5252 
5253 void Parker::park(bool isAbsolute, jlong time) {
5254   guarantee(_ParkEvent != NULL, "invariant");
5255   // First, demultiplex/decode time arguments
5256   if (time < 0) { // don't wait
5257     return;
5258   } else if (time == 0 && !isAbsolute) {
5259     time = INFINITE;




5219   guarantee(_Event >= 0, "invariant");
5220 }
5221 
5222 void os::PlatformEvent::unpark() {
5223   guarantee(_ParkHandle != NULL, "Invariant");
5224 
5225   // Transitions for _Event:
5226   //    0 => 1 : just return
5227   //    1 => 1 : just return
5228   //   -1 => either 0 or 1; must signal target thread
5229   //         That is, we can safely transition _Event from -1 to either
5230   //         0 or 1.
5231   // See also: "Semaphores in Plan 9" by Mullender & Cox
5232   //
5233   // Note: Forcing a transition from "-1" to "1" on an unpark() means
5234   // that it will take two back-to-back park() calls for the owning
5235   // thread to block. This has the benefit of forcing a spurious return
5236   // from the first park() call after an unpark() call which will help
5237   // shake out uses of park() and unpark() without condition variables.
5238 
5239   if (Atomic::xchg(&_Event, 1) >= 0) return;
5240 
5241   ::SetEvent(_ParkHandle);
5242 }
5243 
5244 
5245 // JSR166
5246 // -------------------------------------------------------
5247 
5248 // The Windows implementation of Park is very straightforward: Basic
5249 // operations on Win32 Events turn out to have the right semantics to
5250 // use them directly. We opportunistically resuse the event inherited
5251 // from Monitor.
5252 
5253 void Parker::park(bool isAbsolute, jlong time) {
5254   guarantee(_ParkEvent != NULL, "invariant");
5255   // First, demultiplex/decode time arguments
5256   if (time < 0) { // don't wait
5257     return;
5258   } else if (time == 0 && !isAbsolute) {
5259     time = INFINITE;


< prev index next >