public enqueue ( |
||
info | ||
리턴 | void |
public CallOneResult callOne(int timeout) { setupTLS(); ICallbackInfo cbinfo = null; lock (mutex) { if (!enabled) { return(CallOneResult.Disabled); } if (Count == 0 && timeout != 0) { sem.WaitOne(timeout, false); } if (Count == 0) { return(CallOneResult.Empty); } if (!enabled) { return(CallOneResult.Disabled); } for (int i = 0; i < callbacks.Count; i++) { ICallbackInfo info = callbacks[i]; if (info.marked_for_removal) { callbacks.RemoveAt(--i); Count--; continue; } if (info.Callback.ready()) { cbinfo = info; callbacks.RemoveAt(--i); Count--; break; } } sem.Release(); if (cbinfo != null && cbinfo.Callback == null) { return(CallOneResult.TryAgain); } calling++; } tls.enqueue(cbinfo); CallOneResult res = callOneCB(tls); if (res != CallOneResult.Empty) { lock (mutex) { --calling; } } return(res); }
public bool callAvailable(int timeout) { // UnityEngine.Debug.Log ( "calling" ); setupTLS(); int called = 0; lock (mutex) { if (!enabled) { return(false); } } if (Count == 0 && timeout != 0) { if (!sem.WaitOne(timeout)) { return(true); } } lock (mutex) { if (Count == 0) { return(true); } if (!enabled) { return(false); } callbacks.ForEach(cbi => tls.enqueue(cbi)); callbacks.Clear(); Count = 0; calling += tls.Count; } while (tls.Count > 0 && ROS.ok) { if (callOneCB(tls) != CallOneResult.Empty) { ++called; } } lock (mutex) { calling -= called; } sem.Set(); return(true); }