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 @class OFDate;
23 @class OFSortedList;
24 @class OFRunLoop;
25 
26 #ifdef OF_HAVE_BLOCKS
27 typedef id (^of_thread_block_t)(id object);
28 #endif
29 
42 {
43 #ifdef OF_THREAD_M
44 @public
45 #endif
46  id object;
47 #ifndef OF_THREAD_M
48 @private
49 #endif
50  of_thread_t thread;
51  enum {
52  OF_THREAD_NOT_RUNNING,
53  OF_THREAD_RUNNING,
54  OF_THREAD_WAITING_FOR_JOIN
55  } running;
56 #ifdef OF_HAVE_BLOCKS
57  of_thread_block_t block;
58 #endif
59  id returnValue;
61 }
62 
63 #if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
64 @property (copy) of_thread_block_t block;
65 #endif
66 
72 + (instancetype)thread;
73 
80 + (instancetype)threadWithObject: (id)object;
81 
82 #ifdef OF_HAVE_BLOCKS
83 
89 + (instancetype)threadWithBlock: (of_thread_block_t)block;
90 #endif
91 
102 + (void)setObject: (id)object
103  forTLSKey: (OFTLSKey*)key;
104 
113 + (id)objectForTLSKey: (OFTLSKey*)key;
114 
120 + (OFThread*)currentThread;
121 
127 + (OFThread*)mainThread;
128 
135 + (void)sleepForTimeInterval: (double)seconds;
136 
142 + (void)sleepUntilDate: (OFDate*)date;
143 
148 + (void)yield;
149 
153 + (void)terminate;
154 
160 + (void)terminateWithObject: (id)object;
161 
162 + (void)OF_createMainThread;
163 
170 - initWithObject: (id)object;
171 
172 #ifdef OF_HAVE_BLOCKS
173 
179 - initWithBlock: (of_thread_block_t)block;
180 #endif
181 
190 - (id)main;
191 
198 - (void)handleTermination;
199 
203 - (void)start;
204 
210 - (id)join;
211 
217 - (OFRunLoop*)runLoop;
218 @end