openATV enigma2
openATV is an open source SetTopBox Graphical user interface.
thread.h
Go to the documentation of this file.
1 #ifndef __lib_base_thread_h
2 #define __lib_base_thread_h
3 
4 #include <pthread.h>
5 #include <signal.h>
6 #include <lib/base/elock.h>
7 
8 /* the following states are possible:
9  1 thread has not yet started
10  2 thread has started, but not completed initialization (hadStarted not yet called)
11  3 thread is running
12  4 thread has finished, but not yet joined
13  5 thread has joined (same as state 1)
14 
15  sync() will return:
16  0 (="not alive") for 1, 4, 5
17  1 for 3, 4
18 
19  it will wait when state is 2. It can't differentiate between
20  state 3 and 4, because a thread could always finish.
21 
22  all other state transitions (1 -> 2, 4 -> 5) must be activately
23  changed by either calling run() or kill().
24  */
25 
26 class eThread
27 {
28 public:
29  eThread();
30  virtual ~eThread();
31 
32  /* thread_finished is called from within the thread context as the last function
33  before the thread is going to die.
34  It should be used to do final cleanups (unlock locked mutexes ....) */
35  virtual void thread_finished() {}
36 
37  /* run will wait until the thread has either
38  passed it's initialization, or it has
39  died again. */
40  int run(int prio=0, int policy=0);
41 
42  virtual void thread()=0;
43 
44  int sendSignal(int sig);
45 
46  /* join the thread, i.e. busywait until thread has finnished. */
47  void kill();
48 
49  /* Call pthread_cancel, please don't do this. */
50  void abort_badly() { pthread_cancel(the_thread); }
51 private:
52  pthread_t the_thread;
53 
54  /* waits until thread is in "run" state */
55  /* result: 0 - thread is not alive
56  1 - thread state unknown */
57  int sync();
58  /* runAsync starts the thread.
59  it assumes that the thread is not running,
60  i.e. sync() *must* return 0.
61  it will not wait for anything. */
62  int runAsync(int prio=0, int policy=0);
63  static void *wrapper(void *ptr);
64  int m_alive, m_started;
65  static void thread_completed(void *p);
66 
67  eSemaphore m_state;
68 protected:
69  void hasStarted();
70 };
71 
72 #endif
static int ptr
Definition: bcm.cpp:17
Definition: elock.h:172
Definition: thread.h:27
int sendSignal(int sig)
Definition: thread.cpp:113
eThread()
Definition: thread.cpp:29
int run(int prio=0, int policy=0)
Definition: thread.cpp:82
virtual void thread()=0
void abort_badly()
Definition: thread.h:50
void kill()
Definition: thread.cpp:122
void hasStarted()
Definition: thread.cpp:135
virtual void thread_finished()
Definition: thread.h:35
virtual ~eThread()
Definition: thread.cpp:90
p
Definition: upgrade.py:63