OSCL_EXPORT_REF void OsclSingletonRegistry::initialize(Oscl_DefAlloc &alloc, int32 &aError) { aError = 0; //Allocate the registry on the first init call //Note: there's some chance of thread contention here, since //thread lock isn't available until after this step. if (!iSingletonTable) { OsclAny* table = alloc.allocate(sizeof(SingletonTable)); if (table) iSingletonTable = new(table) SingletonTable(); else { aError = EPVErrorBaseOutOfMemory; return; } } //increment the ref count on each init. iSingletonTable->iTableLock.Lock(); iSingletonTable->iRefCount++; iSingletonTable->iTableLock.Unlock(); }
OSCL_EXPORT_REF void OsclTLSRegistry::initialize(Oscl_DefAlloc &alloc, int32 &aError) { TOsclTlsKey* pkey = NULL; aError = 0; #if ( OSCL_TLS_IS_KEYED) //Allocate the table on the first init call. //Note there's some risk of thread contention here, since //the thread lock is not available until after this step. if (!iTlsKey) { OsclAny* table = alloc.allocate(sizeof(TlsKey)); if (!table) { aError = EPVErrorBaseOutOfMemory; return; } //allocate space for key pkey = (TOsclTlsKey*)alloc.allocate(sizeof(TOsclTlsKey)); if (!pkey) { aError = EPVErrorBaseOutOfMemory; alloc.deallocate(table); return; } //create key for this thread. if (!OSCL_TLS_KEY_CREATE_FUNC(*pkey)) { aError = EPVErrorBaseSystemCallFailed; alloc.deallocate(pkey); alloc.deallocate(table); return; } iTlsKey = new(table) TlsKey(); iTlsKey->iLock.Lock(); iTlsKey->iRefCnt++; iTlsKey->iOsclTlsKey = pkey; iTlsKey->iLock.Unlock(); } else { iTlsKey->iLock.Lock(); iTlsKey->iRefCnt++; pkey = iTlsKey->iOsclTlsKey; iTlsKey->iLock.Unlock(); } #endif // allocate the space and save the pointer registry_pointer_type registry = OSCL_STATIC_CAST(registry_pointer_type, alloc.allocate(sizeof(registry_type) * OSCL_TLS_MAX_SLOTS)); if (registry == 0) { aError = EPVErrorBaseOutOfMemory; return; } // initialize all TLSs to 0 for (uint32 ii = 0; ii < OSCL_TLS_MAX_SLOTS; ii++) registry[ii] = 0; // initialize the magic number registry[OSCL_TLS_ID_MAGICNUM] = (OsclAny*)OSCL_TLS_MAGIC_NUMBER; // save it away TLSStorageOps::save_registry(pkey, registry, aError); }