RSExport RSProcessInfoRef RSProcessInfoGetDefault() { RSSpinLockLock(&__RSProcessInfoLock); if (__RSProcessInfoGlobal) { RSSpinLockUnlock(&__RSProcessInfoLock); return __RSProcessInfoGlobal; } RSProcessInfoRef pi = __RSProcessInfoCreateInstance(RSAllocatorSystemDefault, nil); __RSProcessInfoGlobal = pi; __RSRuntimeSetInstanceSpecial(__RSProcessInfoGlobal, YES); RSSpinLockUnlock(&__RSProcessInfoLock); return __RSProcessInfoGlobal; }
RSExport RSArrayRef RSQueueCopyCoreQueueSafe(RSQueueRef queue) { if (!queue) return nil; __RSGenericValidInstance(queue, _RSQueueTypeID); if (isAtom(queue)) RSSpinLockLock(&queue->_lock); RSArrayRef results = RSCopy(RSAllocatorSystemDefault, queue->_queueCore); if (isAtom(queue)) RSSpinLockUnlock(&queue->_lock); return results; }
RSExport RSArrayRef RSQueueCopyCoreQueueUnsafe(RSQueueRef queue) { if (!queue) return nil; __RSGenericValidInstance(queue, _RSQueueTypeID); if (isAtom(queue)) RSSpinLockLock(&queue->_lock); RSArrayRef results = RSRetain(queue->_queueCore); if (isAtom(queue)) RSSpinLockUnlock(&queue->_lock); return results; }
RSInline void __RSQueueAddToObject(RSQueueRef queue, RSTypeRef obj) { BOOL shouldLocked = isAtom(queue); if (shouldLocked) RSSpinLockLock(&queue->_lock); if (queue->_capacity == 0) { RSArrayAddObject(queue->_queueCore, obj); if (shouldLocked) RSSpinLockUnlock(&queue->_lock); return; } RSIndex cnt = RSArrayGetCount(queue->_queueCore); if (cnt < queue->_capacity) RSArrayAddObject(queue->_queueCore, obj); else __RSCLog(RSLogLevelNotice, "RSQueue %p is full!\n", queue); if (shouldLocked) RSSpinLockUnlock(&queue->_lock); }
RSPrivate void __RSErrorDeallocate() { if (!__RSErrorCallBackTable) return; RSSpinLockLock(&__RSErrorCallBackTableSpinlock); RSRelease(__RSErrorCallBackTable); __RSErrorCallBackTable = nil; RSSpinLockUnlock(&__RSErrorCallBackTableSpinlock); }
RSExport RSErrorUserInfoKeyCallBack RSErrorGetCallBackForDomain(RSStringRef domainName) { if (!__RSErrorCallBackTable) __RSErrorInitUserInfoKeyCallBackTable(); RSSpinLockLock(&__RSErrorCallBackTableSpinlock); RSErrorUserInfoKeyCallBack cb = RSDictionaryGetValue(__RSErrorCallBackTable, domainName); RSSpinLockUnlock(&__RSErrorCallBackTableSpinlock); return cb; }
RSExport RSIndex RSQueueGetCount(RSQueueRef queue) { if (queue == nil) return 0; __RSGenericValidInstance(queue, _RSQueueTypeID); if (isAtom(queue)) RSSpinLockLock(&queue->_lock); RSIndex cnt = RSArrayGetCount(queue->_queueCore); if (isAtom(queue)) RSSpinLockUnlock(&queue->_lock); return cnt; }
RSInline RSTypeRef __RSQueueGetObjectFromQueue(RSQueueRef queue, BOOL remove) { BOOL shouldLocked = isAtom(queue); if (shouldLocked) RSSpinLockLock(&queue->_lock); RSIndex cnt = RSArrayGetCount(queue->_queueCore); if (cnt == 0) { if (shouldLocked) RSSpinLockUnlock(&queue->_lock); return nil; } RSTypeRef obj = RSArrayObjectAtIndex(queue->_queueCore, 0); if (remove) { RSRetain(obj); RSArrayRemoveObjectAtIndex(queue->_queueCore, 0); } if (shouldLocked) RSSpinLockUnlock(&queue->_lock); return obj; }
static void __RSErrorInitUserInfoKeyCallBackTable() { RSMutableDictionaryRef table = RSDictionaryCreateMutable(RSAllocatorSystemDefault, 0, RSDictionaryNilValueContext); RSSpinLockLock(&__RSErrorCallBackTableSpinlock); if (!__RSErrorCallBackTable) { __RSErrorCallBackTable = table; } else { RSSpinLockUnlock(&__RSErrorCallBackTableSpinlock); return; } RSSpinLockUnlock(&__RSErrorCallBackTableSpinlock); RSErrorSetCallBackForDomain(RSErrorDomainPOSIX, __RSErrorPOSIXCallBack); #if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED RSErrorSetCallBackForDomain(RSErrorDomainMach, __RSErrorMachCallBack); #endif RSErrorSetCallBackForDomain(RSErrorDomainRSCoreFoundation, __RSErrorRSCoreFoundationCallBack); }
static void __RSProcessInfoDeallocate(void) { RSSpinLockLock(&__RSProcessInfoLock); if (__RSProcessInfoGlobal) { __RSRuntimeSetInstanceSpecial(__RSProcessInfoGlobal, NO); RSRelease(__RSProcessInfoGlobal); __RSProcessInfoGlobal = nil; } RSSpinLockUnlock(&__RSProcessInfoLock); }
RSExport void RSErrorSetCallBackForDomain(RSStringRef domainName, RSErrorUserInfoKeyCallBack callBack) { if (!__RSErrorCallBackTable) __RSErrorInitUserInfoKeyCallBackTable(); RSSpinLockLock(&__RSErrorCallBackTableSpinlock); if (callBack) { RSDictionarySetValue(__RSErrorCallBackTable, domainName, (void *)callBack); } else { RSDictionaryRemoveValue(__RSErrorCallBackTable, domainName); } RSSpinLockUnlock(&__RSErrorCallBackTableSpinlock); }
static RSBitU64 __RSAllocatorUpdateUnit(RSBit8 operand) { RSBitU64 result = 0; RSSpinLockLock(&___RSAllocatorAllocateUnitNumberLock); switch (operand) { case 0: result = ___RSAllocatorAllocateUnitNumber; break; case 1: ___RSAllocatorAllocateUnitNumber++; #if __RSRuntimeDebugPreference if (___RSDebugLogPreference._RSRuntimeInstanceAllocFreeWatcher) { __RSCLog(RSLogLevelDebug, "runtime unit - %llu\n", ___RSAllocatorAllocateUnitNumber); } #endif result = YES; break; case -1: ___RSAllocatorAllocateUnitNumber--; #if __RSRuntimeDebugPreference if (___RSDebugLogPreference._RSRuntimeInstanceAllocFreeWatcher) { __RSCLog(RSLogLevelDebug, "runtime unit - %llu\n", ___RSAllocatorAllocateUnitNumber); } #endif result = YES; default: break; } if (___RSAllocatorAllocateUnitNumber == ~0) { HALTWithError(RSGenericException, "What the hell was that?! You malloc to much memory blocks!"); } RSSpinLockUnlock(&___RSAllocatorAllocateUnitNumberLock); return result; }