cgv
Loading...
Searching...
No Matches
thread.h
1#pragma once
2
3#include "mutex.h"
4#include <iostream>
5
6#include "lib_begin.h"
7
8namespace cgv {
9 namespace os {
10
12typedef unsigned long long thread_id_type;
13
38class CGV_API thread
39{
40protected:
41 void *thread_ptr;
42 bool stop_request;
43 bool running;
44 bool delete_after_termination;
45 static void* execute_s(void* args);
47 void execute();
48public:
50 thread();
52 virtual ~thread();
54 void start(bool _delete_after_termination = false);
56 virtual void run()=0;
58 static void wait_for_signal(condition_mutex& cm);
60 static void wait_for_signal_with_lock(condition_mutex& cm);
62 static bool wait_for_signal_or_timeout(condition_mutex& cm, unsigned millisec);
64 static bool wait_for_signal_or_timeout_with_lock(condition_mutex& cm, unsigned millisec);
66 static void wait(unsigned millisec);
70 void stop();
72 void kill();
75 void wait_for_completion();
77 inline bool is_running() { return running; }
79 inline bool have_stop_request() { return stop_request; }
81 static thread_id_type get_current_thread_id();
83 thread_id_type get_id() const;
84};
85
87extern CGV_API thread* start_in_thread(void (*func)(thread_id_type), bool _delete_after_termination = false);
88
89 }
90}
91
92#include <cgv/config/lib_end.h>
Thread class implementation that uses pthreads internally.
Definition thread.h:39
virtual void run()=0
thread function to override
bool is_running()
return true if thread is running
Definition thread.h:77
bool have_stop_request()
check if there is a stop request
Definition thread.h:79
the cgv namespace
Definition print.h:11
A mutex that can wake up other threads by signals sent when a condition is fulfilled.
Definition mutex.h:42