Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Thread.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/basic.h>
35 #include <ogdf/basic/memory.h>
36 
37 #include <thread>
38 
39 namespace ogdf {
40 
42 
53 class Thread : public std::thread {
54 public:
55  Thread() : thread() { }
56 
57  Thread(Thread&& other) : thread(std::move((thread &&) other)) { }
58 
59  // Visual C++ 2013 Preview cannot compile that combination of variadic templates and lambda function (though it should).
60  // Therefore we use the version without function arguments for MSVC untils this works.
61 #ifdef _MSC_VER
62  template<class Function>
63  explicit Thread(Function&& f)
64  : thread([&] {
65  f();
66  OGDF_ALLOCATOR::flushPool();
67  }) { }
68 
69 #else
70  template<class Function, class... Args>
71  explicit Thread(Function&& f, Args&&... args)
72  : thread(
73  [&](Args&&... tArgs) {
74  f(std::forward<Args>(tArgs)...);
75  OGDF_ALLOCATOR::flushPool();
76  },
77  std::forward<Args>(args)...) { }
78 #endif
79 
80  Thread& operator=(Thread&& other) {
81  thread::operator=(std::move((thread &&) other));
82  return *this;
83  }
84 };
85 
86 }
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::Thread::Thread
Thread(Thread &&other)
Definition: Thread.h:57
backward::details::move
const T & move(const T &v)
Definition: backward.hpp:243
basic.h
Basic declarations, included by all source files.
std
Definition: GML.h:110
ogdf::Thread::operator=
Thread & operator=(Thread &&other)
Definition: Thread.h:80
ogdf::Thread
Threads supporting OGDF's memory management.
Definition: Thread.h:53
ogdf::Thread::Thread
Thread(Function &&f, Args &&... args)
Definition: Thread.h:71
memory.h
Declaration of memory manager for allocating small pieces of memory.
ogdf::Thread::Thread
Thread()
Definition: Thread.h:55