PFUNC 1.0
Public Types | Public Member Functions | Public Attributes
pfunc::detail::thread Struct Reference

Portably creates and destroys threads on WINDOWS and Linux. More...

#include <pfunc/thread.hpp>

Inheritance diagram for pfunc::detail::thread:
pfunc::detail::no_copy

List of all members.

Public Types

typedef pthread_t thread_handle_type
typedef void *(* start_func_type )(void *)
typedef pthread_t native_thread_id_type
typedef std::vector
< thread_attr * > 
tls_attribute_map_type
typedef
tls_attribute_map_type::value_type 
tls_value_type

Public Member Functions

void initialize (const unsigned int &nthreads)
void create_thread (thread_handle_type &handle, thread_attr *attr, start_func_type start_func_ptr, void *start_func_arg)
 Creates a single thread.
void exit_thread () const
void join_thread (const thread_handle_type &handle) const
native_thread_id_type get_native_id (const thread_handle_type &handle) const
native_thread_id_type get_native_id () const
void tls_set (thread_attr *attr)
thread_attrtls_get ()
int get_num_procs () const
void set_affinity (const int &proc_id) const
void yield ()

Public Attributes

tls_attribute_map_type tls_attr_map

Detailed Description

Portably creates and destroys threads on WINDOWS and Linux.

Only the common subset of thread creation attributes are supported.


Member Typedef Documentation

Type of the native ID

typedef void*(* pfunc::detail::thread::start_func_type)(void *)

start func type

Type of a thread handle

Type of thread local storage

typedef tls_attribute_map_type::value_type pfunc::detail::thread::tls_value_type

Type of the thread local information stored


Member Function Documentation

void pfunc::detail::thread::create_thread ( thread_handle_type handle,
thread_attr attr,
start_func_type  start_func_ptr,
void *  start_func_arg 
) [inline]

Creates a single thread.

Parameters:
[in,out]handleA handle to the new thread.
[in]attrAttributes with which the thread is created.
[in]start_func_ptrPointer to the startup function.
[in]start_func_argArgument to the startup function.
void pfunc::detail::thread::exit_thread ( ) const [inline]

Exits the calling thread

native_thread_id_type pfunc::detail::thread::get_native_id ( const thread_handle_type handle) const [inline]

Get an ID associated with the handle being passed in. For PTHREADS, this is the handle itself. On Windows, its gotten through a function call. This function is never called from the thread whose native ID we seek.

Parameters:
[in]handleThe handle of the thread whose ID is being sought
Returns:
Native ID of the thread with handle "handle".
native_thread_id_type pfunc::detail::thread::get_native_id ( ) const [inline]

Get an ID associated with the current thread.

Returns:
Native ID of the current thread (eg., pthread_self())
int pfunc::detail::thread::get_num_procs ( ) const [inline]

Get the number of cores in the system

Returns:
The number of processors in the currently running system.
void pfunc::detail::thread::initialize ( const unsigned int &  nthreads) [inline]

required only on if TLS is suported.

Parameters:
[in]nthreadsNumber of threads that require thread local storage.
void pfunc::detail::thread::join_thread ( const thread_handle_type handle) const [inline]

Exits the calling thread

Parameters:
[in]handlehandle of the thread that we are joining with.
void pfunc::detail::thread::set_affinity ( const int &  proc_id) const [inline]

Set the affinity of the thread to the given processor

Parameters:
[in]proc_idThe processor ID to bind the current thread.
thread_attr* pfunc::detail::thread::tls_get ( ) [inline]

Get the attributes in the TLS. Called from within a thread

Returns:
Attributes (thread_attr) associated with the current thread.
void pfunc::detail::thread::tls_set ( thread_attr attr) [inline]

Set the attributes in the TLS. Called from within a thread

Parameters:
[in]attrThe attribute to be set.
void pfunc::detail::thread::yield ( ) [inline]

Yield the execution of the current thread


Member Data Documentation

Thread local storage


The documentation for this struct was generated from the following file: