Free Electron
Thread.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __platform_thread_h__
8 #define __platform_thread_h__
9 
10 namespace fe
11 {
12 
13 /*
14  boost::thread_group* m_pGroup;
15  boost::thread** m_ppThread;
16 
17  a_threads=boost::thread::hardware_concurrency();
18 
19  m_pGroup=new boost::thread_group();
20  m_ppWorker=new WORKER*[a_threads];
21  m_ppThread=new boost::thread*[a_threads];
22 
23  m_ppThread[m]=m_pGroup->create_thread(
24  *m_ppWorker[m]);
25  m_ppThread[n]->interrupt();
26  m_pGroup->join_all();
27  m_pGroup->remove_thread(m_ppThread[m]);
28 
29  boost::this_thread::interruption_point();
30 
31  boost::thread_specific_ptr< Array< sp<T> > >* m_pTssArray;
32 
33  Array< sp<T> >* pArray;
34  if(!(pArray=m_pTssArray->get()))
35  {
36  pArray=new Array< sp<T> >();
37  m_pTssArray->reset(pArray);
38 */
39 
40 extern "C"
41 {
42 
43 typedef void* (FE_CDECL ThreadDefaultInitFunction)(void);
44 typedef void* (FE_CDECL ThreadInitFunction)(void* a_pFunctor);
45 typedef bool (FE_CDECL ThreadConfigFunction)(void* a_pRawThread,String a_property,String a_value);
46 typedef void (FE_CDECL ThreadInterruptFunction)(void* a_pRawThread);
47 typedef void (FE_CDECL ThreadJoinFunction)(void* a_pRawThread);
48 typedef bool (FE_CDECL ThreadJoinableFunction)(void* a_pRawThread);
49 typedef void (FE_CDECL ThreadFinishFunction)(void* a_pRawThread);
50 typedef void (FE_CDECL ThreadInterruptionFunction)(void);
51 typedef int (FE_CDECL ThreadConcurrencyFunction)(void);
52 
53 typedef void* (FE_CDECL ThreadGroupInitFunction)(void);
54 typedef void* (FE_CDECL ThreadGroupCreateFunction)(
55  void* a_pRawThreadGroup,void* a_pFunctor);
56 typedef void (FE_CDECL ThreadGroupJoinAllFunction)(void* a_pRawThreadGroup);
57 typedef void (FE_CDECL ThreadGroupFinishFunction)(void* a_pRawThreadGroup);
58 
59 } /* extern "C" */
60 
61 FE_MEM_PORT extern ThreadDefaultInitFunction* gs_fnThreadDefaultInit;
62 FE_MEM_PORT extern ThreadInitFunction* gs_fnThreadInit;
63 FE_MEM_PORT extern ThreadConfigFunction* gs_fnThreadConfig;
64 FE_MEM_PORT extern ThreadInterruptFunction* gs_fnThreadInterrupt;
65 FE_MEM_PORT extern ThreadJoinFunction* gs_fnThreadJoin;
66 FE_MEM_PORT extern ThreadJoinableFunction* gs_fnThreadJoinable;
67 FE_MEM_PORT extern ThreadFinishFunction* gs_fnThreadFinish;
68 FE_MEM_PORT extern ThreadInterruptionFunction* gs_fnThreadInterruption;
69 FE_MEM_PORT extern ThreadConcurrencyFunction* gs_fnThreadConcurrency;
70 
71 FE_MEM_PORT extern ThreadGroupInitFunction* gs_fnThreadGroupInit;
72 FE_MEM_PORT extern ThreadGroupCreateFunction* gs_fnThreadGroupCreate;
73 FE_MEM_PORT extern ThreadGroupJoinAllFunction* gs_fnThreadGroupJoinAll;
74 FE_MEM_PORT extern ThreadGroupFinishFunction* gs_fnThreadGroupFinish;
75 
76 FE_MEM_PORT extern String gs_threadSupport;
77 FE_MEM_PORT extern BWORD gs_threadChecked;
78 FE_MEM_PORT extern DL_Loader* gs_pThreadLoader;
79 
80 class FE_DL_PUBLIC FE_DL_EXPORT Thread
81 {
82  public:
83 
84  class FE_DL_PUBLIC FE_DL_EXPORT Functor
85  {
86  public:
87  Functor(void);
88  virtual ~Functor(void);
89  virtual void operate(void);
90 
91  void operator()(void);
92 
93  protected:
94  Functor* m_pOriginal; //* operator() 'this' may be different
95  };
96 
97  class FE_DL_PUBLIC FE_DL_EXPORT Group
98  {
99  public:
100  Group(void);
101  ~Group(void);
102 
103  Thread* createThread(Functor* a_pFunctor);
104  BWORD joinAll(void);
105 
106  private:
107 
108  void* m_pRawThreadGroup;
109  };
110 
111  Thread(void);
112  Thread(Functor* a_pFunctor);
113  Thread(void* a_pRawThread);
114  ~Thread(void);
115 
116  BWORD config(String a_property,String a_value);
117  BWORD interrupt(void);
118  BWORD join(void);
119  BWORD joinable(void);
120 
121 static BWORD interruptionPoint(void);
122 static I32 hardwareConcurrency(void);
123 static String support(void) { return gs_threadSupport; }
124 
125 static void replaceDefaultInitFunction(
126  ThreadDefaultInitFunction* a_fnDefaultInit)
127  { gs_fnThreadDefaultInit=a_fnDefaultInit; }
128 static void replaceInitFunction(
129  ThreadInitFunction* a_fnInit)
130  { gs_fnThreadInit=a_fnInit; }
131 static void replaceConfigFunction(
132  ThreadConfigFunction* a_fnConfig)
133  { gs_fnThreadConfig=a_fnConfig; }
134 static void replaceInterruptFunction(
135  ThreadInterruptFunction* a_fnInterrupt)
136  { gs_fnThreadInterrupt=a_fnInterrupt; }
137 static void replaceJoinFunction(
138  ThreadJoinFunction* a_fnJoin)
139  { gs_fnThreadJoin=a_fnJoin; }
140 static void replaceJoinableFunction(
141  ThreadJoinableFunction* a_fnJoinable)
142  { gs_fnThreadJoinable=a_fnJoinable; }
143 static void replaceFinishFunction(
144  ThreadFinishFunction* a_fnFinish)
145  { gs_fnThreadFinish=a_fnFinish; }
146 static void replaceInterruptionFunction(
147  ThreadInterruptionFunction* a_fnInterruption)
148  { gs_fnThreadInterruption=a_fnInterruption; }
149 static void replaceConcurrencyFunction(
150  ThreadConcurrencyFunction* a_fnConcurrency)
151  { gs_fnThreadConcurrency=a_fnConcurrency; }
152 
153 static void replaceGroupInitFunction(
154  ThreadGroupInitFunction* a_fnGroupInit)
155  { gs_fnThreadGroupInit=a_fnGroupInit; }
156 static void replaceGroupCreateFunction(
157  ThreadGroupCreateFunction* a_fnGroupCreate)
158  { gs_fnThreadGroupCreate=a_fnGroupCreate; }
159 static void replaceGroupJoinAllFunction(
160  ThreadGroupJoinAllFunction* a_fnGroupJoinAll)
161  { gs_fnThreadGroupJoinAll=a_fnGroupJoinAll; }
162 static void replaceGroupFinishFunction(
163  ThreadGroupFinishFunction* a_fnGroupFinish)
164  { gs_fnThreadGroupFinish=a_fnGroupFinish; }
165 
166 static BWORD clearFunctionPointers(void);
167 static BWORD dismiss(void);
168 
169  private:
170 
171 static BWORD confirm(void);
172 
173  void* m_pRawThread;
174 };
175 
176 } /* namespace */
177 
178 #endif /* __platform_thread_h__ */
kernel
Definition: namespace.dox:3