public void ItShouldBePossibleToExchangeObjects() { var ob1 = new object(); var ob2 = new object(); var lfi = new LockFreeItem <object>(ob1); Assert.AreSame(ob1, lfi.Data); lfi.Data = ob2; Assert.AreSame(ob2, lfi.Data); lfi.Dispose(); }
public SocketRecycling(int maxSocket) { if (maxSocket > 0) { isEnabled = true; array = new LockFreeItem<Socket>[maxSocket]; empty = new LockFreeStack<Socket>(array, 0, maxSocket); full4 = new LockFreeStack<Socket>(array, -1, -1); full6 = new LockFreeStack<Socket>(array, -1, -1); } }
public AsyncLockFreeDictionary(IDictionary <TKey, TValue> dictionary, ITimer timer = null) { MaxMessagesPerCycle = new ConcurrentInt64(100); _opverlappingChecker = new ConcurrentInt64(); _timer = timer ?? new SystemTimer(10, 10); _dictionary = new LockFreeItem <Dictionary <TKey, TValue> >(new Dictionary <TKey, TValue>(dictionary)) { Data = new Dictionary <TKey, TValue>() }; _trustedSource = new Dictionary <TKey, TValue>(); _requestsQueue = new LockFreeQueue <AsyncCollectionRequest <KeyValuePair <TKey, TValue> > >(); _timer.Elapsed += OnSynchronize; _timer.Start(); }
public SmartBufferPool(int maxMemoryUsageMb, int initialSizeMb, int extraBufferSizeMb) { InitialMemoryUsage = initialSizeMb * Mb; ExtraMemoryUsage = extraBufferSizeMb * Mb; MaxBuffersCount = (maxMemoryUsageMb * Mb - InitialMemoryUsage) / ExtraMemoryUsage; MaxMemoryUsage = InitialMemoryUsage + ExtraMemoryUsage * MaxBuffersCount; array = new LockFreeItem<long>[MaxMemoryUsage / MinSize]; empty = new LockFreeStack<long>(array, 0, array.Length); int count = 0; while (MaxSize >> count >= MinSize) count++; ready = new LockFreeStack<long>[count]; for (int i = 0; i < ready.Length; i++) ready[i] = new LockFreeStack<long>(array, -1, -1); buffers = new byte[MaxBuffersCount][]; buffers[0] = NewBuffer(InitialMemoryUsage); }
/*public static void AddRunCountMonitor(string id) * { * _perfData.TryAdd(id.ToLowerInvariant(), new BaseMetric(true, false, _periodRun)); * } * * public static void AddDurationMonitor(string id) * { * _perfData.TryAdd(id.ToLowerInvariant(), new BaseMetric(false, true, _periodRun)); * } * * public static void AddMonitor(string id) * { * _perfData.TryAdd(id.ToLowerInvariant(), new BaseMetric(true, true, _periodRun)); * } * * public static void AddStatusMonitor(string id, object baseStatus) * { * _perfData.TryAdd(id.ToLowerInvariant(), new BaseMetric(false, false, _periodRun, baseStatus)); * }*/ static PerfMon() { _accessibleData = new LockFreeItem <ReadOnlyCollection <BaseMetric> >(new ReadOnlyCollection <BaseMetric>(new List <BaseMetric>())); _perfData = new AsyncLockFreeDictionary <string, BaseMetric>(); _stopWatch = new Stopwatch(); }
static void Main(string[] args) { Console.Write(@"Test Lock-free "); if (testObject == TestObject.Pool) { Console.WriteLine("Pool"); testPool = true; } else if (testObject == TestObject.FastPool) { Console.WriteLine("Fast Pool"); testPool = true; } else if (testObject == TestObject.StackQueue) { Console.WriteLine("Stack & Queue (Not Pool)"); testPool = false; } else throw new NotImplementedException(); Console.WriteLine(@"ThreadPool Test Starting..."); Console.WriteLine(@" All threads: {0}", threads); Console.WriteLine(@" Buffers per thread: {0}", actions); Console.WriteLine(@" Buffer pool size: {0}", poolSize); Console.WriteLine(); if (testPool) { if (testObject == TestObject.Pool) pool = new LockFreePool<Item>(poolSize); if (testObject == TestObject.FastPool) pool = new LockFreeFastPool<Item>(poolSize); } else { array = new LockFreeItem<Item>[poolSize + 1]; for (int i = 1; i < array.Length; i++) array[i].Value = new Item(); queue = new LockFreeQueue<Item>(array, 0, poolSize + 1); stack = new LockFreeStack<Item>(array, -1, -1); } items = new bool[65536]; run = true; for (int i = 0; i < threads; i++) { var thread = new Thread(TestBufferPool); thread.Start(); } Console.WriteLine(@"Started. Press any key to stop..."); Console.ReadKey(true); run = false; while (count > 0) Thread.Sleep(25); }
public ObjectVariable(object baseStatus, BaseMetric container) { _container = container; _internalData = new LockFreeItem <object>(baseStatus); }