fix build
[LibreOffice.git] / include / salhelper / thread.hxx
blobdaea7f352b83fbeabba9a05dde3903175d9e3a74
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 */
11 * This file is part of LibreOffice published API.
14 #ifndef INCLUDED_SALHELPER_THREAD_HXX
15 #define INCLUDED_SALHELPER_THREAD_HXX
17 #include "sal/config.h"
19 #include <cstddef>
21 #include "osl/thread.hxx"
22 #include "sal/types.h"
23 #include "salhelper/salhelperdllapi.h"
24 #include "salhelper/simplereferenceobject.hxx"
26 namespace salhelper
28 /**
29 A safe encapsulation of ::osl::Thread.
31 @since LibreOffice 3.6
33 class SALHELPER_DLLPUBLIC Thread : public salhelper::SimpleReferenceObject, private osl::Thread
35 public:
36 /**
37 @param name the thread name, see ::osl_setThreadName; must be a non-null
38 null terminated string
40 Thread(char const* name);
42 /**
43 Launch the thread.
45 This function must be called at most once.
47 Each call of this function should eventually be followed by a call to
48 ::osl::Thread::join before exit(3), to ensure the thread is no longer
49 relying on any infrastructure while that infrastructure is being shut
50 down in atexit handlers.
52 void launch();
54 using osl::Thread::getIdentifier;
55 using osl::Thread::join;
56 using osl::Thread::schedule;
57 using osl::Thread::terminate;
59 // While the below static member functions should arguably always be called
60 // with qualified (osl::Thread) names, compilers would still complain that
61 // they are inaccessible from within derivations of salhelper::Thread (an
62 // alternative would be to force such derivations to use global names,
63 // prefixed with ::osl::Thread):
64 using osl::Thread::getCurrentIdentifier;
65 using osl::Thread::wait;
66 using osl::Thread::yield;
68 static void* operator new(std::size_t size)
70 return SimpleReferenceObject::operator new(size);
73 static void operator delete(void* pointer) { SimpleReferenceObject::operator delete(pointer); }
75 protected:
76 virtual ~Thread() SAL_OVERRIDE;
78 /**
79 The main function executed by the thread.
81 Any uncaught exceptions lead to std::terminate.
83 virtual void execute() = 0;
85 private:
86 virtual void SAL_CALL run() SAL_OVERRIDE;
88 virtual void SAL_CALL onTerminated() SAL_OVERRIDE;
90 char const* name_;
94 #endif
96 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */