LibreOffice
LibreOffice 7.1 SDK C/C++ API Reference
thread.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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  */
9 
10 #ifndef INCLUDED_SALHELPER_THREAD_HXX
11 #define INCLUDED_SALHELPER_THREAD_HXX
12 
13 #include "sal/config.h"
14 
15 #include <cstddef>
16 
17 #include "osl/thread.hxx"
18 #include "sal/types.h"
21 
22 namespace salhelper
23 {
30 {
31 public:
36  Thread(char const* name);
37 
48  void launch();
49 
51  using osl::Thread::join;
54 
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):
61  using osl::Thread::wait;
62  using osl::Thread::yield;
63 
64  static void* operator new(std::size_t size)
65  {
66  return SimpleReferenceObject::operator new(size);
67  }
68 
69  static void operator delete(void* pointer) { SimpleReferenceObject::operator delete(pointer); }
70 
71 protected:
72  virtual ~Thread() SAL_OVERRIDE;
73 
79  virtual void execute() = 0;
80 
81 private:
82  virtual void SAL_CALL run() SAL_OVERRIDE;
83 
84  virtual void SAL_CALL onTerminated() SAL_OVERRIDE;
85 
86  char const* name_;
87 };
88 }
89 
90 #endif
91 
92 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define SAL_OVERRIDE
C++11 "override" feature.
Definition: types.h:387
#define SALHELPER_DLLPUBLIC
Definition: salhelperdllapi.h:28
Definition: condition.hxx:31
A simple base implementation for reference-counted objects.
Definition: simplereferenceobject.hxx:58
A safe encapsulation of osl::Thread.
Definition: thread.hxx:30
Thread(char const *name)
virtual ~Thread() SAL_OVERRIDE
void launch()
Launch the thread.
A thread abstraction.
Definition: thread.hxx:49
oslThreadIdentifier getIdentifier() const
Definition: thread.hxx:131
static oslThreadIdentifier getCurrentIdentifier()
Definition: thread.hxx:136
static void yield()
Definition: thread.hxx:146
virtual bool schedule()
Definition: thread.hxx:155
virtual void join()
Definition: thread.hxx:110
static void wait(const TimeValue &Delay)
Definition: thread.hxx:141
virtual void terminate()
Definition: thread.hxx:104