HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_ThreadedIO.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_ThreadedIO.h ( UT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __UT_ThreadedIO__
12 #define __UT_ThreadedIO__
13 
14 #include "UT_API.h"
15 
16 #include "UT_Thread.h"
17 #include "UT_ThreadQueue.h"
18 
19 class UT_ThreadedIOTask;
20 
21 ///
22 /// UT_ThreadedIO__ takes care of all the thread administration that
23 /// threaded io requires.
24 ///
25 /// Its features are to maintain single global IO thread
26 /// to which all desired write jobs are posted.
27 ///
29 {
30 public:
31  UT_ThreadedIO(exint maxqueuebytes);
32  ~UT_ThreadedIO();
33 
34  /// Blocks until next IO task is done. Returns the number of
35  /// tasks left.
36  /// Will return immediatenly if no active or pending tasks.
37  int awaitIOTaskDone();
38 
39  /// Current task count. Includes those blocking waiting to
40  /// be added. Includes those still processing.
41  int numTasks() const;
42 
43  /// Adds the task to the IO queue.
44  /// This will block until there is enough free space
45  /// on the queue.
46  void postTask(UT_ThreadedIOTask *task);
47 
48 private:
49  static void *threadCB(void *data);
50  void exec();
51 
53  UT_Thread *myIOThread;
54 
55  SYS_AtomicInt32 myTaskCount;
56 
57 };
58 
59 ///
60 /// IO tasks should be subclassed from this.
61 /// Your destructor will be called on the io thread!
62 ///
64 {
65 public:
67  virtual ~UT_ThreadedIOTask() {}
68 
69  /// This is invoked when it is your turn to write.
70  /// when you exit from this, your task will be destructed.
71  virtual void doWrite() = 0;
72 
73  /// A rough estimate of the number of bytes of RAM are
74  /// lost by waiting for this task to finish. This avoids
75  /// us spooling up too much and swapping.
76  virtual exint memoryEstimate() const = 0;
77 };
78 
80 
81 
82 #endif
virtual ~UT_ThreadedIOTask()
Definition: UT_ThreadedIO.h:67
#define UT_API
Definition: UT_API.h:12
int64 exint
Definition: SYS_Types.h:109
GLboolean * data
Definition: glcorearb.h:130
UT_API UT_ThreadedIO * UTgetIOThread()