15 #include <rofl/common/ciosrv.h>
16 #include <rofl/common/croflexception.h>
17 #include <rofl/common/logging.h>
34 FLAGS_THREAD_IS_RUNNING = 1,
42 cthread() : tid(0), result(0) {};
57 {
return flags.test(FLAGS_THREAD_IS_RUNNING); };
63 set_thread_id(pthread_t tid) { this->tid = tid; };
69 get_thread_id()
const {
return tid; };
75 set_result(
int result) { this->result = result; };
81 get_result()
const {
return result; };
101 start(
const pthread_attr_t* attr = (
const pthread_attr_t*)0) {
102 rofl::logging::debug2 <<
"[rofl-common][cthread][start_thread] create" << std::endl;
103 int rc = pthread_create(&tid, attr, cthread::run_thread, (
void*)
this);
104 rofl::logging::debug2 <<
"[rofl-common][cthread][start_thread] create done tid: 0x" << tid << std::endl;
112 throw eRofThreadFailed(
"cthread::start_thread() invalid thread attributes");
122 flags.set(FLAGS_THREAD_IS_RUNNING);
131 rofl::logging::debug2 <<
"[rofl-common][cthread][stop_thread] stop cioloop tid: 0x" << tid << std::endl;
133 rofl::logging::debug2 <<
"[rofl-common][cthread][stop_thread] join tid: 0x" << tid << std::endl;
136 int rc = pthread_join(tid, &retval);
137 rofl::logging::debug2 <<
"[rofl-common][cthread][stop_thread] join done tid: 0x" << tid << std::endl;
145 throw eRofThreadFailed(
"cthread::stop_thread() -join- thread not joinable");
160 flags.reset(FLAGS_THREAD_IS_RUNNING);
169 run_thread(
void* arg) {
171 thread.set_thread_id(pthread_self());
173 thread.init_thread();
177 return (
void*)&(thread.get_result());
182 std::bitset<32> flags;
void stop()
Terminates cioloop instance running in thread identified by this->tid.
Definition: ciosrv.h:93
static cioloop & get_loop(pthread_t tid=0)
Returns reference to cioloop instance identified by thread id or if none is specified, cioloop of local thread.
Definition: ciosrv.h:57
static void drop_loop(pthread_t tid)
Drop.
Definition: ciosrv.h:71
Definition: croflexception.h:27