InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
CIdleTaskThread.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Shawn Sheridan
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // Copyright 1997-2010 Adobe Systems Incorporated. All rights reserved.
16 //
17 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
18 // with the terms of the Adobe license agreement accompanying it. If you have received
19 // this file from a source other than Adobe, then your use, modification, or
20 // distribution of it requires the prior written permission of Adobe.
21 //
22 //========================================================================================
23 
24 #ifndef __IdleTaskThread__
25 #define __IdleTaskThread__
26 
27 #include "IIdleTaskThread.h"
28 #include "HelperInterface.h"
29 #ifdef MACINTOSH
30 # include <CoreServices/CoreServices.h>
31 #endif
32 
33 // forward declares
34 class IExecutionContext;
35 
36 
96 namespace idt_syncprimitives{
97 class CIdleTaskThreadSyncPrimitives;
98 }
100 {
101 public:
105  ~CIdleTaskThread();
106 
107  /*
108  YieldToEventLoop() will OR in this flag to the returned appflags when it
109  needs the Thread to return from its RunThread() method. This can be useful
110  for those Threads that normally never return and simply yield within an
111  endless loop. When the Thread is forcibly Uninstalled() the CIdleTaskThread
112  will call RunTask() one more time and expects the Thread to return.
113  */
114  const static uint32 kCITT_Shutdown = 0x80000000;
115 
117  virtual uint32 RunTask( uint32 schedulerFlags, IdleTimer* timeCheck);
118 
120  virtual void InstallTask(uint32 millisecsBeforeFirstRun);
121 
123  virtual void UninstallTask();
124 
126  virtual const char* TaskName() = 0;
127 
129  uint32 YieldToEventLoop(uint32 millisecSleep = 0);
130 
138  virtual bool16 IsShuttingDown() const
139  { return ((fFlags & kCITT_Shutdown) != 0); }
140 
149 
150 private:
156  virtual void RunThread(uint32 flags) = 0;
157 
162  virtual uint32 StackSize();
163 
164 private:
165 #if MACINTOSH
166  typedef ThreadID ThreadHandle;
167  ThreadEntryUPP entryPoint;
168 #elif WINDOWS
169  typedef LPVOID ThreadHandle;
170 #elif WASM
171  typedef int32 ThreadHandle;
172 #else
173 # error CIdleTaskThread unimplemented
174 #endif
175  static const ThreadHandle kInvalidThreadHandle;
176  ThreadHandle fThisThread;
177  K2Vector<ThreadHandle> fParentThread; //can I use stack<ThreadHandle, K2Vector<ThreadHandle> > here?
178 
179  uint32 fSleep; //when this becomes kEndOfTime thread is done
180  uint32 fFlags; //set every time RunTask is called, i.e. every time YieldToEventLoop returns
181  IdleTimer* fTimeCheck;
182  //fState is for sanity checking--could make kFinished == kConstructed call it say kUninstalled
183  //hmm is kInstalled the same as kYielding? Not yet, see UninstallTask
184  enum { kConstructed, kInstalled, kRunning, kYielding, kFinished, kDestroyed, kProcessingMainThreadTasks} fState;
185 
186  IIdleTaskThread::Task fMainThreadTask;
187 
188  void SwitchToChildThread();
189  void SwitchToParentThread();
190 
191  static void private_FiberFunction( CIdleTaskThread* theTask);
192 #ifdef MACINTOSH
193  static DEFINE_API(void *) FiberEntryPoint( void * cookie);
194 #elif WASM
195  static void * FiberEntryPoint( void * cookie);
196 #else
197  static VOID CALLBACK CIdleTaskThread::FiberEntryPoint( PVOID cookie);
198 #endif
199 
200  // For private use only.
201  void FiberEntryPointNoReturn(void* cookie);
202 
203  idt_syncprimitives::CIdleTaskThreadSyncPrimitives* fSyncPrimitives;
204 
205 };
206 
207 
208 #endif // __IdleTaskThread__