ObjFW
|
A class which provides portable threads. More...
#include <OFThread.h>
Public Types | |
enum | { OF_THREAD_NOT_RUNNING, OF_THREAD_RUNNING, OF_THREAD_WAITING_FOR_JOIN } |
Public Member Functions | |
id | initWithObject: (id obj) |
id | main () |
void | handleTermination () |
void | start () |
id | join () |
Static Public Member Functions | |
id | thread () |
id | threadWithObject: (id obj) |
void | setObject:forTLSKey: (id obj,[forTLSKey] OFTLSKey *key) |
id | objectForTLSKey: (OFTLSKey *key) |
OFThread * | currentThread () |
void | sleepForTimeInterval: (int64_t sec) |
void | sleepForTimeInterval:microseconds: (int64_t sec,[microseconds] uint32_t usec) |
void | sleepUntilDate: (OFDate *date) |
void | yield () |
void | terminate () |
void | terminateWithObject: (id obj) |
Public Attributes | |
enum OFThread:: { ... } | running |
id | retval |
Protected Attributes | |
id | object |
of_thread_t | thread |
A class which provides portable threads.
To use it, you should create a new class derived from it and reimplement main.
OFThread * OFThread::currentThread | ( | ) | [static, virtual] |
void OFThread::handleTermination | ( | ) | [virtual] |
This routine is exectued when the thread's main method has finished executing or terminate has been called.
id OFThread::initWithObject: | ( | id | obj | ) | [virtual] |
obj | An object which is passed for use in the main method or nil |
id OFThread::join | ( | ) | [virtual] |
Joins a thread.
id OFThread::main | ( | ) | [virtual] |
The main routine of the thread. You need to reimplement this!
It can access the object passed to the threadWithObject or initWithObject method using the instance variable named object.
id OFThread::objectForTLSKey: | ( | OFTLSKey* | key | ) | [static, virtual] |
Returns the object for the specified Thread Local Storage key.
The returned object is not retained and autoreleased for performance reasons!
key | The Thread Local Storage key |
void OFThread::setObject:forTLSKey: | ( | id | obj, |
[forTLSKey] OFTLSKey* | key | ||
) | [static, virtual] |
Sets the Thread Local Storage for the specified key.
The specified object is first retained and then the object stored before is released. You can specify nil as object if you want the old object to be released and don't want any new object for the TLS key.
key | The Thread Local Storage key |
obj | The object the Thread Local Storage key will be set to |
void OFThread::sleepForTimeInterval: | ( | int64_t | sec | ) | [static, virtual] |
Suspends execution of the current thread for the specified time interval.
sec | The number of seconds to sleep |
void OFThread::sleepForTimeInterval:microseconds: | ( | int64_t | sec, |
[microseconds] uint32_t | usec | ||
) | [static, virtual] |
Suspends execution of the current thread for the specified time interval.
sec | The number of seconds to sleep |
usec | The number of microseconds to sleep |
void OFThread::sleepUntilDate: | ( | OFDate* | date | ) | [static, virtual] |
Suspends execution of the current thread until the specified date.
void OFThread::start | ( | ) | [virtual] |
Starts the thread.
void OFThread::terminate | ( | ) | [static, virtual] |
Terminates the current thread, letting it return nil.
void OFThread::terminateWithObject: | ( | id | obj | ) | [static, virtual] |
Terminates the current thread, letting it return the specified object.
obj | The object which the terminated thread will return |
id OFThread::thread | ( | ) | [static, virtual] |
id OFThread::threadWithObject: | ( | id | obj | ) | [static, virtual] |
obj | An object which is passed for use in the main method or nil |
void OFThread::yield | ( | ) | [static, virtual] |
Yields a processor voluntarily and moves the thread at the end of the queue for its priority.