private void Return(WinTunOwnedMemory ownedMemory) { lock (_pool) { _pool.Enqueue(ownedMemory); _emptyEvent.Set(); } }
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); } }
public bool TryGetMemory(out WinTunOwnedMemory memory) { lock (_pool) { var result = _pool.TryDequeue(out memory); if (!result) { _emptyEvent.Reset(); } return(result); } }