OSDN Git Service

RIO-6534: Updates to OsclSingleton & OsclTls
authorPacketVideo CM <engbuild@pv.com>
Tue, 30 Mar 2010 21:58:51 +0000 (14:58 -0700)
committerPacketVideo CM <engbuild@pv.com>
Tue, 30 Mar 2010 21:58:51 +0000 (14:58 -0700)
Change-Id: I2706c360ed86318606b28f8c268e5637bc488151

engines/2way/src/pv_2way_sdkinfo.h
engines/author/src/pv_author_sdkinfo.h
engines/player/src/pv_player_sdkinfo.h
oscl/oscl/osclbase/src/oscl_base.cpp
oscl/oscl/osclbase/src/oscl_singleton.cpp
oscl/oscl/osclbase/src/oscl_singleton.h
oscl/oscl/osclbase/src/oscl_tls.cpp
oscl/oscl/osclbase/src/oscl_tls.h

index 3d85324..b73488a 100644 (file)
@@ -21,7 +21,7 @@
 // This header file is automatically generated at build-time
 // *** OFFICIAL RELEASE INFO -- Will not auto update
 
-#define PV2WAY_ENGINE_SDKINFO_LABEL "1338044"
+#define PV2WAY_ENGINE_SDKINFO_LABEL "1338246"
 #define PV2WAY_ENGINE_SDKINFO_DATE 0x20100323
 
 #endif //PV_2WAY_SDKINFO_H_INCLUDED
index aecc42b..6580ab7 100644 (file)
@@ -21,7 +21,7 @@
 // This header file is automatically generated at build-time
 // *** OFFICIAL RELEASE INFO -- Will not auto update
 
-#define PVAUTHOR_ENGINE_SDKINFO_LABEL "1338044"
+#define PVAUTHOR_ENGINE_SDKINFO_LABEL "1338246"
 #define PVAUTHOR_ENGINE_SDKINFO_DATE 0x20100323
 
 #endif //PV_AUTHOR_SDKINFO_H_INCLUDED
index 4881566..a5d7960 100644 (file)
@@ -21,7 +21,7 @@
 // This header file is automatically generated at build-time
 // *** OFFICIAL RELEASE INFO -- Will not auto update
 
-#define PVPLAYER_ENGINE_SDKINFO_LABEL "1338044"
+#define PVPLAYER_ENGINE_SDKINFO_LABEL "1338246"
 #define PVPLAYER_ENGINE_SDKINFO_DATE 0x20100323
 
 #endif //PV_PLAYER_SDKINFO_H_INCLUDED
index b338a26..d66d77b 100644 (file)
@@ -1,5 +1,5 @@
 /* ------------------------------------------------------------------
- * Copyright (C) 1998-2009 PacketVideo
+ * Copyright (C) 1998-2010 PacketVideo
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -35,32 +35,12 @@ OSCL_EXPORT_REF int32 OsclBase::Init()
         if (error)
             return error;
     }
-#if (OSCL_HAS_SINGLETON_SUPPORT)
-    {
-        _OsclBasicAllocator alloc;
-        int32 error;
-        OsclSingletonRegistry::initialize(alloc, error);
-        //exit on error
-        if (error)
-            return error;
-    }
-#endif
     return 0;
 }
 
 OSCL_EXPORT_REF int32 OsclBase::Cleanup()
 {
     int32 result = 0;
-#if (OSCL_HAS_SINGLETON_SUPPORT)
-    {
-        _OsclBasicAllocator alloc;
-        int32 error;
-        OsclSingletonRegistry::cleanup(alloc, error);
-        //continue if error
-        if (error)
-            result = error;
-    }
-#endif
     {
         _OsclBasicAllocator alloc;
         int32 error;
index 310b02e..1ae3332 100644 (file)
@@ -1,5 +1,5 @@
 /* ------------------------------------------------------------------
- * Copyright (C) 1998-2009 PacketVideo
+ * Copyright (C) 1998-2010 PacketVideo
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 #include "oscl_lock_base.h"
 #include "oscl_base_alloc.h"
 
-
-OsclSingletonRegistry::SingletonTable* OsclSingletonRegistry::iSingletonTable = NULL;
-
-
-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 OsclSingletonRegistry::cleanup(Oscl_DefAlloc &alloc, int32 &aError)
-{
-    aError = 0;
-    if (!iSingletonTable)
-    {
-        aError = EPVErrorBaseNotInstalled;//no table!
-        return;
-    }
-
-    //decrement the ref count and cleanup when it reaches zero.
-    iSingletonTable->iTableLock.Lock();
-    iSingletonTable->iRefCount--;
-    if (iSingletonTable->iRefCount == 0)
-    {
-        //cleanup
-        iSingletonTable->iTableLock.Unlock();
-        iSingletonTable->~SingletonTable();
-        alloc.deallocate(iSingletonTable);
-        iSingletonTable = NULL;
-    }
-    else
-    {
-        iSingletonTable->iTableLock.Unlock();
-    }
-}
+// static object instantiation, alive with application
+OsclSingletonRegistry::SingletonTable OsclSingletonRegistry::sSingletonTable;
 
 OSCL_EXPORT_REF OsclAny* OsclSingletonRegistry::getInstance(uint32 ID, int32 &aError)
 {
     OSCL_ASSERT(ID < OSCL_SINGLETON_ID_LAST);
 
     aError = 0;
-    if (!iSingletonTable)
-    {
-        aError = EPVErrorBaseNotInstalled;//no table!
-        return NULL;
-    }
-
-    iSingletonTable->iSingletonLocks[ID].Lock();
-    OsclAny* value = iSingletonTable->iSingletons[ID];
-    iSingletonTable->iSingletonLocks[ID].Unlock();
-
+    sSingletonTable.iSingletonLocks[ID].Lock();
+    OsclAny* value = sSingletonTable.iSingletons[ID];
+    sSingletonTable.iSingletonLocks[ID].Unlock();
     return value;
 }
 
@@ -102,15 +44,9 @@ OSCL_EXPORT_REF void OsclSingletonRegistry::registerInstance(OsclAny* ptr, uint3
     OSCL_ASSERT(ID < OSCL_SINGLETON_ID_LAST);
 
     aError = 0;
-    if (!iSingletonTable)
-    {
-        aError = EPVErrorBaseNotInstalled;//no table!
-        return;
-    }
-
-    iSingletonTable->iSingletonLocks[ID].Lock();
-    iSingletonTable->iSingletons[ID] = ptr;
-    iSingletonTable->iSingletonLocks[ID].Unlock();
+    sSingletonTable.iSingletonLocks[ID].Lock();
+    sSingletonTable.iSingletons[ID] = ptr;
+    sSingletonTable.iSingletonLocks[ID].Unlock();
 }
 
 OSCL_EXPORT_REF OsclAny* OsclSingletonRegistry::lockAndGetInstance(uint32 ID, int32 &aError)
@@ -118,16 +54,9 @@ OSCL_EXPORT_REF OsclAny* OsclSingletonRegistry::lockAndGetInstance(uint32 ID, in
     OSCL_ASSERT(ID < OSCL_SINGLETON_ID_LAST);
 
     aError = 0;
-
-    if (!iSingletonTable)
-    {
-        aError = EPVErrorBaseNotInstalled;//no table!
-        return NULL;
-    }
-
-    iSingletonTable->iSingletonLocks[ID].Lock();
-    OsclAny* value = iSingletonTable->iSingletons[ID];
-    //leave it locked.
+    sSingletonTable.iSingletonLocks[ID].Lock();
+    OsclAny* value = sSingletonTable.iSingletons[ID];
+    //leave this table entry locked
 
     return value;
 }
@@ -138,16 +67,9 @@ OSCL_EXPORT_REF void OsclSingletonRegistry::registerInstanceAndUnlock(OsclAny* p
 
     aError = 0;
 
-    if (!iSingletonTable)
-    {
-        aError = EPVErrorBaseNotInstalled;//no table!
-        return;
-    }
-
     //assume it's already locked.
-
-    iSingletonTable->iSingletons[ID] = ptr;
-    iSingletonTable->iSingletonLocks[ID].Unlock();
+    sSingletonTable.iSingletons[ID] = ptr;
+    sSingletonTable.iSingletonLocks[ID].Unlock();
 }
 
 #endif //OSCL_HAS_SINGLETON_SUPPORT
index 6cf3ca5..06c966d 100644 (file)
@@ -114,26 +114,22 @@ class OsclSingletonRegistry
         typedef registry_type* registry_pointer_type;
 
     private:
-        OSCL_IMPORT_REF static void initialize(Oscl_DefAlloc &alloc, int32 &error);
-        OSCL_IMPORT_REF static void cleanup(Oscl_DefAlloc &alloc, int32 &error);
         friend class OsclBase;
 
     private:
         class SingletonTable
         {
             public:
-                SingletonTable(): iRefCount(0)
+                SingletonTable()
                 {
                     for (uint32 i = 0; i < OSCL_SINGLETON_ID_LAST; i++)
                         iSingletons[i] = NULL;
                 }
-                _OsclBasicLock iTableLock;
-                uint32 iRefCount;
                 OsclAny* iSingletons[OSCL_SINGLETON_ID_LAST];
                 _OsclBasicLock iSingletonLocks[OSCL_SINGLETON_ID_LAST];
         };
         //The singleton table is a global variable.
-        static SingletonTable* iSingletonTable;
+        static SingletonTable sSingletonTable;
 };
 
 template < class T, uint32 ID, class Registry = OsclSingletonRegistry > class OsclSingleton
index 42379e1..5b04632 100644 (file)
@@ -1,5 +1,5 @@
 /* ------------------------------------------------------------------
- * Copyright (C) 1998-2009 PacketVideo
+ * Copyright (C) 1998-2010 PacketVideo
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -64,12 +64,13 @@ OsclTLSRegistry::TlsKey* OsclTLSRegistry::iTlsKey = NULL;
 
 #endif //OSCL_TLS_IS_KEYED
 
-
+_OsclBasicLock OsclTLSRegistry::sLock; // static object instanciated, alive with application
 
 OSCL_EXPORT_REF void OsclTLSRegistry::initialize(Oscl_DefAlloc &alloc, int32 &aError)
 {
     TOsclTlsKey* pkey = NULL;
     aError = 0;
+    sLock.Lock();
 
 #if ( OSCL_TLS_IS_KEYED)
     //Allocate the table on the first init call.
@@ -81,6 +82,7 @@ OSCL_EXPORT_REF void OsclTLSRegistry::initialize(Oscl_DefAlloc &alloc, int32 &aE
         if (!table)
         {
             aError = EPVErrorBaseOutOfMemory;
+            sLock.Unlock();
             return;
         }
 
@@ -90,6 +92,7 @@ OSCL_EXPORT_REF void OsclTLSRegistry::initialize(Oscl_DefAlloc &alloc, int32 &aE
         {
             aError = EPVErrorBaseOutOfMemory;
             alloc.deallocate(table);
+            sLock.Unlock();
             return;
         }
 
@@ -99,21 +102,18 @@ OSCL_EXPORT_REF void OsclTLSRegistry::initialize(Oscl_DefAlloc &alloc, int32 &aE
             aError = EPVErrorBaseSystemCallFailed;
             alloc.deallocate(pkey);
             alloc.deallocate(table);
+            sLock.Unlock();
             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
@@ -124,6 +124,7 @@ OSCL_EXPORT_REF void OsclTLSRegistry::initialize(Oscl_DefAlloc &alloc, int32 &aE
     if (registry == 0)
     {
         aError = EPVErrorBaseOutOfMemory;
+        sLock.Unlock();
         return;
     }
 
@@ -135,17 +136,20 @@ OSCL_EXPORT_REF void OsclTLSRegistry::initialize(Oscl_DefAlloc &alloc, int32 &aE
 
     // save it away
     TLSStorageOps::save_registry(pkey, registry, aError);
+    sLock.Unlock();
 }
 
 OSCL_EXPORT_REF void OsclTLSRegistry::cleanup(Oscl_DefAlloc &alloc, int32 &aError)
 {
     TOsclTlsKey* pkey = NULL;
     aError = 0;
+    sLock.Lock();
 
 #if (OSCL_TLS_IS_KEYED)
     if (!iTlsKey)
     {
         aError = EPVErrorBaseNotInstalled;//No key!
+        sLock.Unlock();
         return;
     }
     pkey = iTlsKey->iOsclTlsKey;
@@ -156,35 +160,34 @@ OSCL_EXPORT_REF void OsclTLSRegistry::cleanup(Oscl_DefAlloc &alloc, int32 &aErro
     if (!OSCL_TLS_REGISTRY_VALID(registry))
     {
         aError = EPVErrorBaseNotInstalled;//No registry!
+        sLock.Unlock();
         return;
     }
     alloc.deallocate(registry);
 
     TLSStorageOps::save_registry(pkey, NULL, aError);
     if (aError)
+    {
+        sLock.Unlock();
         return;
+    }
 
 #if (OSCL_TLS_IS_KEYED)
 
     //Remove Tls key
-
-    iTlsKey->iLock.Lock();
     iTlsKey->iRefCnt--;
     if (iTlsKey->iRefCnt == 0)
     {
         //Deallocate key.
         OSCL_TLS_KEY_DELETE_FUNC(*pkey);
         alloc.deallocate(pkey);
-        iTlsKey->iLock.Unlock();
         iTlsKey->~TlsKey();
         alloc.deallocate(iTlsKey);
         iTlsKey = NULL;
     }
-    else
-    {
-        iTlsKey->iLock.Unlock();
-    }
 #endif
+
+    sLock.Unlock();
 }
 
 OSCL_EXPORT_REF OsclAny* OsclTLSRegistry::getInstance(uint32 ID, int32 &aError)
@@ -195,10 +198,12 @@ OSCL_EXPORT_REF OsclAny* OsclTLSRegistry::getInstance(uint32 ID, int32 &aError)
 
     TOsclTlsKey* pkey = NULL;
 
+    sLock.Lock();
 #if (OSCL_TLS_IS_KEYED)
     if (!iTlsKey)
     {
         aError = EPVErrorBaseNotInstalled;//No table!
+        sLock.Unlock();
         return NULL;
     }
     pkey = iTlsKey->iOsclTlsKey;
@@ -208,10 +213,13 @@ OSCL_EXPORT_REF OsclAny* OsclTLSRegistry::getInstance(uint32 ID, int32 &aError)
     if (!OSCL_TLS_REGISTRY_VALID(registry))
     {
         aError = EPVErrorBaseNotInstalled;//No registry!
+        sLock.Unlock();
         return NULL;
     }
+    registry_type id = registry[ID];
+    sLock.Unlock();
 
-    return registry[ID];
+    return id;
 }
 
 OSCL_EXPORT_REF void OsclTLSRegistry::registerInstance(OsclAny* ptr, uint32 ID, int32 &aError)
@@ -220,11 +228,13 @@ OSCL_EXPORT_REF void OsclTLSRegistry::registerInstance(OsclAny* ptr, uint32 ID,
 
     aError = 0;
     TOsclTlsKey *pkey = NULL;
+    sLock.Lock();
 
 #if (OSCL_TLS_IS_KEYED)
     if (!iTlsKey)
     {
         aError = EPVErrorBaseNotInstalled;//No table!
+        sLock.Unlock();
         return ;
     }
     pkey = iTlsKey->iOsclTlsKey;
@@ -234,11 +244,12 @@ OSCL_EXPORT_REF void OsclTLSRegistry::registerInstance(OsclAny* ptr, uint32 ID,
     if (!OSCL_TLS_REGISTRY_VALID(registry))
     {
         aError = EPVErrorBaseNotInstalled;//no registry!
+        sLock.Unlock();
         return;
     }
 
     registry[ID] = ptr;
-
+    sLock.Unlock();
 }
 
 
index a874420..6fcc2f5 100644 (file)
@@ -113,6 +113,7 @@ class OsclTLSRegistry
         {}
         typedef OsclAny* registry_type;
         typedef registry_type* registry_pointer_type;
+        static _OsclBasicLock sLock;  // _osclbaselock declaration with TLS registry and key
 
 #if ( OSCL_TLS_IS_KEYED)
         class TlsKey
@@ -120,7 +121,6 @@ class OsclTLSRegistry
             public:
                 TlsKey(): iRefCnt(0), iOsclTlsKey(NULL)
                 {}
-                _OsclBasicLock iLock;
                 uint32 iRefCnt;
                 TOsclTlsKey *iOsclTlsKey;
         };