diff options
author | Frank Schoenheit [fs] <frank.schoenheit@oracle.com> | 2011-02-23 09:58:44 +0100 |
---|---|---|
committer | Frank Schoenheit [fs] <frank.schoenheit@oracle.com> | 2011-02-23 09:58:44 +0100 |
commit | 4dcc14fa7e853546d68a48cd9d5f81b69c25bc1f (patch) | |
tree | 58f8531af5e54784fca54c72d414e144b5e18373 /sal | |
parent | fb4f853ff6e53f3537e8e5ff2b488d039d175a16 (diff) | |
parent | ea713649e558dcec291302bffd00b148a96e33a8 (diff) |
debuglevels: merged to-be-m101
Diffstat (limited to 'sal')
-rw-r--r-- | sal/inc/osl/thread.h | 12 | ||||
-rw-r--r-- | sal/inc/osl/thread.hxx | 3 | ||||
-rw-r--r-- | sal/osl/os2/thread.c | 4 | ||||
-rw-r--r-- | sal/osl/unx/pipe.c | 2 | ||||
-rw-r--r-- | sal/osl/unx/thread.c | 16 | ||||
-rwxr-xr-x[-rw-r--r--] | sal/osl/w32/thread.c | 25 | ||||
-rw-r--r-- | sal/prj/build.lst | 1 | ||||
-rw-r--r-- | sal/qa/osl/setthreadname/makefile.mk | 57 | ||||
-rwxr-xr-x | sal/qa/osl/setthreadname/test-setthreadname.cxx | 87 | ||||
-rw-r--r-- | sal/qa/osl/setthreadname/version.map | 34 | ||||
-rwxr-xr-x | sal/util/sal.map | 1 |
11 files changed, 241 insertions, 1 deletions
diff --git a/sal/inc/osl/thread.h b/sal/inc/osl/thread.h index 16860644d7a0..4c53b001fcd6 100644 --- a/sal/inc/osl/thread.h +++ b/sal/inc/osl/thread.h @@ -159,6 +159,18 @@ sal_Bool SAL_CALL osl_scheduleThread(oslThread Thread); */ void SAL_CALL osl_yieldThread(void); +/** Attempts to set the name of the current thread. + + The name of a thread is usually evaluated for debugging purposes. Not all + platforms support this. On Linux, a set thread name can be observed with + "ps -L". On Windows with the Microsoft compiler, a thread name set while a + debugger is attached can be observed within the debugger. + + @param name the name of the thread; must not be null; on Linux, only the + first 16 characters are used +*/ +void SAL_CALL osl_setThreadName(char const * name); + /* Callback when data stored in a thread key is no longer needed */ typedef void (SAL_CALL *oslThreadKeyCallbackFunction)(void *); diff --git a/sal/inc/osl/thread.hxx b/sal/inc/osl/thread.hxx index 51fe059d2210..c3ca49926456 100644 --- a/sal/inc/osl/thread.hxx +++ b/sal/inc/osl/thread.hxx @@ -150,6 +150,9 @@ public: osl_yieldThread(); } + static inline void setName(char const * name) throw () { + osl_setThreadName(name); + } virtual sal_Bool SAL_CALL schedule() { diff --git a/sal/osl/os2/thread.c b/sal/osl/os2/thread.c index 313e67c0f925..0f0c396a407c 100644 --- a/sal/osl/os2/thread.c +++ b/sal/osl/os2/thread.c @@ -549,6 +549,10 @@ void SAL_CALL osl_yieldThread() DosSleep(0); } +void osl_setThreadName(char const * name) { + (void) name; +} + typedef struct _TLS { PULONG pulPtr; diff --git a/sal/osl/unx/pipe.c b/sal/osl/unx/pipe.c index ede4cd7e074f..069ea9990951 100644 --- a/sal/osl/unx/pipe.c +++ b/sal/osl/unx/pipe.c @@ -486,7 +486,7 @@ sal_Int32 SAL_CALL osl_receivePipe(oslPipe pPipe, (sal_Char*)pBuffer, BytesToRead, 0); - if ( nRet <= 0 ) + if ( nRet < 0 ) { OSL_TRACE("osl_receivePipe failed : %i '%s'",nRet,strerror(errno)); } diff --git a/sal/osl/unx/thread.c b/sal/osl/unx/thread.c index fe53915b792f..18c4b033daf7 100644 --- a/sal/osl/unx/thread.c +++ b/sal/osl/unx/thread.c @@ -34,6 +34,10 @@ #include <rtl/textenc.h> #endif +#if defined LINUX +#include <sys/prctl.h> +#endif + /**************************************************************************** * @@@ TODO @@@ * @@ -566,6 +570,18 @@ void SAL_CALL osl_yieldThread() sched_yield(); } +void SAL_CALL osl_setThreadName(char const * name) { +#if defined LINUX + 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); + } +#else + (void) name; +#endif +} + /*****************************************************************************/ /* osl_getThreadIdentifier @@@ see TODO @@@ */ /*****************************************************************************/ diff --git a/sal/osl/w32/thread.c b/sal/osl/w32/thread.c index 88ce87cdf175..8d85c8867b2d 100644..100755 --- a/sal/osl/w32/thread.c +++ b/sal/osl/w32/thread.c @@ -394,6 +394,31 @@ void SAL_CALL osl_yieldThread(void) Sleep(0); } +void SAL_CALL osl_setThreadName(char const * name) { +#ifdef _MSC_VER + /* See <http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx>: */ +#pragma pack(push, 8) + struct { + DWORD dwType; + LPCSTR szName; + DWORD dwThreadID; + DWORD dwFlags; + } info; +#pragma pack(pop) + info.dwType = 0x1000; + info.szName = name; + info.dwThreadID = (DWORD) -1; + info.dwFlags = 0; + __try { + RaiseException( + 0x406D1388, 0, sizeof info / sizeof (ULONG_PTR), + (ULONG_PTR *) &info); + } __except (EXCEPTION_EXECUTE_HANDLER) {} +#else + (void) name; +#endif +} + typedef struct _TLS { DWORD dwIndex; diff --git a/sal/prj/build.lst b/sal/prj/build.lst index 06e3958443e9..b7786f604eaf 100644 --- a/sal/prj/build.lst +++ b/sal/prj/build.lst @@ -20,4 +20,5 @@ sa sal\qa\OStringBuffer nmake - all sa_qa_OStringBuffer sa_cppunittester sa_util sa sal\qa\osl\mutex nmake - all sa_qa_osl_mutex sa_cppunittester sa_util NULL sa sal\qa\osl\pipe nmake - all sa_qa_osl_pipe sa_cppunittester sa_util NULL sa sal\qa\osl\profile nmake - all sa_qa_osl_profile sa_cppunittester sa_util NULL +sa sal\qa\osl\setthreadname nmake - all sa_qa_osl_setthreadname sa_cppunittester sa_util NULL sa sal\qa\rtl\math nmake - all sa_qa_rtl_math sa_cppunittester sa_util NULL diff --git a/sal/qa/osl/setthreadname/makefile.mk b/sal/qa/osl/setthreadname/makefile.mk new file mode 100644 index 000000000000..f2d9da15c468 --- /dev/null +++ b/sal/qa/osl/setthreadname/makefile.mk @@ -0,0 +1,57 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2011 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#***********************************************************************/ + +.IF "$(OOO_SUBSEQUENT_TESTS)" == "" +nothing .PHONY: +.ELSE + +PRJ = ..$/..$/.. +PRJNAME = sal +TARGET = qa_osl_setthreadname + +ENABLE_EXCEPTIONS = TRUE + +.INCLUDE: settings.mk + +CFLAGSCXX += $(CPPUNIT_CFLAGS) + +DLLPRE = + +SHL1IMPLIB = i$(SHL1TARGET) +SHL1OBJS = $(SLO)/test-setthreadname.obj +SHL1RPATH = NONE +SHL1STDLIBS = $(CPPUNITLIB) $(SALLIB) +SHL1TARGET = test-setthreadname +SHL1VERSIONMAP = version.map +DEF1NAME = $(SHL1TARGET) + +SLOFILES = $(SHL1OBJS) + +.INCLUDE: target.mk +.INCLUDE: _cppunit.mk + +.END diff --git a/sal/qa/osl/setthreadname/test-setthreadname.cxx b/sal/qa/osl/setthreadname/test-setthreadname.cxx new file mode 100755 index 000000000000..0f0f618395a8 --- /dev/null +++ b/sal/qa/osl/setthreadname/test-setthreadname.cxx @@ -0,0 +1,87 @@ +/************************************************************************* +* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2000, 2011 Oracle and/or its affiliates. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* OpenOffice.org is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* OpenOffice.org is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details +* (a copy is included in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with OpenOffice.org. If not, see +* <http://www.openoffice.org/license.html> +* for a copy of the LGPLv3 License. +* +************************************************************************/ + +#include "precompiled_sal.hxx" +#include "sal/config.h" + +#include <cstdlib> +#include <iostream> +#include <limits> + +#include "boost/noncopyable.hpp" +#include "cppunit/TestAssert.h" +#include "cppunit/TestFixture.h" +#include "cppunit/extensions/HelperMacros.h" +#include "cppunit/plugin/TestPlugIn.h" +#include "osl/thread.hxx" + +namespace { + +class TestThread: public osl::Thread, private boost::noncopyable { +private: + virtual void SAL_CALL run(); +}; + +void TestThread::run() { +#if defined WNT + if (std::getenv("URE_TEST_SETTHREADNAME") != 0) { + // On Windows, setting thread names appears to only take effect when the + // process is being debugged, so attach a debugger now: + std::cout << "set: "; + std::cin.ignore(std::numeric_limits< int >::max(), '\n'); + } +#endif + setName("TestThread"); + if (std::getenv("URE_TEST_SETTHREADNAME") != 0) { + // On Linux, the thread name can now be observed with "ps -L"; on + // Windows with the Microsoft compiler, the thread name can now be + // observed in a debugger. + std::cout << "stop: "; + std::cin.ignore(std::numeric_limits< int >::max(), '\n'); + } +} + +class Test: public CppUnit::TestFixture { +private: + CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST(test); + CPPUNIT_TEST_SUITE_END(); + + void test(); +}; + +void Test::test() { + TestThread t; + t.create(); + t.join(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(Test); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sal/qa/osl/setthreadname/version.map b/sal/qa/osl/setthreadname/version.map new file mode 100644 index 000000000000..ef2ab497cb5e --- /dev/null +++ b/sal/qa/osl/setthreadname/version.map @@ -0,0 +1,34 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2011 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#***********************************************************************/ + +UDK_3_0_0 { + global: + cppunitTestPlugIn; + + local: + *; +}; diff --git a/sal/util/sal.map b/sal/util/sal.map index 8b1c079ec899..73ae4431100e 100755 --- a/sal/util/sal.map +++ b/sal/util/sal.map @@ -602,6 +602,7 @@ UDK_3.11 { # OOo 3.4 global: osl_setEnvironment; osl_clearEnvironment; + osl_setThreadName; } UDK_3.10; PRIVATE_1.0 { |