private void SetupTls()
 {
     if (tls == null)
     {
         tls = new TLS
         {
             calling_in_this_thread = Thread.CurrentThread.ManagedThreadId
         };
     }
 }
Esempio n. 2
0
        private CallOneResult CallOne(TLS tls)
        {
            CallbackInfo info = tls.Head;

            if (info == null)
            {
                return(CallOneResult.Empty);
            }
            IDInfo idinfo = null;

            idinfo = GetIdInfo(info.RemovalId);
            if (idinfo != null)
            {
                CallbackInterface cb = info.Callback;
                lock (idinfo.calling_rw_mutex)
                {
                    CallbackInterface.CallResult result = CallbackInterface.CallResult.Invalid;
                    tls.SpliceOut(info);
                    if (!info.MarkedForRemoval)
                    {
                        try
                        {
                            result = cb.Call();
                        }
                        catch (Exception ex)
                        {
                            ROS.Error()($"[{ThisNode.Name}] Error during callback. Error: {ex.ToString()}, Stacktrace: {ex.StackTrace}");
                        }
                    }
                    if (result == CallbackInterface.CallResult.TryAgain && !info.MarkedForRemoval)
                    {
                        lock ( mutex )
                        {
                            callbacks.Add(info);
                            count++;
                        }
                        return(CallOneResult.TryAgain);
                    }
                }
                return(CallOneResult.Called);
            }
            CallbackInfo cbi = tls.SpliceOut(info);

            if (cbi != null)
            {
                cbi.Callback.Call();
            }
            return(CallOneResult.Called);
        }
        public CallOneResult CallOne(TLS tls)
        {
            CallbackInfo info = tls.Head;

            if (info == null)
            {
                return(CallOneResult.Empty);
            }
            IDInfo idinfo = null;

            idinfo = GetIdInfo(info.RemovalId);
            if (idinfo != null)
            {
                CallbackInterface cb = info.Callback;
                lock (idinfo.calling_rw_mutex)
                {
                    CallbackInterface.CallResult result = CallbackInterface.CallResult.Invalid;
                    tls.SpliceOut(info);
                    if (!info.MarkedForRemoval)
                    {
                        result = cb.Call();
                    }
                    if (result == CallbackInterface.CallResult.TryAgain && !info.MarkedForRemoval)
                    {
                        lock ( mutex )
                        {
                            callbacks.Add(info);
                            count++;
                        }
                        return(CallOneResult.TryAgain);
                    }
                }
                return(CallOneResult.Called);
            }
            CallbackInfo cbi = tls.SpliceOut(info);

            if (cbi != null)
            {
                cbi.Callback.Call();
            }
            return(CallOneResult.Called);
        }