ObjFW
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes
OFThread Class Reference

A class which provides portable threads. More...

#include <OFThread.h>

Inheritance diagram for OFThread:
OFObject <OFObject>

List of all members.

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)
OFThreadcurrentThread ()
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

Detailed Description

A class which provides portable threads.

To use it, you should create a new class derived from it and reimplement main.


Member Function Documentation

OFThread * OFThread::currentThread ( ) [static, virtual]
Returns:
The current thread or nil if we are in the main thread
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]
Parameters:
objAn object which is passed for use in the main method or nil
Returns:
An initialized OFThread.
id OFThread::join ( ) [virtual]

Joins a thread.

Returns:
The object returned by the main method of the 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.

Returns:
The object the join method should return when called for this thread
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!

Parameters:
keyThe 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.

Parameters:
keyThe Thread Local Storage key
objThe 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.

Parameters:
secThe 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.

Parameters:
secThe number of seconds to sleep
usecThe 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.

Parameters:
objThe object which the terminated thread will return
id OFThread::thread ( ) [static, virtual]
Returns:
A new, autoreleased thread
id OFThread::threadWithObject: ( id  obj) [static, virtual]
Parameters:
objAn object which is passed for use in the main method or nil
Returns:
A new, autoreleased thread
void OFThread::yield ( ) [static, virtual]

Yields a processor voluntarily and moves the thread at the end of the queue for its priority.


The documentation for this class was generated from the following files:
 All Classes Functions Variables