-
Notifications
You must be signed in to change notification settings - Fork 0
/
thread.h
50 lines (44 loc) · 1.22 KB
/
thread.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* @file thread.h
* @version 1.0
* @brief MP3enc_cpp thread module header
* @date Mar 4, 2020
* @author Siwon Kang (kkangshawn@gmail.com)
*/
#ifndef _THREAD_H
#define _THREAD_H
#include <pthread.h>
/**
* @class Thread thread.h "thread.h"
*
* @brief Thread class using pthread library.
* This class is supposed to be used by other classes inherit this
* , override run() function then call start() and join() from instance.
*/
class Thread {
public:
Thread() : m_thread{}, m_is_running(false) {}
/**
* @fn void start()
* @brief start a thread binding a function specified by run() via pthread_create()
*/
void start();
/**
* @fn void join()
* @brief join a thread binding a function specified by run() via pthread_create()
*/
void join();
private:
/**
* @fn virtual void run()
* @brief A function to bind thread
*/
virtual void run() {}
static void* run_(void* p) {
((Thread*)p)->run();
return NULL;
}
pthread_t m_thread; /**< thread handle */
bool m_is_running; /**< state variable to check thread is running */
};
#endif /* _THREAD_H */