-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDKThread.h
More file actions
121 lines (81 loc) · 3.48 KB
/
Copy pathDKThread.h
File metadata and controls
121 lines (81 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// =======================================================================================
//
// DKThread.h
// Duck Object Library -- See LICENSE for legal information.
//
// Copyright (c) 2014-2026 Derek W. Nylen
//
// =======================================================================================
#ifndef _DK_THREAD_H_
#define _DK_THREAD_H_
#ifdef __cplusplus
extern "C"
{
#endif
// DKThread ==============================================================================
typedef struct DKThread * DKThreadRef;
typedef void (*DKThreadProc)( void * context );
typedef void (*DKThreadMethod)( DKObjectRef _self, DKObjectRef param );
typedef enum
{
DKThreadCreated = 0,
DKThreadStarted,
DKThreadRunning,
DKThreadCancelled,
DKThreadFinished,
// The thread was not created by DKThread
DKThreadStateUnknown
} DKThreadState;
DK_API DKClassRef DKThreadClass( void );
DK_API DKThreadRef DKThreadGetCurrentThread( void );
DK_API DKThreadRef DKThreadGetMainThread( void );
DK_API void DKDetachNewThread( DKThreadProc proc, void * context );
DK_API void DKDetachNewThreadToTarget( DKObjectRef target, DKThreadMethod method, DKObjectRef param );
DK_API DKObjectRef DKThreadInit( DKObjectRef _self, DKThreadProc proc, void * context );
DK_API DKObjectRef DKThreadInitWithTarget( DKObjectRef _self, DKObjectRef target, DKThreadMethod method, DKObjectRef param );
DK_API void DKThreadSetLabel( DKThreadRef _self, DKStringRef label );
DK_API void DKThreadStart( DKThreadRef _self );
DK_API void DKThreadJoin( DKThreadRef _self );
DK_API void DKThreadCancel( DKThreadRef _self );
DK_API void DKThreadExit( void );
// Get thread information. Unlike most interfaces, if '_self' is NULL, the values
// associated with the current thread are returned.
DK_API DKThreadState DKThreadGetState( DKThreadRef _self );
DK_API bool DKThreadIsMainThread( DKThreadRef _self );
// DKThreadContext =======================================================================
typedef struct DKThreadContext * DKThreadContextRef;
// The main thread and DKThreads manage their own thread contexts. Any threads created
// manually must allocate a DKThreadContext structure and set it before calling any Duck
// functions, and free the DKThreadContext once it is no longer in use.
DK_API DKThreadContextRef DKAllocThreadContext( void );
DK_API void DKFreeThreadContext( DKThreadContextRef threadContext );
// Get/Set the thread context for the current thread
DK_API void DKSetCurrentThreadContext( DKThreadContextRef threadContext );
DK_API bool DKCurrentThreadContextIsSet( void );
DK_API DKThreadContextRef DKGetCurrentThreadContext( void );
// Get the thread context of the main thread
DK_API DKThreadContextRef DKGetMainThreadContext( void );
// Get rhe thread-specific dictionary for the current thread
DK_API DKMutableDictionaryRef DKGetCurrentThreadDictionary( void );
// Private ===============================================================================
#if DK_THREAD_PRIVATE
struct DKThreadContext
{
DKThreadRef threadObject;
DKMutableDictionaryRef threadDictionary;
uint32_t options;
struct
{
DKGenericArray objects;
DKIndex top;
DKIndex lowWater[DK_AUTORELEASE_POOL_STACK_SIZE];
} arp;
};
void DKThreadContextInit( DKThreadContextRef threadContext, uint32_t options );
void DKThreadContextFinalize( DKThreadContextRef threadContext );
void DKMainThreadContextInit( void );
#endif // DK_RUNTIME_PRIVATE
#ifdef __cplusplus
}
#endif
#endif // _DK_THREAD_H_