Пример #1
0
	public static int Main () {
		Console.WriteLine ("Hello, World!");
		Test test=new Test();
		Thread thr=new Thread(new ThreadStart(test.Thread_func));
		thr.Start();

		for(int i=0; i<51200; i++) {
			slot[i]=Thread.AllocateDataSlot();
			Thread.SetData(slot[i], i);
		}
		Thread.SetData(slot[11111], 69);
		Thread.SetData(slot[26801], 69);

		Thread.Sleep(10000);
		
		Console.WriteLine("Main thread done");
		Console.WriteLine("slot 11111 contains " + Thread.GetData(slot[11111]));
		Console.WriteLine("slot 16801 contains " + Thread.GetData(slot[16801]));
		Console.WriteLine("slot 26801 contains " + Thread.GetData(slot[26801]));
		Console.WriteLine("slot 76801 contains " + Thread.GetData(slot[76801]));

		// Test appdomain transitions
		AppDomain ad = AppDomain.CreateDomain ("MyFriendlyDomain");
		Test o = (Test) ad.CreateInstanceFromAndUnwrap ("dataslot.exe", "Test");
		
		slot2 = Thread.AllocateDataSlot ();
		Thread.SetData (slot2, "hello");
		
		o.Foo (AppDomain.CurrentDomain);

		if (Test.slot_value != "hello")
			return 1;

		return 0;
	}
Пример #2
0
 internal static HybridDictionary GetGlobalContext()
 {
     if (HttpContext.Current == null)
     {
         LocalDataStoreSlot slot = Thread.GetNamedDataSlot(_globalContextName);
         return((HybridDictionary)Thread.GetData(slot));
     }
     else
     {
         return((HybridDictionary)HttpContext.Current.Items[_globalContextName]);
     }
 }
Пример #3
0
 internal static void SetGlobalContext(HybridDictionary globalContext)
 {
     if (HttpContext.Current == null)
     {
         LocalDataStoreSlot slot = Thread.GetNamedDataSlot("Dothan.GlobalContext");
         Thread.SetData(slot, globalContext);
     }
     else
     {
         HttpContext.Current.Items["Dothan.GlobalContext"] = globalContext;
     }
 }
Пример #4
0
 public static void SetGlobalContext(HybridDictionary globalContext)
 {
     if (HttpContext.Current == null)
     {
         LocalDataStoreSlot slot = Thread.GetNamedDataSlot(_globalContextName);
         Thread.SetData(slot, globalContext);
     }
     else
     {
         HttpContext.Current.Items[_globalContextName] = globalContext;
     }
 }
Пример #5
0
        LocalDataStoreSlot writeCache;         // thread-local write copy

        public STMObject(ICloneable obj, LocalDataStoreSlot readCache, LocalDataStoreSlot writeCache)
        {
            start           = new Locator(obj);
            this.readCache  = readCache;
            this.writeCache = writeCache;
            // Do not cache objects if not in transaction!
            if (Xaction.IsActive)
            {
                Xaction.AddToCache(readCache, obj);
                Xaction.AddToCache(writeCache, obj);
            }
        }
Пример #6
0
 /// <summary>
 /// The authenticated token is extracted from TLS(Thread Local Storage)
 /// from the named data slot 'AuthenticatedToken'.
 /// </summary>
 /// <returns>The <see cref="AuthenticatedToken"/> corresponding to the identity that has been
 /// authenticated.</returns>
 private static AuthenticatedToken GetTokenFromThreadLocalStorage()
 {
     try
     {
         LocalDataStoreSlot slot = Thread.GetNamedDataSlot("AuthenticatedToken");
         return(Thread.GetData(slot) as AuthenticatedToken);
     }
     catch
     {
         throw new AuthorizationException(Zentity.Security.Authorization.Properties.Resources.TokenUnavailableInTLS);
     }
 }
Пример #7
0
 /// <summary>
 /// Gets the client context.
 /// </summary>
 /// <returns></returns>
 public ContextDictionary GetClientContext()
 {
     if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client)
     {
         return((ContextDictionary)AppDomain.CurrentDomain.GetData(_clientContextName));
     }
     else
     {
         LocalDataStoreSlot slot = Thread.GetNamedDataSlot(_clientContextName);
         return((ContextDictionary)Thread.GetData(slot));
     }
 }
        private bool GetThreadDataValueAsBool(string propertyName)
        {
            LocalDataStoreSlot slot     = Thread.GetNamedDataSlot(propertyName);
            object             dataSlot = Thread.GetData(slot);

            if (dataSlot != null)
            {
                return((bool)dataSlot);
            }

            return(false);
        }
        private string GetThreadDataValue(string propertyName)
        {
            LocalDataStoreSlot slot     = Thread.GetNamedDataSlot(propertyName);
            object             dataSlot = Thread.GetData(slot);

            if (dataSlot != null)
            {
                return(dataSlot.ToString());
            }

            return(string.Empty);
        }
Пример #10
0
 private static void SetClientContext(HybridDictionary clientContext)
 {
     if (HttpContext.Current == null)
     {
         LocalDataStoreSlot slot = Thread.GetNamedDataSlot("Dothan.ClientContext");
         Thread.SetData(slot, clientContext);
     }
     else
     {
         HttpContext.Current.Items["Dothan.ClientContext"] = clientContext;
     }
 }
Пример #11
0
 internal static HybridDictionary GetClientContext()
 {
     if (HttpContext.Current == null)
     {
         LocalDataStoreSlot slot = Thread.GetNamedDataSlot("Dothan.ClientContext");
         return((HybridDictionary)Thread.GetData(slot));
     }
     else
     {
         return((HybridDictionary)HttpContext.Current.Items["Dothan.ClientContext"]);
     }
 }
Пример #12
0
 /// <summary>
 /// Sets the client context.
 /// </summary>
 /// <param name="clientContext">Client context.</param>
 public void SetClientContext(ContextDictionary clientContext)
 {
     if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client)
     {
         AppDomain.CurrentDomain.SetData(_clientContextName, clientContext);
     }
     else
     {
         LocalDataStoreSlot slot = Thread.GetNamedDataSlot(_clientContextName);
         Thread.SetData(slot, clientContext);
     }
 }
Пример #13
0
        static void Main(string[] args)
        {
            Factory.CreateObject();
            UserSession us = new UserSession();

            us.UserID             = SS.DB.Query.ParameterServices.ImportSystemUserID;
            us.CurrentProgramCode = "ImageFileIO";
            LocalDataStoreSlot slot = System.Threading.Thread.AllocateNamedDataSlot(SessionEnum.WebSession.UserProfiles.ToString());

            System.Threading.Thread.SetData(slot, us);

            imagePostService   = Factory.DbDocumentImagePostingService;
            avDocumentService  = Factory.AvAdvanceDocumentService;
            expDocumentService = Factory.FnExpenseDocumentService;
            avDocumentQuery    = Factory.AvAdvanceDocumentQuery;
            expDocumentQuery   = Factory.FnExpenseDocumentQuery;
            docQuery           = Factory.SCGDocumentQuery;
            imgLogService      = Factory.SuImageToSAPLogService;
            parameterQuery     = Factory.DbParameterQuery;
            imgPostingQuery    = Factory.DbDocumentImagePostingQuery;
            fnRemittanceQuery  = Factory.FnRemittanceQuery;
            docService         = Factory.SCGDocumentService;

            Console.WriteLine("Program Export Document Image is running.");
            Factory.CreateObject();
            if (args.Length == 0)
            {
                args = new string[1];
                Console.WriteLine("Insert \"I\" or \"O\" to import / export mode");
                args[0] = Console.ReadLine();
            }


            if (args[0].ToLower() == "i")
            {
                Console.WriteLine("Import Start.");
                ImportPath = args[1];

                ReadExportImageLogfile();
            }
            if (args[0].ToLower() == "o")
            {
                Console.WriteLine("Export Start.");
                RootPath        = args[1];
                ExportImagePath = args[2];
                ExportDocumentImage();
            }



            Console.WriteLine("Program finish.");
        }
Пример #14
0
        public TestBase(string strName, int nDeviceID = DEFAULT_DEVICE_ID, EngineParameter.Engine engine = EngineParameter.Engine.DEFAULT, object tag = null, bool bHalf = false)
        {
            m_bHalf = bHalf;

            // If an auto test has set the GPUID, us it instead.
            LocalDataStoreSlot lds = Thread.GetNamedDataSlot("GPUID");

            if (lds != null)
            {
                object obj = Thread.GetData(lds);
                if (obj != null)
                {
                    string strGpuId = obj.ToString();
                    if (!string.IsNullOrEmpty(strGpuId))
                    {
                        int nVal;

                        if (int.TryParse(strGpuId, out nVal) && nDeviceID < 4)
                        {
                            nDeviceID = nVal;
                        }
                    }
                }
            }

            m_strName = strName;

            if (create_count == 1)
            {
                m_rgTests.Add(create(DataType.FLOAT, strName, nDeviceID, engine));
                m_rgTests.Add(create(DataType.DOUBLE, strName, nDeviceID, engine));
            }
            else
            {
                for (int i = 0; i < create_count; i++)
                {
                    ITest iTestF = create(i, DataType.FLOAT, strName, nDeviceID, engine);

                    if (iTestF != null)
                    {
                        m_rgTests.Add(iTestF);
                    }

                    ITest iTestD = create(i, DataType.DOUBLE, strName, nDeviceID, engine);

                    if (iTestD != null)
                    {
                        m_rgTests.Add(iTestD);
                    }
                }
            }
        }
Пример #15
0
        // Token: 0x060006DA RID: 1754 RVA: 0x0001AECC File Offset: 0x000190CC
        public static TStream GetCurrent <TStream>() where TStream : BufferStream, new()
        {
            LocalDataStoreSlot namedDataSlot = Thread.GetNamedDataSlot("ThreadBufferListStream");
            TStream            tstream       = Thread.GetData(namedDataSlot) as TStream;

            if (tstream != null)
            {
                return(tstream);
            }
            tstream = Activator.CreateInstance <TStream>();
            Thread.SetData(namedDataSlot, tstream);
            return(tstream);
        }
Пример #16
0
        public void Error(Exception e)
        {
            LocalDataStoreSlot sessionIDSlot = Thread.GetNamedDataSlot("sessionID");

            var logger   = LogManager.GetLogger("error");
            var logEvent = new LogEventInfo();

            logEvent.Level      = LogLevel.Error;
            logEvent.LoggerName = "error";
            logEvent.Message    = e.ToString();
            logEvent.Properties["SessionID"] = Thread.GetData(sessionIDSlot);
            logger.Log(logEvent);
        }
Пример #17
0
        public static object GetData(LocalDataStoreSlot slot)
        {
            Context ctx = Thread.CurrentContext;

            lock (ctx)
            {
                if (ctx.datastore != null && slot.slot < ctx.datastore.Length)
                {
                    return(ctx.datastore [slot.slot]);
                }
                return(null);
            }
        }
Пример #18
0
        /// <summary>Allocates a named data slot.</summary>
        /// <returns>A local data slot object.</returns>
        /// <param name="name">The required name for the data slot. </param>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="Infrastructure" />
        /// </PermissionSet>
        public static LocalDataStoreSlot AllocateNamedDataSlot(string name)
        {
            object             syncRoot = Context.namedSlots.SyncRoot;
            LocalDataStoreSlot result;

            lock (syncRoot)
            {
                LocalDataStoreSlot localDataStoreSlot = Context.AllocateDataSlot();
                Context.namedSlots.Add(name, localDataStoreSlot);
                result = localDataStoreSlot;
            }
            return(result);
        }
Пример #19
0
        void CheckOtherContextDatastore()
        {
            LocalDataStoreSlot namedSlot1 = Context.GetNamedDataSlot("slot1");
            LocalDataStoreSlot namedSlot2 = Context.GetNamedDataSlot("slot2");

            Assert.IsTrue(Context.GetData(slot) == null, "Slot already has data");
            Assert.IsTrue(Context.GetData(namedSlot1) == null, "Slot already has data");
            Assert.IsTrue(Context.GetData(namedSlot2) == null, "Slot already has data");

            Context.SetData(slot, "other data");
            Context.SetData(namedSlot1, "other data1");
            Context.SetData(namedSlot2, "other data2");
        }
Пример #20
0
        /// <summary>
        /// 激活会话
        /// </summary>
        /// <param name="sessionId">The session id.</param>
        public void Activate(string sessionId)
        {
            if (!sessions.ContainsKey(sessionId))
            {
                logger.Debug(String.Format("不存在 [{0}] 的会话, 该会话可能已经超时无法激活此会话.", sessionId));
                return;
            }

            LocalDataStoreSlot slot = Thread.GetNamedDataSlot(SESSION_SOLOTNAME);

            Thread.SetData(slot, sessionId);
            sessions[sessionId].Activate();
        }
Пример #21
0
 public static object GetData(LocalDataStoreSlot slot)
 {
     object[] slots = local_slots;
     if (slot == null)
     {
         throw new ArgumentNullException("slot");
     }
     if (slots != null && slot.slot < slots.Length)
     {
         return(slots [slot.slot]);
     }
     return(null);
 }
Пример #22
0
        // GET: Producto
        public ActionResult Index()
        {
            local = Thread.GetNamedDataSlot("tenant");
            string valor_Tenant = System.Threading.Thread.GetData(local).ToString();

            var user = Session["usuario"] as UsuarioSite;

            var lista_Productos = _blproducto.ObtenerProductos();

            ViewBag.ListaCategorias = lista_Productos;

            return(View());
        }
Пример #23
0
 public static IUnitOfWork UnitOfWork()
 {
     lock (unitOfWorkGetLock)
     {
         LocalDataStoreSlot lds = System.Threading.Thread.GetNamedDataSlot("" + System.Threading.Thread.CurrentThread.ManagedThreadId);
         var unitOfWork         = (IUnitOfWork)System.Threading.Thread.GetData(lds);
         if (unitOfWork == null)
         {
             throw new Exception("A unit of work has not been started for the current thread.");
         }
         return(unitOfWork);
     }
 }
Пример #24
0
 public static Guid GetTenant()
 {
     lock (tenantGetLock)
     {
         LocalDataStoreSlot lds = System.Threading.Thread.GetNamedDataSlot("Tenant" + System.Threading.Thread.CurrentThread.ManagedThreadId);
         var tenantGuid         = (Guid)System.Threading.Thread.GetData(lds);
         if (tenantGuid == null)
         {
             throw new Exception("A tenant has not been set for the current thread.");
         }
         return(tenantGuid);
     }
 }
Пример #25
0
        public static TStream GetCurrent <TStream>() where TStream : BufferStream, new()
        {
            LocalDataStoreSlot namedDataSlot = Thread.GetNamedDataSlot("ThreadBufferListStream");
            TStream            val           = Thread.GetData(namedDataSlot) as TStream;

            if (val != null)
            {
                return(val);
            }
            val = new TStream();
            Thread.SetData(namedDataSlot, val);
            return(val);
        }
Пример #26
0
        public void invoke(object obj)
        {
            m_taskStatus = Task.Factory.StartNew(new Action(status));
            Tuple <object, int> arg = obj as Tuple <object, int>;
            object instance         = arg.Item1;
            int    nGpuId           = arg.Item2;

            try
            {
                LocalDataStoreSlot lds = Thread.GetNamedDataSlot("GPUID");
                if (lds == null)
                {
                    lds = Thread.AllocateNamedDataSlot("GPUID");
                }

                if (lds != null)
                {
                    Thread.SetData(lds, nGpuId.ToString());
                }

                m_swTiming.Reset();
                m_swTiming.Start();
                m_status = STATUS.Running;
                m_mi.Invoke(instance, null);
                m_status = STATUS.Passed;
            }
            catch (Exception excpt)
            {
                if (excpt.Message == "Aborted!" || (excpt.InnerException != null && excpt.InnerException.Message == "Aborted!"))
                {
                    m_status = STATUS.Aborted;
                }
                else
                {
                    m_status = STATUS.Failed;
                    m_errorInfo.SetError(excpt);
                }
            }
            finally
            {
                m_swTiming.Stop();

                if (m_miDispose != null)
                {
                    m_miDispose.Invoke(instance, null);
                }

                m_evtStatusCancel.Set();
                Thread.FreeNamedDataSlot("GPUID");
            }
        }
Пример #27
0
        /// <summary>
        /// Gets the data for a slot in thread-local storage.
        /// </summary>
        /// <typeparam name="T">Type of the data.</typeparam>
        /// <param name="slot">The slot to get data for.</param>
        /// <param name="create">Automatically create the object if it doesn't exist.</param>
        /// <returns>
        /// Slot data (will create T if null).
        /// </returns>
        public static T GetDataForSlot <T>(object slot, bool create = true)
            where T : class, new()
        {
#if TLS_WORKAROUND
            IDictionary <int, object> dict = GetThreadDataDictionary(Thread.CurrentThread);
            int    slotNumber = (int)slot;
            object v;
            if (!dict.TryGetValue(slotNumber, out v))
            {
                if (!create)
                {
                    return(null);
                }

                v = new T();
                dict.Add(slotNumber, v);
            }
            return((T)v);
#elif NETSTANDARD || NET4_6
            var thread = slot as ThreadLocal <object>;
            if (thread == null)
            {
                throw new InvalidOperationException($"Expected ThreadLocal object. Received {slot?.GetType()}.");
            }
            if (!thread.IsValueCreated)
            {
                if (!create)
                {
                    return(null);
                }

                thread.Value = new T();
            }
            return((T)thread.Value);
#else
            LocalDataStoreSlot localDataStoreSlot = (LocalDataStoreSlot)slot;
            object             v = Thread.GetData(localDataStoreSlot);
            if (v == null)
            {
                if (!create)
                {
                    return(null);
                }

                v = new T();
                Thread.SetData(localDataStoreSlot, v);
            }

            return((T)v);
#endif
        }
        public static object GetData(LocalDataStoreSlot slot)
        {
            if (_ctypeThreadType == null)
            {
                return(null);
            }

            if (_delGetData == null)
            {
                _delGetData = CDelegateEx.CreateDelegate <DelGetData> (_ctypeThread, "GetData");
            }

            return(_delGetData(slot));
        }
Пример #29
0
        /// <summary>
        /// Get an instance of T for current thread
        /// </summary>
        /// <param name="appendedkey"></param>
        /// <param name="onCreateInstance"></param>
        /// <returns></returns>
        public static T GetThreadInstance(string appendedkey, CreateInstanceHandler <T> onCreateInstance)
        {
            LocalDataStoreSlot          slot      = Thread.GetNamedDataSlot("__ThreadInstanceTable");
            Dictionary <string, object> instances = Thread.GetData(slot) as Dictionary <string, object>;

            if (instances == null)
            {
                lock (LockKey)
                {
                    instances = Thread.GetData(slot) as Dictionary <string, object>;
                    if (instances == null)
                    {
                        instances = new Dictionary <string, object>();
                        Thread.SetData(slot, instances);
                    }
                }
            }

            string key = string.Format("{0}:{1}", typeof(T).AssemblyQualifiedName, appendedkey);
            object obj;

            if (instances.TryGetValue(key, out obj))
            {
                return((T)obj);
            }
            else
            {
                lock (LockKey)
                {
                    if (instances.TryGetValue(key, out obj))
                    {
                        return((T)obj);
                    }
                    else
                    {
                        T t;
                        try
                        {
                            t = (onCreateInstance == null ? Activator.CreateInstance <T>() : onCreateInstance());
                        }
                        catch
                        {
                            t = default(T);
                        }
                        instances[key] = t;
                        return(t);
                    }
                }
            }
        }
Пример #30
0
        /// <summary>
        /// Release the instance of T for current thread
        /// </summary>
        public static void ReleaseThreadInstance()
        {
            LocalDataStoreSlot slot = Thread.GetNamedDataSlot("__ThreadInstanceTable");

            lock (LockKey)
            {
                Dictionary <int, object> instances = Thread.GetData(slot) as Dictionary <int, object>;
                if (instances != null)
                {
                    int threadId = Thread.CurrentThread.ManagedThreadId;
                    instances.Remove(threadId);
                }
            }
        }
        public static void SetData(LocalDataStoreSlot slot, object data)
        {
            if (_ctypeThreadType == null)
            {
                return;
            }

            if (_delSetData == null)
            {
                _delSetData = CDelegateEx.CreateDelegate <DelSetData> (_ctypeThread, "SetData");
            }

            _delSetData(slot, data);
        }
Пример #32
0
		public LocalDataStoreSlot Get (string name)
		{
			lock (this) {
				if (datastorehash == null)
					datastorehash = new Dictionary<string, LocalDataStoreSlot> ();

				LocalDataStoreSlot slot;
				if (!datastorehash.TryGetValue (name, out slot)) {
					slot = new LocalDataStoreSlot (true);
				}
			
				return slot;
			}
		}		
Пример #33
0
	public static int Main () {
		Console.WriteLine ("Hello, World!");
		slot=Thread.AllocateDataSlot();
		LocalDataStoreSlot namedslot=Thread.AllocateNamedDataSlot("data-slot");

		Test test = new Test();
		Thread thr=new Thread(new ThreadStart(test.Thread_func));
		thr.Start();
		Thread.Sleep(1000);
		Thread main=Thread.CurrentThread;
		main.Name="wibble";
		Thread othermain=Thread.CurrentThread;
		Console.WriteLine("Other name " + othermain.Name);
		Thread.Sleep(0);
		
		Console.WriteLine("In the main line!");

		Console.WriteLine("Trying to enter lock");
		if(Monitor.TryEnter(thr, 100)==true) {
			Console.WriteLine("Returned lock");
			Monitor.Exit(thr);
		} else {
			Console.WriteLine("Didn't get lock");
		}

		Thread.SetData(slot, main);
		Thread storedthr=(Thread)Thread.GetData(slot);
		Console.WriteLine("Stored subthread is " + storedthr.Name);

		Thread.SetData(namedslot, main);
		storedthr=(Thread)Thread.GetData(namedslot);
		Console.WriteLine("Stored subthread is " + storedthr.Name);
		
		if(thr.Join(5000)) {
			Console.WriteLine("Joined thread");
		} else {
			Console.WriteLine("Didn't join thread");
		}
		
		lock(thr) {
			Monitor.Pulse(thr);
			Console.WriteLine("Signalled thread");
		}
		
		thr.Join();
		
		return 0;
	}
Пример #34
0
		public LocalDataStoreSlot Allocate (string name)
		{		
			lock (this) {
				if (datastorehash == null)
					datastorehash = new Dictionary<string, LocalDataStoreSlot> ();

				if (datastorehash.ContainsKey (name)) {
					// This exception isnt documented (of
					// course) but .net throws it
					throw new ArgumentException ("Named data slot already added");
				}
			
				var slot = new LocalDataStoreSlot (true);
				datastorehash.Add (name, slot);
				return slot;
			}
		}
	// Get a data store slot with a specific name.
	internal static LocalDataStoreSlot GetNamed(String name)
			{
				lock(typeof(LocalDataStoreSlot))
				{
					LocalDataStoreSlot slot = namedSlots;
					while(slot != null)
					{
						if(slot.isNamed && slot.name == name)
						{
							return slot;
						}
						slot = slot.nextNamed;
					}
					slot = new LocalDataStoreSlot(true, name);
					slot.nextNamed = namedSlots;
					namedSlots = slot;
					return slot;
				}
			}
Пример #36
0
	// Set the value of a local data store slot.
	public static void SetData(LocalDataStoreSlot slot, Object value)
			{
				Thread.SetData(slot, value);
			}
Пример #37
0
        private static BaseLoggingObject LoggingInitialize() {

#if DEBUG
            if (GetSwitchValue("SystemNetLogging", "System.Net logging module", false) &&
                GetSwitchValue("SystemNetLog_ConnectionMonitor", "System.Net connection monitor thread", false)) {
                InitConnectionMonitor();
            }
#endif // DEBUG
#if TRAVE
            // by default we'll log to c:\temp\ so that non interactive services (like w3wp.exe) that don't have environment
            // variables can easily be debugged, note that the ACLs of the directory might need to be adjusted
            if (!GetSwitchValue("SystemNetLog_OverrideDefaults", "System.Net log override default settings", false)) {
                s_ThreadIdSlot = Thread.AllocateDataSlot();
                s_UseThreadId = true;
                s_UseTimeSpan = true;
                s_DumpWebData = true;
                s_MaxDumpSize = 256;
                s_UsePerfCounter = true;
                s_DebugCallNesting = true;
                s_DumpToConsole = false;
                s_RootDirectory = "C:\\Temp\\";
                return new LoggingObject();
            }
            if (GetSwitchValue("SystemNetLogging", "System.Net logging module", false)) {
                s_ThreadIdSlot = Thread.AllocateDataSlot();
                s_UseThreadId = GetSwitchValue("SystemNetLog_UseThreadId", "System.Net log display system thread id", false);
                s_UseTimeSpan = GetSwitchValue("SystemNetLog_UseTimeSpan", "System.Net log display ticks as TimeSpan", false);
                s_DumpWebData = GetSwitchValue("SystemNetLog_DumpWebData", "System.Net log display HTTP send/receive data", false);
                s_MaxDumpSize = GetSwitchValue("SystemNetLog_MaxDumpSize", "System.Net log max size of display data", 256);
                s_UsePerfCounter = GetSwitchValue("SystemNetLog_UsePerfCounter", "System.Net log use QueryPerformanceCounter() to get ticks ", false);
                s_DebugCallNesting = GetSwitchValue("SystemNetLog_DebugCallNesting", "System.Net used to debug call nesting", false);
                s_DumpToConsole = GetSwitchValue("SystemNetLog_DumpToConsole", "System.Net log to console", false);
                s_RootDirectory = GetSwitchValue("SystemNetLog_RootDirectory", "System.Net root directory of log file", string.Empty);
                return new LoggingObject();
            }
#endif // TRAVE
            return new BaseLoggingObject();
        }
Пример #38
0
		public static object GetData (LocalDataStoreSlot slot)
		{
			Context ctx = Thread.CurrentContext;
			
			lock (ctx)
			{
				if (ctx.datastore != null && slot.slot < ctx.datastore.Length)
					return ctx.datastore [slot.slot];
				return null;
			}
		}
Пример #39
0
		public static void SetData (LocalDataStoreSlot slot, object data)
		{
			Context ctx = Thread.CurrentContext;
			lock (ctx)
			{
				if (ctx.datastore == null) {
					ctx.datastore = new object [slot.slot + 2];
				} else if (slot.slot >= ctx.datastore.Length) {
					object[] nslots = new object [slot.slot + 2];
					ctx.datastore.CopyTo (nslots, 0);
					ctx.datastore = nslots;
				}
				ctx.datastore [slot.slot] = data;
			}
		}
Пример #40
0
		public static object GetData (LocalDataStoreSlot slot)
		{
			return Thread.CurrentContext.MyLocalStore.GetData (slot);
		}
Пример #41
0
	// Get the data stored in a particular data store slot.
	public static Object GetData(LocalDataStoreSlot slot)
			{
				return Thread.GetData(slot);
			}
Пример #42
0
	// Set the data in a particular local data store slot.
	public static void SetData(LocalDataStoreSlot slot, Object data)
			{
				if(slot != null)
				{
					slot.Data = data;
				}
			}
Пример #43
0
        private static void VerifyLocalDataSlot(LocalDataStoreSlot slot)
        {
            Assert.NotNull(slot);

            var waitForThreadArray = new Action[2];
            var threadArray = new Thread[2];
            var barrier = new Barrier(threadArray.Length);
            var cancellationTokenSource = new CancellationTokenSource();
            var cancellationToken = cancellationTokenSource.Token;

            Func<bool> barrierSignalAndWait =
                () =>
                {
                    try
                    {
                        Assert.True(barrier.SignalAndWait(UnexpectedTimeoutMilliseconds, cancellationToken));
                    }
                    catch (OperationCanceledException)
                    {
                        return false;
                    }
                    return true;
                };

            Action<int> threadMain =
                threadIndex =>
                {
                    try
                    {
                        Assert.Null(Thread.GetData(slot));
                        if (!barrierSignalAndWait())
                        {
                            return;
                        }

                        if (threadIndex == 0)
                        {
                            Thread.SetData(slot, threadIndex);
                        }
                        if (!barrierSignalAndWait())
                        {
                            return;
                        }

                        if (threadIndex == 0)
                        {
                            Assert.Equal(threadIndex, Thread.GetData(slot));
                        }
                        else
                        {
                            Assert.Null(Thread.GetData(slot));
                        }
                        if (!barrierSignalAndWait())
                        {
                            return;
                        }

                        if (threadIndex != 0)
                        {
                            Thread.SetData(slot, threadIndex);
                        }
                        if (!barrierSignalAndWait())
                        {
                            return;
                        }

                        Assert.Equal(threadIndex, Thread.GetData(slot));
                        if (!barrierSignalAndWait())
                        {
                            return;
                        }
                    }
                    catch (Exception ex)
                    {
                        cancellationTokenSource.Cancel();
                        throw new TargetInvocationException(ex);
                    }
                };

            for (int i = 0; i < threadArray.Length; ++i)
            {
                threadArray[i] = ThreadTestHelpers.CreateGuardedThread(out waitForThreadArray[i], () => threadMain(i));
                threadArray[i].IsBackground = true;
                threadArray[i].Start();
            }

            foreach (var waitForThread in waitForThreadArray)
            {
                waitForThread();
            }
        }
Пример #44
0
 public static object GetData(LocalDataStoreSlot slot)
 {
     return GetThreadLocal(slot).Value;
 }
Пример #45
0
 public static void SetData(LocalDataStoreSlot slot, object value)
 {
     GetThreadLocal(slot).Value = value;
 }
Пример #46
0
            private static ThreadLocal<object> GetThreadLocal(LocalDataStoreSlot slot)
            {
                if (slot == null)
                {
                    throw new ArgumentNullException(nameof(slot));
                }

                Debug.Assert(slot.Data != null);
                return slot.Data;
            }
Пример #47
0
 public static void SetData(LocalDataStoreSlot slot, object data) => LocalDataStore.SetData(slot, data);
Пример #48
0
 public static object GetData(LocalDataStoreSlot slot) => LocalDataStore.GetData(slot);
Пример #49
0
		public static object GetData (LocalDataStoreSlot slot) {
			object[] slots = local_slots;
			if (slot == null)
				throw new ArgumentNullException ("slot");
			if (slots != null && slot.slot < slots.Length)
				return slots [slot.slot];
			return null;
		}
Пример #50
0
	// Get the data in a particular data store slot.
	public static Object GetData(LocalDataStoreSlot slot)
			{
				if(slot == null)
				{
					return null;
				}
				else
				{
					return slot.Data;
				}
			}
Пример #51
0
		public static void SetData (LocalDataStoreSlot slot, object data) {
			object[] slots = local_slots;
			if (slot == null)
				throw new ArgumentNullException ("slot");
			if (slots == null) {
				slots = new object [slot.slot + 2];
				local_slots = slots;
			} else if (slot.slot >= slots.Length) {
				object[] nslots = new object [slot.slot + 2];
				slots.CopyTo (nslots, 0);
				slots = nslots;
				local_slots = slots;
			}
			slots [slot.slot] = data;
		}
Пример #52
0
static Slot()
{
rnd = new Random();
slt = Thread.AllocateDataSlot();
}
Пример #53
0
		public static void SetData (LocalDataStoreSlot slot, object data)
		{
			Thread.CurrentContext.MyLocalStore.SetData (slot, data);
		}
	// Free a data store slot with a specific name.
	internal static void FreeNamed(String name)
			{
				lock(typeof(LocalDataStoreSlot))
				{
					LocalDataStoreSlot slot = namedSlots;
					LocalDataStoreSlot prev = null;
					while(slot != null)
					{
						if(slot.isNamed && slot.name == name)
						{
							if(prev != null)
							{
								prev.nextNamed = slot.nextNamed;
							}
							else
							{
								namedSlots = slot.nextNamed;
							}
							slot.free = true;
							return;
						}
						prev = slot;
						slot = slot.nextNamed;
					}
				}
			}