public override void addCallback(CallbackInterface cb, UInt64 owner_id) { ICallbackInfo info = new ICallbackInfo { Callback = cb, removal_id = owner_id }; lock (mutex) { if (!enabled) { return; } callbacks.Add(info); Count++; } lock (id_info_mutex) { if (!id_info.ContainsKey(owner_id)) { id_info.Add(owner_id, new IDInfo { calling_rw_mutex = new object(), id = owner_id }); } } notify_one(); }
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 CallOneResult callOneCB(TLS tls) { ICallbackInfo info = tls.head; if (info == null) { return(CallOneResult.Empty); } IDInfo idinfo = null; idinfo = getIDInfo(info.removal_id); if (idinfo != null) { CallbackInterface cb = info.Callback; lock (idinfo.calling_rw_mutex) { CallbackInterface.CallResult result = CallbackInterface.CallResult.Invalid; tls.spliceout(info); if (!info.marked_for_removal) { result = cb.Call(); } if (result == CallbackInterface.CallResult.TryAgain && !info.marked_for_removal) { lock (mutex) { callbacks.Add(info); Count++; } return(CallOneResult.TryAgain); } } return(CallOneResult.Called); } ICallbackInfo cbi = tls.spliceout(info); if (cbi != null) { cbi.Callback.Call(); } return(CallOneResult.Called); }
internal bool addCallback( ISubscriptionCallbackHelper helper, string md5sum, ICallbackQueue queue, int queue_size, bool allow_concurrent_callbacks, string topiclol ) { lock ( md5sum_mutex ) { if (this.md5sum == "*" && md5sum != "*") { this.md5sum = md5sum; } } if (md5sum != "*" && md5sum != this.md5sum) { return(false); } lock ( callbacks_mutex ) { ICallbackInfo info = new ICallbackInfo { helper = helper, callback = queue, subscription_queue = new Callback(helper.Callback.SendEvent, topiclol, queue_size, allow_concurrent_callbacks) }; //if (!helper.isConst()) //{ ++nonconst_callbacks; //} callbacks.Add(info); if (latched_messages.Count > 0) { string ti = info.helper.type; lock ( publisher_links_mutex ) { foreach (PublisherLink link in publisher_links) { if (link.Latched) { if (latched_messages.ContainsKey(link)) { LatchInfo latch_info = latched_messages[link]; bool was_full = false; bool nonconst_need_copy = callbacks.Count > 1; info.subscription_queue.AddToCallbackQueue(info.helper, latched_messages[link].message, nonconst_need_copy, ref was_full, ROS.GetTime().data); if (!was_full) { info.callback.AddCallback(info.subscription_queue); } } } } } } } return(true); }
public override void addCallback(CallbackInterface cb, UInt64 owner_id) { ICallbackInfo info = new ICallbackInfo {Callback = cb, removal_id = owner_id}; lock (mutex) { if (!enabled) return; callbacks.Add(info); Count++; } lock (id_info_mutex) { if (!id_info.ContainsKey(owner_id)) { id_info.Add(owner_id, new IDInfo {calling_rw_mutex = new object(), id = owner_id}); } } notify_one(); }