libpandac  0.0.0
A library designed for a comm.ai Panda.
thread.h
1 /******************************************************************************
2  * *
3  * Copyright (C) 2016 Mogi, LLC - All Rights Reserved *
4  * Author: Matt Bunting *
5  * *
6  * Proprietary and confidential. *
7  * *
8  * Unauthorized copying of this file via any medium is strictly prohibited *
9  * without the explicit permission of Mogi, LLC. *
10  * *
11  * See license in root directory for terms. *
12  * http://www.binpress.com/license/view/l/0088eb4b29b2fcff36e42134b0949f93 *
13  * *
14  *****************************************************************************/
15 
16 #ifndef MOGI_THREAD_H
17 #define MOGI_THREAD_H
18 
19 #include <pthread.h>
20 
21 namespace Mogi {
22 
27 class Thread {
28 public:
29  Thread();
30  virtual ~Thread() = 0;
31 
37  bool start();
38 
41  void stop();
42 
46 
53  int lock();
54 
60  int unlock();
61 
65  void pause();
66 
70  void resume();
71 
75  bool running() {
76  return isRunning;
77  }
78 
79 protected:
84  virtual void entryAction();
85 
91  virtual void doAction();
92 
97  virtual void exitAction();
98 
101  void checkSuspend();
102 
103 private:
104  static void* InternalThreadEntryFunc(void* This);
105 
106  pthread_t _thread;
107  pthread_mutex_t _mutex;
108  pthread_mutex_t _condMutex;
109  pthread_cond_t _cond;
110 
111  bool pauseFlag;
112  // bool killable;
113  bool isRunning;
114  bool shouldTerminate;
115 };
116 }
117 
118 #endif
bool start()
Starts the internal thread method.
bool running()
Returns the state of the thread.
Definition: thread.h:75
void resume()
Resumes the thread from a pause.
int unlock()
Performs a mutual exclusion unlock. Will allow other threads that have been locked to resume...
virtual void exitAction()
Called once when thread is commanded to stop.
int lock()
Performs a mutual exclusion lock. Will halt if locked by another thread, and will resume when the oth...
Abstract class, handles a single thread. Features mutual exclusion and pause/resume.
Definition: thread.h:27
void stop()
Stops the internal thread method.
Definition: thread.h:21
void WaitForInternalThreadToExit()
Will wait until the thread has finished.
virtual void doAction()
Continuously called until the thread is commanded to stop.
virtual void entryAction()
Called once at the beginning of the thread running.
void pause()
Performs a pause.
void checkSuspend()
Blocks the thread from a pause() call until resume() is called.