EpcTools
An event based multi-threaded C++ development framework.
etbasic.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2019 Sprint
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 
17 #ifndef __ETBASIC_H
18 #define __ETBASIC_H
19 
20 #include "ebase.h"
21 #include "eerror.h"
22 #include "esynch.h"
23 
26 
28 {
29 };
30 
32 {
33 public:
35 };
36 
39 
41 
42 typedef list<EThreadBasic *> EThreadPtrList;
43 
54 {
55  friend class EThreadBase;
56  friend class EpcTools;
57 
58 public:
60  enum RunState
61  {
67  rsDoneRunning
68  };
69 
71  EThreadBasic();
73  virtual ~EThreadBasic();
74 
83  virtual Dword threadProc(pVoid arg) = 0;
84 
97  Void init(pVoid arg, size_t stackSize = 0);
107  Void join();
108 
114  static Void sleep(Int milliseconds);
122  static Void yield();
123 
131  Bool isInitialized();
132 
140  RunState getRunState() { return m_state; }
141 
150  Bool isWaitingToRun() { return m_state == EThreadBasic::rsWaitingToRun; }
159  Bool isRunning() { return m_state == EThreadBasic::rsRunning; }
168  Bool isDoneRunning() { return m_state == EThreadBasic::rsDoneRunning; }
169 
180  Int cancelWait();
181 
183  Void signal(Int sig) { pthread_kill(m_thread, sig); }
184 
185 protected:
187  static Void Initialize();
189  static Void UnInitialize();
190 
191 private:
192  Bool m_initialized;
193  pthread_t m_thread;
194  static pVoid _threadProc(pVoid arg);
195  static EThreadBasic *findCurrentThread();
196  static EThreadPtrList m_thrdCtl;
197  static EMutexPrivate m_thrdCtlMutex;
198 
199  Void _shutdown();
200 
201  EMutexPrivate m_mutex;
202  RunState m_state;
203  pVoid m_arg;
204  Dword m_exitCode;
205 };
206 
207 #endif // #ifndef __ETBASIC_H
Definition: etbasic.h:31
Bool isWaitingToRun()
Determines if the thread is waiting to run.
Definition: etbasic.h:150
the threadProc has exited and the thread is no longer running
Definition: etbasic.h:67
Macros for various standard C library functions and standard includes.
static Void UnInitialize()
Uninitialize the EpcTools runtime environment.
Definition: ebase.cpp:33
the thread is running
Definition: etbasic.h:65
Bool isDoneRunning()
Determines if the thread has finished running.
Definition: etbasic.h:168
Defines base class for exceptions and declaration helper macros.
Bool isRunning()
Determines if the thread is running.
Definition: etbasic.h:159
An abstract class that represents contains the threadProc() that will be run in a separate thread...
Definition: etbasic.h:53
The base class for exceptions derived from std::exception.
Definition: eerror.h:94
RunState getRunState()
Returns the current thread run state.
Definition: etbasic.h:140
A private mutex (the mutex data is allocated from either the heap or stack).
Definition: esynch.h:175
The primary class used to initialize/uninitialize EpcTools.
Definition: einternal.h:30
Contains definitions for synchronization objects.
Void signal(Int sig)
Definition: etbasic.h:183
list< EThreadBasic * > EThreadPtrList
Definition: etbasic.h:40
Void Initialize()
Initializes/starts the PFCP stack. This should be called after setting the initial configuration valu...
Definition: epfcp.cpp:120
Definition: etbasic.h:27
the thread is waiting to run
Definition: etbasic.h:63
RunState
EThreadBasic run states.
Definition: etbasic.h:60