Pointer to a thread-local variable. More...
#include <ThreadLocalPtr.hpp>
Public Member Functions | |
ThreadLocalPtr (T *value=NULL) | |
Default constructor. | |
T & | operator* () const |
Overload of unary operator *. | |
T * | operator-> () const |
Overload of operator ->. | |
operator T * () const | |
Cast operator to implicitely convert the pointer to its raw pointer type (T*). | |
ThreadLocalPtr< T > & | operator= (T *value) |
Assignment operator for a raw pointer parameter. | |
ThreadLocalPtr< T > & | operator= (const ThreadLocalPtr< T > &right) |
Assignment operator for a ThreadLocalPtr parameter. | |
Private Member Functions | |
void | SetValue (void *value) |
Set the thread-specific value of the variable. | |
void * | GetValue () const |
Retrieve the thread-specific value of the variable. |
Pointer to a thread-local variable.
sf::ThreadLocalPtr is a type-safe wrapper for storing pointers to thread-local variables.
A thread-local variable holds a different value for each different thread, unlike normal variable that are shared.
Its usage is completely transparent, so that it is similar to manipulating the raw pointer directly (like any smart pointer).
Usage example:
MyClass object1; MyClass object2; sf::ThreadLocalPtr<MyClass> objectPtr; void Thread1(void*) { objectPtr = &object1; // doesn't impact Thread2 ... } void Thread1(void*) { objectPtr = &object2; // doesn't impact Thread1 ... } int main() { // Create and launch the two threads sf::Thread thread1(&Thread1); sf::Thread thread2(&Thread2); thread1.Launch(); thread2.Launch(); return 0; }
ThreadLocalPtr is designed for internal use; however you can use it if you feel like it fits well your implementation.
Definition at line 41 of file ThreadLocalPtr.hpp.
sf::ThreadLocalPtr< T >::ThreadLocalPtr | ( | T * | value = NULL |
) | [inline] |
Default constructor.
value | Optional value to initalize the variable |
Definition at line 30 of file ThreadLocalPtr.inl.
sf::ThreadLocalPtr< T >::operator T * | ( | ) | const [inline] |
Cast operator to implicitely convert the pointer to its raw pointer type (T*).
Definition at line 54 of file ThreadLocalPtr.inl.
T & sf::ThreadLocalPtr< T >::operator* | ( | ) | const [inline] |
Overload of unary operator *.
Like raw pointers, applying the * operator returns a reference to the pointed object.
Definition at line 38 of file ThreadLocalPtr.inl.
T * sf::ThreadLocalPtr< T >::operator-> | ( | ) | const [inline] |
Overload of operator ->.
Like raw pointers, applying the -> operator returns the pointed object.
Definition at line 46 of file ThreadLocalPtr.inl.
ThreadLocalPtr< T > & sf::ThreadLocalPtr< T >::operator= | ( | const ThreadLocalPtr< T > & | right | ) | [inline] |
Assignment operator for a ThreadLocalPtr parameter.
right | ThreadLocalPtr to assign |
Definition at line 71 of file ThreadLocalPtr.inl.
ThreadLocalPtr< T > & sf::ThreadLocalPtr< T >::operator= | ( | T * | value | ) | [inline] |
Assignment operator for a raw pointer parameter.
value | Pointer to assign |
Definition at line 62 of file ThreadLocalPtr.inl.