ObjFW
 All Classes Functions Variables
OFThread.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012
3  * Jonathan Schleifer <js@webkeks.org>
4  *
5  * All rights reserved.
6  *
7  * This file is part of ObjFW. It may be distributed under the terms of the
8  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
9  * the packaging of this file.
10  *
11  * Alternatively, it may be distributed under the terms of the GNU General
12  * Public License, either version 2 or 3, which can be found in the file
13  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
14  * file.
15  */
16 
17 #import "OFObject.h"
18 #import "OFTLSKey.h"
19 
20 #import "threading.h"
21 
22 /* Haiku used to define this for some unknown reason which causes trouble */
23 #ifdef protected
24 # undef protected
25 #endif
26 
27 @class OFDate;
28 @class OFSortedList;
29 @class OFRunLoop;
30 
31 #ifdef OF_HAVE_BLOCKS
32 typedef id (^of_thread_block_t)(id object);
33 #endif
34 
47 {
48 #ifdef OF_THREAD_M
49 @public
50 #endif
51  id object;
52 #ifndef OF_THREAD_M
53 @private
54 #endif
55  of_thread_t thread;
56  enum {
57  OF_THREAD_NOT_RUNNING,
58  OF_THREAD_RUNNING,
59  OF_THREAD_WAITING_FOR_JOIN
60  } running;
61 #ifdef OF_HAVE_BLOCKS
62  of_thread_block_t block;
63 #endif
64  id returnValue;
66 }
67 
68 #if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
69 @property (copy) of_thread_block_t block;
70 #endif
71 
77 + (instancetype)thread;
78 
85 + (instancetype)threadWithObject: (id)object;
86 
87 #ifdef OF_HAVE_BLOCKS
88 
94 + (instancetype)threadWithBlock: (of_thread_block_t)block;
95 #endif
96 
107 + (void)setObject: (id)object
108  forTLSKey: (OFTLSKey*)key;
109 
118 + (id)objectForTLSKey: (OFTLSKey*)key;
119 
125 + (OFThread*)currentThread;
126 
132 + (OFThread*)mainThread;
133 
140 + (void)sleepForTimeInterval: (double)seconds;
141 
147 + (void)sleepUntilDate: (OFDate*)date;
148 
153 + (void)yield;
154 
158 + (void)terminate;
159 
165 + (void)terminateWithObject: (id)object;
166 
167 + (void)OF_createMainThread;
168 
175 - initWithObject: (id)object;
176 
177 #ifdef OF_HAVE_BLOCKS
178 
184 - initWithBlock: (of_thread_block_t)block;
185 #endif
186 
195 - (id)main;
196 
203 - (void)handleTermination;
204 
208 - (void)start;
209 
215 - (id)join;
216 
222 - (OFRunLoop*)runLoop;
223 @end