mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-27 17:28:41 +00:00
Remove threads.h and replace its definitions with their C++11 equivalents (#5957)
This also changes threadProc's signature, since C++11 supports arbitrary thread function signatures.
This commit is contained in:
parent
5cc8ad946e
commit
6c5e5e2023
16 changed files with 82 additions and 160 deletions
|
@ -26,10 +26,10 @@ DEALINGS IN THE SOFTWARE.
|
|||
#pragma once
|
||||
|
||||
#include "util/basic_macros.h"
|
||||
#include "threads.h"
|
||||
|
||||
#include <string>
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
|
||||
#ifdef _AIX
|
||||
|
@ -49,10 +49,12 @@ DEALINGS IN THE SOFTWARE.
|
|||
#endif
|
||||
|
||||
|
||||
|
||||
class Thread {
|
||||
public:
|
||||
Thread(const std::string &name="");
|
||||
virtual ~Thread();
|
||||
DISABLE_CLASS_COPY(Thread)
|
||||
|
||||
/*
|
||||
* Begins execution of a new thread at the pure virtual method Thread::run().
|
||||
|
@ -87,13 +89,12 @@ public:
|
|||
/*
|
||||
* Returns true if the calling thread is this Thread object.
|
||||
*/
|
||||
bool isCurrentThread() { return thr_is_current_thread(getThreadId()); }
|
||||
bool isCurrentThread() { return std::this_thread::get_id() == getThreadId(); }
|
||||
|
||||
inline bool isRunning() { return m_running; }
|
||||
inline bool stopRequested() { return m_request_stop; }
|
||||
bool isRunning() { return m_running; }
|
||||
bool stopRequested() { return m_request_stop; }
|
||||
|
||||
inline threadid_t getThreadId() { return m_thread_obj->get_id(); }
|
||||
inline threadhandle_t getThreadHandle() { return m_thread_obj->native_handle(); }
|
||||
std::thread::id getThreadId() { return m_thread_obj->get_id(); }
|
||||
|
||||
/*
|
||||
* Gets the thread return value.
|
||||
|
@ -139,6 +140,11 @@ protected:
|
|||
virtual void *run() = 0;
|
||||
|
||||
private:
|
||||
std::thread::native_handle_type getThreadHandle()
|
||||
{ return m_thread_obj->native_handle(); }
|
||||
|
||||
static void threadProc(Thread *thr);
|
||||
|
||||
void *m_retval;
|
||||
bool m_joinable;
|
||||
std::atomic<bool> m_request_stop;
|
||||
|
@ -148,13 +154,11 @@ private:
|
|||
|
||||
std::thread *m_thread_obj;
|
||||
|
||||
static ThreadStartFunc threadProc;
|
||||
|
||||
#ifdef _AIX
|
||||
// For AIX, there does not exist any mapping from pthread_t to tid_t
|
||||
// available to us, so we maintain one ourselves. This is set on thread start.
|
||||
tid_t m_kernel_thread_id;
|
||||
#endif
|
||||
Thread(const Thread &) = delete;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue