nss: upgrade to release 3.73
[LibreOffice.git] / include / salhelper / thread.hxx
blob70172a313b35ad53e733c8d194dfa27aab6247d6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #ifndef INCLUDED_SALHELPER_THREAD_HXX
11 #define INCLUDED_SALHELPER_THREAD_HXX
13 #include "sal/config.h"
15 #include <cstddef>
17 #include "osl/thread.hxx"
18 #include "sal/types.h"
19 #include "salhelper/salhelperdllapi.h"
20 #include "salhelper/simplereferenceobject.hxx"
22 namespace salhelper
24 /**
25 A safe encapsulation of ::osl::Thread.
27 @since LibreOffice 3.6
29 class SALHELPER_DLLPUBLIC Thread : public salhelper::SimpleReferenceObject, private osl::Thread
31 public:
32 /**
33 @param name the thread name, see ::osl_setThreadName; must be a non-null
34 null terminated string
36 Thread(char const* name);
38 /**
39 Launch the thread.
41 This function must be called at most once.
43 Each call of this function should eventually be followed by a call to
44 ::osl::Thread::join before exit(3), to ensure the thread is no longer
45 relying on any infrastructure while that infrastructure is being shut
46 down in atexit handlers.
48 void launch();
50 using osl::Thread::getIdentifier;
51 using osl::Thread::join;
52 using osl::Thread::schedule;
53 using osl::Thread::terminate;
55 // While the below static member functions should arguably always be called
56 // with qualified (osl::Thread) names, compilers would still complain that
57 // they are inaccessible from within derivations of salhelper::Thread (an
58 // alternative would be to force such derivations to use global names,
59 // prefixed with ::osl::Thread):
60 using osl::Thread::getCurrentIdentifier;
61 using osl::Thread::wait;
62 using osl::Thread::yield;
64 static void* operator new(std::size_t size)
66 return SimpleReferenceObject::operator new(size);
69 static void operator delete(void* pointer) { SimpleReferenceObject::operator delete(pointer); }
71 protected:
72 virtual ~Thread() SAL_OVERRIDE;
74 /**
75 The main function executed by the thread.
77 Any uncaught exceptions lead to std::terminate.
79 virtual void execute() = 0;
81 private:
82 virtual void SAL_CALL run() SAL_OVERRIDE;
84 virtual void SAL_CALL onTerminated() SAL_OVERRIDE;
86 char const* name_;
90 #endif
92 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */