Zen API
 All Classes Files Functions Variables Typedefs Macros Groups Pages
kThread.h
Go to the documentation of this file.
1 /**
2  * @file kThread.h
3  * @brief Declares the kThread class.
4  *
5  * @internal
6  * Copyright (C) 2005-2014 by LMI Technologies Inc.
7  * Licensed under the MIT License.
8  * Redistributed files must retain the above copyright notice.
9  */
10 #ifndef K_API_THREAD_H
11 #define K_API_THREAD_H
12 
13 #include <kApi/kApiDef.h>
14 
15 kBeginHeader()
16 
17 /** Thread entry-point signature; used by kThread_Start. */
18 typedef kStatus(kCall* kThreadFx)(kPointer context);
19 
20 /**
21  * @class kThread
22  * @extends kObject
23  * @ingroup kApi-Threads
24  * @brief Represents a thread.
25  */
26 //typedef kObject kThread; --forward-declared in kApiDef.x.h
27 
28 /**
29  * Causes the current thread to yield control for the specified duration.
30  *
31  * @public @memberof kThread
32  * @param duration Time to sleep, in microseconds
33  * @return Operation status.
34  */
35 kFx(kStatus) kThread_Sleep(k64u duration);
36 
37 /**
38  * Constructs a kThread object.
39  *
40  * @public @memberof kThread
41  * @param thread Destination for the constructed object handle.
42  * @param allocator Memory allocator (or kNULL for default).
43  * @return Operation status.
44  */
45 kFx(kStatus) kThread_Construct(kThread* thread, kAlloc allocator);
46 
47 /**
48  * Begins executing a thread using the specified callback function.
49  *
50  * @public @memberof kThread
51  * @param thread Thread object.
52  * @param function The thread entry function.
53  * @param context An argument to be passed to the thread entry function.
54  * @return Operation status.
55  */
56 kFx(kStatus) kThread_Start(kThread thread, kThreadFx function, kPointer context);
57 
58 /**
59  * Blocks until the thread exits, or until a timeout occurs.
60  *
61  * @public @memberof kThread
62  * @param thread Thread object.
63  * @param timeout Timeout in microseconds, or kINFINITE to wait indefinitely.
64  * @param exitCode Receives the return value from the thread function.
65  * @return Operation status.
66  */
67 kFx(kStatus) kThread_Join(kThread thread, k64u timeout, kStatus* exitCode);
68 
69 kEndHeader()
70 
71 #include <kApi/Threads/kThread.x.h>
72 
73 #endif
kStatus kThread_Sleep(k64u duration)
Causes the current thread to yield control for the specified duration.
Represents a 64-bit unsigned integer.
Represents a void pointer.
kStatus kThread_Start(kThread thread, kThreadFx function, kPointer context)
Begins executing a thread using the specified callback function.
Abstract base class for memory allocator types.
kStatus kThread_Construct(kThread *thread, kAlloc allocator)
Constructs a kThread object.
Represents a thread.
Essential API declarations.
kStatus kThread_Join(kThread thread, k64u timeout, kStatus *exitCode)
Blocks until the thread exits, or until a timeout occurs.
Represents an enumeration of error codes.
#define kCall
kApi standard function calling convention.
Definition: kApiDef.h:17
kStatus(kCall * kThreadFx)(kPointer context)
Thread entry-point signature; used by kThread_Start.
Definition: kThread.h:18