[Libreoffice-commits] core.git: 2 commits - jurt/source sal/Library_sal.mk sal/osl

Stephan Bergmann sbergman at redhat.com
Wed Oct 1 01:20:45 PDT 2014


 jurt/source/pipe/staticsalhack_c.c     |    1 
 jurt/source/pipe/staticsalhack_cxx.cxx |    1 
 sal/Library_sal.mk                     |    2 
 sal/osl/unx/thread.c                   | 1011 -------------------------------
 sal/osl/unx/thread.cxx                 | 1044 +++++++++++++++++++++++++++++++++
 5 files changed, 1046 insertions(+), 1013 deletions(-)

New commits:
commit 4b0197627dcd031758b6ced994f718ce777e69eb
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Wed Oct 1 09:02:08 2014 +0200

    Use sal/log.hxx
    
    Change-Id: I54fd66b8788171884c6d3d6e7645871615d48080

diff --git a/sal/osl/unx/thread.cxx b/sal/osl/unx/thread.cxx
index fc0ff87..1f0a587 100644
--- a/sal/osl/unx/thread.cxx
+++ b/sal/osl/unx/thread.cxx
@@ -16,18 +16,21 @@
  *   except in compliance with the License. You may obtain a copy of
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
-#include <assert.h>
+
+#include <sal/config.h>
+
+#include <cassert>
 #include "system.h"
 #include <string.h>
 #if defined(OPENBSD)
 #include <sched.h>
 #endif
 #include <config_options.h>
-#include <osl/diagnose.h>
 #include <osl/thread.h>
 #include <osl/nlsupport.h>
 #include <rtl/textenc.h>
 #include <rtl/alloc.h>
+#include <sal/log.hxx>
 #include <sal/macros.h>
 #ifdef ANDROID
 #include <jni.h>
@@ -157,7 +160,7 @@ Thread_Impl* osl_thread_construct_Impl (void)
 
 static void osl_thread_destruct_Impl (Thread_Impl ** ppImpl)
 {
-    OSL_ASSERT(ppImpl);
+    assert(ppImpl);
     if (*ppImpl)
     {
         pthread_cond_destroy  (&((*ppImpl)->m_Cond));
@@ -295,8 +298,10 @@ static oslThread osl_thread_create_Impl (
         osl_thread_start_Impl,
         (void*)(pImpl))) != 0)
     {
-        OSL_TRACE("osl_thread_create_Impl(): errno: %d, %s\n",
-                  nRet, strerror(nRet));
+        SAL_WARN(
+            "sal.osl",
+            "pthread_create failed with " << nRet << " \"" << strerror(nRet)
+                << "\"");
 
         pthread_mutex_unlock (&(pImpl->m_Lock));
         osl_thread_destruct_Impl (&pImpl);
@@ -360,9 +365,11 @@ void SAL_CALL osl_resumeThread(oslThread Thread)
 {
     Thread_Impl* pImpl= (Thread_Impl*)Thread;
 
-    OSL_ASSERT(pImpl);
     if (!pImpl)
+    {
+        SAL_WARN("sal.osl", "invalid osl_resumeThread(nullptr) call");
         return; /* EINVAL */
+    }
 
     pthread_mutex_lock (&(pImpl->m_Lock));
 
@@ -380,9 +387,11 @@ void SAL_CALL osl_suspendThread(oslThread Thread)
 {
     Thread_Impl* pImpl= (Thread_Impl*)Thread;
 
-    OSL_ASSERT(pImpl);
     if (!pImpl)
+    {
+        SAL_WARN("sal.osl", "invalid osl_suspendThread(nullptr) call");
         return; /* EINVAL */
+    }
 
     pthread_mutex_lock (&(pImpl->m_Lock));
 
@@ -450,9 +459,11 @@ void SAL_CALL osl_terminateThread(oslThread Thread)
 {
     Thread_Impl* pImpl= (Thread_Impl*)Thread;
 
-    OSL_ASSERT(pImpl);
     if (!pImpl)
+    {
+        SAL_WARN("sal.osl", "invalid osl_terminateThread(nullptr) call");
         return; /* EINVAL */
+    }
 
     pthread_mutex_lock (&(pImpl->m_Lock));
 
@@ -473,13 +484,17 @@ sal_Bool SAL_CALL osl_scheduleThread(oslThread Thread)
     bool terminate;
     Thread_Impl* pImpl= (Thread_Impl*)Thread;
 
-    OSL_ASSERT(pImpl);
     if (!pImpl)
+    {
+        SAL_WARN("sal.osl", "invalid osl_scheduleThread(nullptr) call");
         return sal_False; /* EINVAL */
+    }
 
-    OSL_ASSERT(pthread_equal (pthread_self(), pImpl->m_hThread));
     if (!(pthread_equal (pthread_self(), pImpl->m_hThread)))
+    {
+        SAL_WARN("sal.osl", "invalid osl_scheduleThread(non-self) call");
         return sal_False; /* EINVAL */
+    }
 
     pthread_mutex_lock (&(pImpl->m_Lock));
 
@@ -524,9 +539,8 @@ void SAL_CALL osl_yieldThread()
 void SAL_CALL osl_setThreadName(char const * name) {
 #if defined LINUX && ! defined __FreeBSD_kernel__
     if (prctl(PR_SET_NAME, (unsigned long) name, 0, 0, 0) != 0) {
-        OSL_TRACE(
-            "%s prctl(PR_SET_NAME) failed with errno %d", OSL_LOG_PREFIX,
-            errno);
+        int e = errno;
+        SAL_WARN("sal.osl", "prctl(PR_SET_NAME) failed with errno " << e);
     }
 #else
     (void) name;
@@ -689,7 +703,10 @@ static void osl_thread_priority_init_Impl (void)
 
     if ((nRet = pthread_getschedparam(pthread_self(), &policy, &param)) != 0)
     {
-        OSL_TRACE("failed to get priority of thread [%s]",strerror(nRet));
+        SAL_WARN(
+            "sal.osl",
+            "pthread_getschedparam failed with " << nRet << " \""
+                << strerror(nRet) << "\"");
         return;
     }
 
@@ -705,27 +722,33 @@ static void osl_thread_priority_init_Impl (void)
 
     if ((nRet = sched_get_priority_min(policy) ) != -1)
     {
-        OSL_TRACE("Min Prioriy for policy '%i' == '%i'",policy,nRet);
+        SAL_INFO(
+            "sal.osl", "Min Prioriy for policy " << policy << " == " << nRet);
         g_thread.m_priority.m_Lowest=nRet;
     }
-#if OSL_DEBUG_LEVEL > 1
     else
     {
-        fprintf(stderr,"failed to get min sched param [%s]\n",strerror(errno));
+        int e = errno;
+        SAL_WARN(
+            "sal.osl",
+            "sched_get_priority_min failed with " << e << " \"" << strerror(e)
+                << "\"");
     }
-#endif /* OSL_DEBUG_LEVEL */
 
     if ((nRet = sched_get_priority_max(policy) ) != -1)
     {
-        OSL_TRACE("Max Prioriy for policy '%i' == '%i'",policy,nRet);
+        SAL_INFO(
+            "sal.osl", "Max Prioriy for policy " << policy << " == " << nRet);
         g_thread.m_priority.m_Highest=nRet;
     }
-#if OSL_DEBUG_LEVEL > 1
     else
     {
-        fprintf(stderr,"failed to get max sched param [%s]\n",strerror(errno));
+        int e = errno;
+        SAL_WARN(
+            "sal.osl",
+            "sched_get_priority_max failed with " << e << " \"" << strerror(e)
+                << "\"");
     }
-#endif /* OSL_DEBUG_LEVEL */
 
     g_thread.m_priority.m_Normal =
         (g_thread.m_priority.m_Lowest + g_thread.m_priority.m_Highest) / 2;
@@ -740,8 +763,14 @@ static void osl_thread_priority_init_Impl (void)
 
     if ((nRet = pthread_setschedparam(pthread_self(), policy, &param)) != 0)
     {
-        OSL_TRACE("failed to change base priority of thread [%s]",strerror(nRet));
-        OSL_TRACE("Thread ID '%i', Policy '%i', Priority '%i'\n",pthread_self(),policy,param.sched_priority);
+        SAL_WARN(
+            "sal.osl",
+            "pthread_setschedparam failed with " << nRet << " \""
+                << strerror(nRet) << "\"");
+        SAL_INFO(
+            "sal.osl",
+            "Thread ID " << pthread_self() << ", Policy " << policy
+                << ", Priority " << param.sched_priority);
     }
 
 #endif /* NO_PTHREAD_PRIORITY */
@@ -769,9 +798,11 @@ void SAL_CALL osl_setThreadPriority (
 
     Thread_Impl* pImpl= (Thread_Impl*)Thread;
 
-    OSL_ASSERT(pImpl);
     if (!pImpl)
+    {
+        SAL_WARN("sal.osl", "invalid osl_setThreadPriority(nullptr, ...) call");
         return; /* EINVAL */
+    }
 
 #ifdef NO_PTHREAD_PRIORITY
     (void) Priority; /* unused */
@@ -815,22 +846,25 @@ void SAL_CALL osl_setThreadPriority (
             break;
 
         case osl_Thread_PriorityUnknown:
-            OSL_ASSERT(sal_False);      /* only fools try this...*/
-
-            /* let release-version behave friendly */
+            SAL_WARN(
+                "sal.osl",
+                "invalid osl_setThreadPriority(..., osl_Thread_PriorityUnknown)"
+                    " call");
             return;
 
         default:
-            /* enum expanded, but forgotten here...*/
-            OSL_ENSURE(sal_False,"osl_setThreadPriority : unknown priority\n");
-
-            /* let release-version behave friendly */
+            SAL_WARN(
+                "sal.osl",
+                "invalid osl_setThreadPriority(..., " << Priority << ") call");
             return;
     }
 
     if ((nRet = pthread_setschedparam(pImpl->m_hThread, policy, &Param)) != 0)
     {
-        OSL_TRACE("failed to change thread priority [%s]",strerror(nRet));
+        SAL_WARN(
+            "sal.osl",
+            "pthread_setschedparam failed with " << nRet << " \""
+                << strerror(nRet) << "\"");
     }
 
 #endif /* NO_PTHREAD_PRIORITY */
@@ -848,9 +882,11 @@ oslThreadPriority SAL_CALL osl_getThreadPriority(const oslThread Thread)
     oslThreadPriority Priority = osl_Thread_PriorityNormal;
     Thread_Impl* pImpl= (Thread_Impl*)Thread;
 
-    OSL_ASSERT(pImpl);
     if (!pImpl)
+    {
+        SAL_WARN("sal.osl", "invalid osl_getThreadPriority(nullptr) call");
         return osl_Thread_PriorityUnknown; /* EINVAL */
+    }
 
 #ifndef NO_PTHREAD_PRIORITY
 
@@ -967,15 +1003,13 @@ static void osl_thread_textencoding_init_Impl (void)
 
     /* determine default text encoding */
     defaultEncoding = osl_getTextEncodingFromLocale(NULL);
-    OSL_ASSERT(defaultEncoding != RTL_TEXTENCODING_DONTKNOW);
-
-    /*
-    Tools string functions call abort() on an unknown encoding so ASCII
-    is a meaningfull fallback regardless whether the assertion makes sense.
-    */
-
+    // Tools string functions call abort() on an unknown encoding so ASCII is a
+    // meaningfull fallback:
     if ( RTL_TEXTENCODING_DONTKNOW == defaultEncoding )
+    {
+        SAL_WARN("sal.osl", "RTL_TEXTENCODING_DONTKNOW -> _ASCII_US");
         defaultEncoding = RTL_TEXTENCODING_ASCII_US;
+    }
 
     g_thread.m_textencoding.m_default = defaultEncoding;
 }
commit 585ac6e4dd49d8cb52e575a0ba1aaec9b58aa835
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Wed Oct 1 08:37:21 2014 +0200

    sal/osl/unx/thread.c -> .cxx
    
    Change-Id: I6cb46a51dda3fda51a3b6413656da15fc5bdb04d

diff --git a/jurt/source/pipe/staticsalhack_c.c b/jurt/source/pipe/staticsalhack_c.c
index 77c4291..ac9a913 100644
--- a/jurt/source/pipe/staticsalhack_c.c
+++ b/jurt/source/pipe/staticsalhack_c.c
@@ -14,6 +14,5 @@
 #include <sal/osl/unx/nlsupport.c>
 #include <sal/osl/unx/pipe.c>
 #include <sal/osl/unx/readwrite_helper.c>
-#include <sal/osl/unx/thread.c>
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/jurt/source/pipe/staticsalhack_cxx.cxx b/jurt/source/pipe/staticsalhack_cxx.cxx
index f3a5e5d..de02379 100644
--- a/jurt/source/pipe/staticsalhack_cxx.cxx
+++ b/jurt/source/pipe/staticsalhack_cxx.cxx
@@ -31,6 +31,7 @@
 #include <sal/osl/unx/process_impl.cxx>
 #include <sal/osl/unx/profile.cxx>
 #include <sal/osl/unx/security.cxx>
+#include <sal/osl/unx/thread.cxx>
 #include <sal/osl/unx/uunxapi.cxx>
 #include <sal/rtl/alloc_arena.cxx>
 #include <sal/rtl/alloc_cache.cxx>
diff --git a/sal/Library_sal.mk b/sal/Library_sal.mk
index e5c02c2..12f5551 100644
--- a/sal/Library_sal.mk
+++ b/sal/Library_sal.mk
@@ -167,6 +167,7 @@ $(eval $(call gb_Library_add_exception_objects,sal,\
 	sal/osl/unx/profile \
 	sal/osl/unx/security \
 	sal/osl/unx/tempfile \
+	sal/osl/unx/thread \
         $(if $(filter DESKTOP,$(BUILD_TYPE)), sal/osl/unx/salinit) \
 ))
 $(eval $(call gb_Library_add_cobjects,sal,\
@@ -177,7 +178,6 @@ $(eval $(call gb_Library_add_cobjects,sal,\
 	sal/osl/unx/readwrite_helper \
 	sal/osl/unx/socket \
 	sal/osl/unx/system \
-	sal/osl/unx/thread \
 	sal/osl/unx/time \
 ))
 $(eval $(call gb_Library_add_cobject,sal,sal/osl/unx/signal, \
diff --git a/sal/osl/unx/thread.c b/sal/osl/unx/thread.cxx
similarity index 98%
rename from sal/osl/unx/thread.c
rename to sal/osl/unx/thread.cxx
index 1c703ca..fc0ff87 100644
--- a/sal/osl/unx/thread.c
+++ b/sal/osl/unx/thread.cxx
@@ -144,7 +144,7 @@ static void osl_thread_init_Impl (void)
 
 Thread_Impl* osl_thread_construct_Impl (void)
 {
-    Thread_Impl* pImpl = malloc (sizeof(Thread_Impl));
+    Thread_Impl* pImpl = new Thread_Impl;
     if (pImpl)
     {
         memset (pImpl, 0, sizeof(Thread_Impl));
@@ -171,8 +171,8 @@ static void osl_thread_destruct_Impl (Thread_Impl ** ppImpl)
 static void osl_thread_cleanup_Impl (Thread_Impl * pImpl)
 {
     pthread_t thread;
-    int attached;
-    int destroyed;
+    bool attached;
+    bool destroyed;
 
     pthread_mutex_lock (&(pImpl->m_Lock));
 
@@ -199,7 +199,7 @@ static void osl_thread_cleanup_Impl (Thread_Impl * pImpl)
 
 static void* osl_thread_start_Impl (void* pData)
 {
-    int terminate;
+    bool terminate;
     Thread_Impl* pImpl= (Thread_Impl*)pData;
 
     assert(pImpl);
@@ -345,7 +345,7 @@ void SAL_CALL osl_destroyThread(oslThread Thread)
 {
     if (Thread != NULL) {
         Thread_Impl * impl = (Thread_Impl *) Thread;
-        int active;
+        bool active;
         pthread_mutex_lock(&impl->m_Lock);
         active = (impl->m_Flags & THREADIMPL_FLAGS_ACTIVE) != 0;
         impl->m_Flags |= THREADIMPL_FLAGS_DESTROYED;
@@ -403,7 +403,7 @@ void SAL_CALL osl_suspendThread(oslThread Thread)
 
 sal_Bool SAL_CALL osl_isThreadRunning(const oslThread Thread)
 {
-    sal_Bool active;
+    bool active;
     Thread_Impl* pImpl= (Thread_Impl*)Thread;
 
     if (!pImpl)
@@ -419,7 +419,7 @@ sal_Bool SAL_CALL osl_isThreadRunning(const oslThread Thread)
 void SAL_CALL osl_joinWithThread(oslThread Thread)
 {
     pthread_t thread;
-    int attached;
+    bool attached;
     Thread_Impl* pImpl= (Thread_Impl*)Thread;
 
     if (!pImpl)
@@ -470,7 +470,7 @@ void SAL_CALL osl_terminateThread(oslThread Thread)
 
 sal_Bool SAL_CALL osl_scheduleThread(oslThread Thread)
 {
-    int terminate;
+    bool terminate;
     Thread_Impl* pImpl= (Thread_Impl*)Thread;
 
     OSL_ASSERT(pImpl);
@@ -493,7 +493,7 @@ sal_Bool SAL_CALL osl_scheduleThread(oslThread Thread)
 
     pthread_mutex_unlock(&(pImpl->m_Lock));
 
-    return (terminate == 0);
+    return !terminate;
 }
 
 void SAL_CALL osl_waitThread(const TimeValue* pDelay)
@@ -938,7 +938,7 @@ void* SAL_CALL osl_getThreadKeyData(oslThreadKey Key)
 
 sal_Bool SAL_CALL osl_setThreadKeyData(oslThreadKey Key, void *pData)
 {
-    sal_Bool bRet;
+    bool bRet;
     void *pOldData = NULL;
     wrapper_pthread_key *pKey = (wrapper_pthread_key*)Key;
     if (!pKey)
@@ -987,8 +987,7 @@ rtl_TextEncoding SAL_CALL osl_getThreadTextEncoding()
     pthread_once (&(g_thread.m_once), osl_thread_init_Impl);
 
     /* check for thread specific encoding, use default if not set */
-    threadEncoding = SAL_INT_CAST(
-        rtl_TextEncoding,
+    threadEncoding = static_cast<rtl_TextEncoding>(
         (sal_uIntPtr) pthread_getspecific(g_thread.m_textencoding.m_key));
     if (0 == threadEncoding)
         threadEncoding = g_thread.m_textencoding.m_default;
@@ -1003,7 +1002,7 @@ rtl_TextEncoding osl_setThreadTextEncoding(rtl_TextEncoding Encoding)
     /* save encoding in thread local storage */
     pthread_setspecific (
         g_thread.m_textencoding.m_key,
-        (void*) SAL_INT_CAST(sal_uIntPtr, Encoding));
+        (void*) static_cast<sal_uIntPtr>(Encoding));
 
     return oldThreadEncoding;
 }


More information about the Libreoffice-commits mailing list