private unsafe int load() { if (versionNode == (IntPtr)0) { throw new InvalidOperationException("Trying to dereference a null versionNode here!"); } AtomicSafetyHandleInternal *hInternal = (AtomicSafetyHandleInternal *)versionNode; if (hInternal == null) { throw new System.InvalidOperationException("The NativeArray has been deallocated, it is not allowed to access it"); } return(IsSecondaryVersion()? hInternal->version2 : hInternal->version1); }
public static void Release(AtomicSafetyHandle handle) { unsafe { AtomicSafetyHandleInternal *hInternal = handle.GetInternal(); if (hInternal != null) { #if DEBUG_DUMMY UnityEngine.Debug.Log($"xxx Release({handle}"); #endif release(hInternal); hInternal->version1 &= ~AtomicSafetyHandleVersionMask.ReadWriteAndDispose; handle.BumpPrimaryVersion(); hInternal->version2 &= ~AtomicSafetyHandleVersionMask.ReadWriteAndDispose; handle.BumpSecondaryVersion(); hInternal->permissions = 0; } } }
public static AtomicSafetyHandle Create() { unsafe { AtomicSafetyHandleInternal *node = alloc(); AtomicSafetyHandle handle = new AtomicSafetyHandle() { versionNode = (IntPtr)node, }; //node->version1 = node->version2 = node->permissions = 0; handle.version = node->version1; UnityEngine.Assertions.Assert.IsFalse(handle.IsSecondaryVersion()); UnityEngine.Assertions.Assert.IsTrue((handle.version & AtomicSafetyHandleVersionMask.ReadWriteAndDispose) == 0); UnityEngine.Assertions.Assert.IsTrue((node->version1 & AtomicSafetyHandleVersionMask.ReadWriteAndDispose) == 0); UnityEngine.Assertions.Assert.IsTrue((node->version2 & AtomicSafetyHandleVersionMask.ReadWriteAndDispose) == 0); #if DEBUG_DUMMY UnityEngine.Debug.Log($"xxx Create() = {handle}"); #endif return(handle); } }
internal AtomicSafetyHandleInternal *alloc() { if (m_nextAvail != null) { AtomicSafetyHandleInternal *r = &m_nextAvail->handle; m_nextAvail = m_nextAvail->nextAvail; return(r); } AtomicSafetyHandleNode *h = m_headChunk->m_curChunk; if ((IntPtr)h == (IntPtr)m_headChunk->GetHeader()) { addChunk(); h = m_headChunk->m_curChunk; } m_headChunk->m_curChunk = (AtomicSafetyHandleNode *)((ulong)m_headChunk->m_curChunk + esz); h->handle.version1 = h->handle.version2 = h->handle.permissions = 0; return(&h->handle); }
public static void SetAllowSecondaryVersionWriting(AtomicSafetyHandle handle, bool allowWriting) { #if DEBUG_DUMMY UnityEngine.Debug.Log($"xxx SetAllowSecondaryVersionWriting({handle}, {allowWriting})"); #endif unsafe { AtomicSafetyHandleInternal *hInternal = handle.GetInternalWithCheck(); hInternal->version2 |= AtomicSafetyHandleVersionMask.Write; if (allowWriting) { hInternal->permissions |= SecondaryWritingEnabled; } else { hInternal->permissions &= ~SecondaryWritingEnabled; } #if DEBUG_DUMMY UnityEngine.Debug.Log($"xxx SetAllowSecondaryVersionWriting() = {handle}"); #endif } }
static unsafe void release(AtomicSafetyHandleInternal *handle) { pool.release(handle); }
internal void release(AtomicSafetyHandleInternal *handle) { ((AtomicSafetyHandleNode *)handle)->nextAvail = m_nextAvail; m_nextAvail = (AtomicSafetyHandleNode *)handle; }