Exemplo n.º 1
0
		internal static bool SignalAndWait (StWaitable tos, StWaitable tow, StCancelArgs cargs)
		{
			if (tos == tow) {
				return true;
			}

			var pk = new StParker ();
			StWaitBlock hint = null;
			int sc = 0;
			StWaitBlock wb = tow._WaitAnyPrologue (pk, StParkStatus.Success, ref hint, ref sc);

			if (!tos._Release ()) {
				if (wb != null && pk.TryCancel ()) {
               tow._CancelAcquire (wb, hint);
            } else {
					if (wb != null) { 
						pk.Park ();
					}
					tow._UndoAcquire ();
				}

				throw tos._SignalException;
			}

			int ws;
			
			if (hint == INFLATED || (ws = pk.Park (sc, cargs)) == StParkStatus.Inflated) {
				return tow.InflatedWait (cargs);
			}

			if (ws == StParkStatus.Success) {
				tow._WaitEpilogue ();
				return true;
			}

			tow._CancelAcquire (wb, hint);
			cargs.ThrowIfException (ws);
			return false;
		}