Esempio n. 1
0
 private void Return(WinTunOwnedMemory ownedMemory)
 {
     lock (_pool)
     {
         _pool.Enqueue(ownedMemory);
         _emptyEvent.Set();
     }
 }
Esempio n. 2
0
        public unsafe WinTunMemoryPool(int poolSize, int bufferSize)
        {
            var totalMemory = poolSize * bufferSize;
            var memory      = Marshal.AllocHGlobal(totalMemory);

            for (var i = 0; i < totalMemory; i += bufferSize)
            {
                var mem = new WinTunOwnedMemory(this, memory, i, bufferSize);
                _pool.Enqueue(mem);
            }
        }
Esempio n. 3
0
 public bool TryGetMemory(out WinTunOwnedMemory memory)
 {
     lock (_pool)
     {
         var result = _pool.TryDequeue(out memory);
         if (!result)
         {
             _emptyEvent.Reset();
         }
         return(result);
     }
 }