HDK
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
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
#include "
UT_NonCopyable.h
"
16
#include "
UT_Thread.h
"
17
#include "
UT_ThreadQueue.h
"
18
#include "
UT_UniquePtr.h
"
19
20
class
UT_ThreadedIOTask
;
21
22
///
23
/// UT_ThreadedIO__ takes care of all the thread administration that
24
/// threaded io requires.
25
///
26
/// Its features are to maintain single global IO thread
27
/// to which all desired write jobs are posted.
28
///
29
class
UT_API
UT_ThreadedIO
30
{
31
public
:
32
UT_ThreadedIO
(
exint
maxqueuebytes);
33
~
UT_ThreadedIO
();
34
35
UT_NON_COPYABLE
(
UT_ThreadedIO
)
36
37
/// Blocks until next IO task is done. Returns the number of
38
/// tasks left.
39
/// Will return immediatenly if no active or pending tasks.
40
int
awaitIOTaskDone();
41
42
/// Current task count. Includes those blocking waiting to
43
/// be added. Includes those still processing.
44
int
numTasks()
const
;
45
46
/// Adds the task to the IO queue.
47
/// This will block until there is enough free space
48
/// on the queue.
49
void
postTask(
UT_UniquePtr<UT_ThreadedIOTask>
task);
50
51
private
:
52
static
void
*threadCB(
void
*
data
);
53
void
exec();
54
55
UT_ThreadQueue<UT_UniquePtr<UT_ThreadedIOTask>
>
56
myQueue;
57
UT_UniquePtr<UT_Thread>
myIOThread;
58
59
SYS_AtomicInt32
myTaskCount;
60
61
};
62
63
///
64
/// IO tasks should be subclassed from this.
65
/// Your destructor will be called on the io thread!
66
///
67
class
UT_API
UT_ThreadedIOTask
68
{
69
public
:
70
UT_ThreadedIOTask
() {}
71
virtual
~UT_ThreadedIOTask
() {}
72
UT_NON_COPYABLE
(
UT_ThreadedIOTask
)
73
74
/// This is invoked when it is your turn to write.
75
/// when you exit from this, your task will be destructed.
76
virtual
void
doWrite() = 0;
77
78
/// A rough estimate of the number of bytes of RAM are
79
/// lost by waiting for this task to finish. This avoids
80
/// us spooling up too much and swapping.
81
virtual
exint
memoryEstimate()
const
= 0;
82
};
83
84
UT_API
UT_ThreadedIO
*
UTgetIOThread
();
85
86
87
#endif
UT_ThreadedIOTask
Definition:
UT_ThreadedIO.h:67
UT_ThreadedIO
Definition:
UT_ThreadedIO.h:29
exint
int64 exint
Definition:
SYS_Types.h:125
UT_API.h
UT_ThreadedIOTask::~UT_ThreadedIOTask
virtual ~UT_ThreadedIOTask()
Definition:
UT_ThreadedIO.h:71
UT_API
#define UT_API
Definition:
UT_API.h:14
UT_ThreadQueue.h
UT_UniquePtr
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition:
UT_UniquePtr.h:39
UT_NON_COPYABLE
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
Definition:
UT_NonCopyable.h:31
UT_NonCopyable.h
UT_UniquePtr.h
UT_ThreadQueue
Definition:
UT_ThreadQueue.h:29
SYS_AtomicInt< int32 >
const
#define const
Definition:
zconf.h:214
UT_ThreadedIOTask::UT_ThreadedIOTask
UT_ThreadedIOTask()
Definition:
UT_ThreadedIO.h:70
UTgetIOThread
UT_API UT_ThreadedIO * UTgetIOThread()
UT_Thread.h
data
Definition:
format.h:895
UT
UT_ThreadedIO.h
Generated on Thu Mar 28 2024 03:47:50 for HDK by
1.8.6