示例#1
0
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;
}
示例#2
0
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;
}
示例#3
0
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;
}
示例#4
0
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);
}
示例#5
0
RSPrivate void __RSErrorDeallocate()
{
    if (!__RSErrorCallBackTable) return;
    RSSpinLockLock(&__RSErrorCallBackTableSpinlock);
    RSRelease(__RSErrorCallBackTable);
    __RSErrorCallBackTable = nil;
    RSSpinLockUnlock(&__RSErrorCallBackTableSpinlock);
}
示例#6
0
RSExport RSErrorUserInfoKeyCallBack RSErrorGetCallBackForDomain(RSStringRef domainName)
{
    if (!__RSErrorCallBackTable) __RSErrorInitUserInfoKeyCallBackTable();
    RSSpinLockLock(&__RSErrorCallBackTableSpinlock);
    RSErrorUserInfoKeyCallBack cb = RSDictionaryGetValue(__RSErrorCallBackTable, domainName);
    RSSpinLockUnlock(&__RSErrorCallBackTableSpinlock);
    return cb;
}
示例#7
0
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;
}
示例#8
0
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;
}
示例#9
0
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);
}
示例#10
0
static void __RSProcessInfoDeallocate(void) {
    RSSpinLockLock(&__RSProcessInfoLock);
    if (__RSProcessInfoGlobal)
    {
        __RSRuntimeSetInstanceSpecial(__RSProcessInfoGlobal, NO);
        RSRelease(__RSProcessInfoGlobal);
        __RSProcessInfoGlobal = nil;
    }
    RSSpinLockUnlock(&__RSProcessInfoLock);
}
示例#11
0
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);
}
示例#12
0
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;
}