ObjFW
|
00001 /* 00002 * Copyright (c) 2008, 2009, 2010, 2011, 2012 00003 * Jonathan Schleifer <js@webkeks.org> 00004 * 00005 * All rights reserved. 00006 * 00007 * This file is part of ObjFW. It may be distributed under the terms of the 00008 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in 00009 * the packaging of this file. 00010 * 00011 * Alternatively, it may be distributed under the terms of the GNU General 00012 * Public License, either version 2 or 3, which can be found in the file 00013 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this 00014 * file. 00015 */ 00016 00017 #import "OFObject.h" 00018 #import "OFList.h" 00019 00020 #import "threading.h" 00021 00022 @class OFDate; 00023 00024 #ifdef OF_HAVE_BLOCKS 00025 typedef id (^of_thread_block_t)(id object); 00026 #endif 00027 00031 @interface OFTLSKey: OFObject 00032 { 00033 @public 00034 of_tlskey_t key; 00035 /* Work around a bug in gcc 4.4.4 (possibly only on Haiku) */ 00036 #if !defined(__GNUC__) || __GNUC__ != 4 || __GNUC_MINOR__ != 4 || \ 00037 __GNUC_PATCHLEVEL__ != 4 00038 @protected 00039 #endif 00040 void (*destructor)(id); 00041 of_list_object_t *listObject; 00042 BOOL initialized; 00043 } 00044 00050 + TLSKey; 00051 00058 + TLSKeyWithDestructor: (void(*)(id))destructor; 00059 00060 + (void)callAllDestructors; 00061 00069 - initWithDestructor: (void(*)(id))destructor; 00070 @end 00071 00078 @interface OFThread: OFObject 00079 { 00080 @public 00081 id object; 00082 of_thread_t thread; 00083 enum { 00084 OF_THREAD_NOT_RUNNING, 00085 OF_THREAD_RUNNING, 00086 OF_THREAD_WAITING_FOR_JOIN 00087 } running; 00088 #ifdef OF_HAVE_BLOCKS 00089 of_thread_block_t block; 00090 #endif 00091 id returnValue; 00092 } 00093 00094 #if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS) 00095 @property (retain) of_thread_block_t block; 00096 #endif 00097 00103 + thread; 00104 00111 + threadWithObject: (id)object; 00112 00113 #ifdef OF_HAVE_BLOCKS 00114 00120 + threadWithBlock: (of_thread_block_t)block; 00121 00129 + threadWithBlock: (of_thread_block_t)block 00130 object: (id)object; 00131 #endif 00132 00143 + (void)setObject: (id)object 00144 forTLSKey: (OFTLSKey*)key; 00145 00154 + (id)objectForTLSKey: (OFTLSKey*)key; 00155 00161 + (OFThread*)currentThread; 00162 00169 + (void)sleepForTimeInterval: (double)seconds; 00170 00176 + (void)sleepUntilDate: (OFDate*)date; 00177 00182 + (void)yield; 00183 00187 + (void)terminate; 00188 00194 + (void)terminateWithObject: (id)object; 00195 00202 - initWithObject: (id)object; 00203 00204 #ifdef OF_HAVE_BLOCKS 00205 00211 - initWithBlock: (of_thread_block_t)block; 00212 00221 - initWithBlock: (of_thread_block_t)block 00222 object: (id)object; 00223 #endif 00224 00233 - (id)main; 00234 00239 - (void)handleTermination; 00240 00244 - (void)start; 00245 00251 - (id)join; 00252 @end 00253 00257 @interface OFMutex: OFObject 00258 { 00259 of_mutex_t mutex; 00260 BOOL initialized; 00261 } 00262 00268 + mutex; 00269 00273 - (void)lock; 00274 00280 - (BOOL)tryLock; 00281 00285 - (void)unlock; 00286 @end 00287 00291 @interface OFCondition: OFMutex 00292 { 00293 of_condition_t condition; 00294 BOOL conditionInitialized; 00295 } 00296 00302 + condition; 00303 00308 - (void)wait; 00309 00313 - (void)signal; 00314 00318 - (void)broadcast; 00319 @end