[Libreoffice-commits] core.git: cppu/source

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Fri Aug 6 10:15:35 UTC 2021


 cppu/source/threadpool/current.cxx     |   39 +++++++++------------
 cppu/source/threadpool/current.hxx     |    2 -
 cppu/source/threadpool/threadident.cxx |   61 +++++++++++++++------------------
 3 files changed, 47 insertions(+), 55 deletions(-)

New commits:
commit 413b80ed1a9d29f394d0746106f5698e65fe23dc
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Fri Aug 6 09:59:52 2021 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Fri Aug 6 12:14:58 2021 +0200

    return a reference instead of a pointer
    
    and remove redundant nullptr OSL_ENSURE check
    
    Change-Id: I19e202c3786386ed6f094504a0e1eb6928aa423a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120105
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/cppu/source/threadpool/current.cxx b/cppu/source/threadpool/current.cxx
index e163a20be2ec..6a992c6af541 100644
--- a/cppu/source/threadpool/current.cxx
+++ b/cppu/source/threadpool/current.cxx
@@ -106,33 +106,31 @@ IdContainer::~IdContainer()
     }
 }
 
-IdContainer * getIdContainer()
+IdContainer& getIdContainer()
 {
     static thread_local IdContainer aId;
-    return &aId;
+    return aId;
 }
 
 }
 
-
 extern "C" sal_Bool SAL_CALL uno_setCurrentContext(
     void * pCurrentContext,
     rtl_uString * pEnvTypeName, void * pEnvContext )
     SAL_THROW_EXTERN_C()
 {
-    IdContainer * pId = getIdContainer();
-    OSL_ASSERT( pId );
+    IdContainer& id = getIdContainer();
 
     // free old one
-    if (pId->pCurrentContext)
+    if (id.pCurrentContext)
     {
-        (*pId->pCurrentContextEnv->releaseInterface)(
-            pId->pCurrentContextEnv, pId->pCurrentContext );
-        (*pId->pCurrentContextEnv->aBase.release)(
-            &pId->pCurrentContextEnv->aBase );
-        pId->pCurrentContextEnv = nullptr;
+        (*id.pCurrentContextEnv->releaseInterface)(
+            id.pCurrentContextEnv, id.pCurrentContext );
+        (*id.pCurrentContextEnv->aBase.release)(
+            &id.pCurrentContextEnv->aBase );
+        id.pCurrentContextEnv = nullptr;
 
-        pId->pCurrentContext = nullptr;
+        id.pCurrentContext = nullptr;
     }
 
     if (pCurrentContext)
@@ -144,10 +142,10 @@ extern "C" sal_Bool SAL_CALL uno_setCurrentContext(
         {
             if (pEnv->pExtEnv)
             {
-                pId->pCurrentContextEnv = pEnv->pExtEnv;
-                (*pId->pCurrentContextEnv->acquireInterface)(
-                    pId->pCurrentContextEnv, pCurrentContext );
-                pId->pCurrentContext = pCurrentContext;
+                id.pCurrentContextEnv = pEnv->pExtEnv;
+                (*id.pCurrentContextEnv->acquireInterface)(
+                    id.pCurrentContextEnv, pCurrentContext );
+                id.pCurrentContext = pCurrentContext;
             }
             else
             {
@@ -167,8 +165,7 @@ extern "C" sal_Bool SAL_CALL uno_getCurrentContext(
     void ** ppCurrentContext, rtl_uString * pEnvTypeName, void * pEnvContext )
     SAL_THROW_EXTERN_C()
 {
-    IdContainer * pId = getIdContainer();
-    OSL_ASSERT( pId );
+    IdContainer& id = getIdContainer();
 
     Environment target_env;
 
@@ -189,7 +186,7 @@ extern "C" sal_Bool SAL_CALL uno_getCurrentContext(
     }
 
     // case: null-ref
-    if (nullptr == pId->pCurrentContext)
+    if (nullptr == id.pCurrentContext)
         return true;
 
     if (! target_env.is())
@@ -200,12 +197,12 @@ extern "C" sal_Bool SAL_CALL uno_getCurrentContext(
             return false;
     }
 
-    Mapping mapping(&pId->pCurrentContextEnv->aBase, target_env.get());
+    Mapping mapping(&id.pCurrentContextEnv->aBase, target_env.get());
     OSL_ASSERT( mapping.is() );
     if (! mapping.is())
         return false;
 
-    mapping.mapInterface(ppCurrentContext, pId->pCurrentContext, ::cppu::get_type_XCurrentContext() );
+    mapping.mapInterface(ppCurrentContext, id.pCurrentContext, ::cppu::get_type_XCurrentContext());
 
     return true;
 }
diff --git a/cppu/source/threadpool/current.hxx b/cppu/source/threadpool/current.hxx
index 8ab4e3acf43a..cb0094413d66 100644
--- a/cppu/source/threadpool/current.hxx
+++ b/cppu/source/threadpool/current.hxx
@@ -41,7 +41,7 @@ struct IdContainer
     ~IdContainer();
 };
 
-IdContainer * getIdContainer();
+IdContainer& getIdContainer();
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/cppu/source/threadpool/threadident.cxx b/cppu/source/threadpool/threadident.cxx
index 544acc7af520..16b7c0b2700a 100644
--- a/cppu/source/threadpool/threadident.cxx
+++ b/cppu/source/threadpool/threadident.cxx
@@ -27,12 +27,10 @@
 
 #include "current.hxx"
 
-
 using namespace ::std;
 using namespace ::osl;
 using namespace ::cppu;
 
-
 static void createLocalId( sal_Sequence **ppThreadId )
 {
     rtl_byte_sequence_constructNoDefault( ppThreadId , 4 + 16 );
@@ -44,74 +42,71 @@ static void createLocalId( sal_Sequence **ppThreadId )
     rtl_getGlobalProcessId( reinterpret_cast<sal_uInt8 *>(&(*ppThreadId)->elements[4]) );
 }
 
-
 extern "C" void SAL_CALL
 uno_getIdOfCurrentThread( sal_Sequence **ppThreadId )
     SAL_THROW_EXTERN_C()
 {
-    IdContainer * p = getIdContainer();
-    if( ! p->bInit )
+    IdContainer& id = getIdContainer();
+    if (!id.bInit)
     {
         // first time, that the thread enters the bridge
         createLocalId( ppThreadId );
 
         // TODO
         // note : this is a leak !
-        p->pLocalThreadId = *ppThreadId;
-        p->pCurrentId = *ppThreadId;
-        p->nRefCountOfCurrentId = 1;
-        rtl_byte_sequence_acquire( p->pLocalThreadId );
-        rtl_byte_sequence_acquire( p->pCurrentId );
-        p->bInit = true;
+        id.pLocalThreadId = *ppThreadId;
+        id.pCurrentId = *ppThreadId;
+        id.nRefCountOfCurrentId = 1;
+        rtl_byte_sequence_acquire( id.pLocalThreadId );
+        rtl_byte_sequence_acquire( id.pCurrentId );
+        id.bInit = true;
     }
     else
     {
-        p->nRefCountOfCurrentId ++;
+        id.nRefCountOfCurrentId ++;
         if( *ppThreadId )
         {
             rtl_byte_sequence_release( *ppThreadId );
         }
-        *ppThreadId = p->pCurrentId;
+        *ppThreadId = id.pCurrentId;
         rtl_byte_sequence_acquire( *ppThreadId );
     }
 }
 
-
 extern "C" void SAL_CALL uno_releaseIdFromCurrentThread()
     SAL_THROW_EXTERN_C()
 {
-    IdContainer *p = getIdContainer();
-    OSL_ASSERT( p );
-    OSL_ASSERT( p->bInit );
-    OSL_ASSERT( p->nRefCountOfCurrentId );
+    IdContainer& id = getIdContainer();
+    OSL_ASSERT( id.bInit );
+    OSL_ASSERT( id.nRefCountOfCurrentId );
 
-    p->nRefCountOfCurrentId --;
-    if( ! p->nRefCountOfCurrentId && (p->pLocalThreadId != p->pCurrentId) )
+    id.nRefCountOfCurrentId --;
+    if( ! id.nRefCountOfCurrentId && (id.pLocalThreadId != id.pCurrentId) )
     {
-        rtl_byte_sequence_assign( &(p->pCurrentId) , p->pLocalThreadId );
+        rtl_byte_sequence_assign( &(id.pCurrentId) , id.pLocalThreadId );
     }
 }
 
 extern "C" sal_Bool SAL_CALL uno_bindIdToCurrentThread( sal_Sequence *pThreadId )
     SAL_THROW_EXTERN_C()
 {
-    IdContainer *p = getIdContainer();
-    if( ! p->bInit )
+    IdContainer& id = getIdContainer();
+    if (!id.bInit)
     {
-        p->pLocalThreadId = nullptr;
-        createLocalId( &(p->pLocalThreadId) );
-        p->nRefCountOfCurrentId = 1;
-        p->pCurrentId = pThreadId;
-        rtl_byte_sequence_acquire( p->pCurrentId );
-        p->bInit = true;
+        id.pLocalThreadId = nullptr;
+        createLocalId( &(id.pLocalThreadId) );
+        id.nRefCountOfCurrentId = 1;
+        id.pCurrentId = pThreadId;
+        rtl_byte_sequence_acquire(id.pCurrentId);
+        id.bInit = true;
     }
     else
     {
-        OSL_ASSERT( 0 == p->nRefCountOfCurrentId );
-        if( 0 == p->nRefCountOfCurrentId )
+        OSL_ASSERT( 0 == id.nRefCountOfCurrentId );
+        if( 0 == id.nRefCountOfCurrentId )
         {
-            rtl_byte_sequence_assign(&( p->pCurrentId ), pThreadId );
-            p->nRefCountOfCurrentId ++;
+            rtl_byte_sequence_assign(&( id.pCurrentId ), pThreadId );
+            id.nRefCountOfCurrentId ++;
         }
         else
         {


More information about the Libreoffice-commits mailing list