distortos
v0.7.0
object-oriented C++ RTOS for microcontrollers
|
ThreadIdentifier class is an identifier of thread. More...
#include "distortos/ThreadIdentifier.hpp"
Public Member Functions | |
constexpr | ThreadIdentifier () |
ThreadIdentifier's constructor. More... | |
ThreadIdentifier (const internal::ThreadControlBlock &threadControlBlock, const uintptr_t sequenceNumber) | |
ThreadIdentifier's constructor. More... | |
Thread * | getThread () const |
Tries to obtain the thread represented by this identifier. More... | |
Private Attributes | |
uintptr_t | sequenceNumber_ |
expected sequence number of threadControlBlock_ More... | |
const internal::ThreadControlBlock * | threadControlBlock_ |
pointer to thread control block More... | |
Related Functions | |
(Note that these are not member functions.) | |
bool | operator== (const ThreadIdentifier &left, const ThreadIdentifier &right) |
ThreadIdentifier's equality comparison operator. More... | |
bool | operator!= (const ThreadIdentifier &left, const ThreadIdentifier &right) |
ThreadIdentifier's inequality comparison operator. More... | |
bool | operator< (const ThreadIdentifier &left, const ThreadIdentifier &right) |
ThreadIdentifier's less-than comparison operator. More... | |
bool | operator> (const ThreadIdentifier &left, const ThreadIdentifier &right) |
ThreadIdentifier's greater-than comparison operator. More... | |
bool | operator<= (const ThreadIdentifier &left, const ThreadIdentifier &right) |
ThreadIdentifier's less-than-or-equal comparison operator. More... | |
bool | operator>= (const ThreadIdentifier &left, const ThreadIdentifier &right) |
ThreadIdentifier's greater-than-or-equal comparison operator. More... | |
ThreadIdentifier class is an identifier of thread.
Similar to std::thread::id - http://en.cppreference.com/w/cpp/thread/thread/id Similar to POSIX pthread_t - http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_types.h.html
It is true that the address of a thread object (DynamicThread
or StaticThread
) can be used as an identifier in most cases, however it is worth noting that there are two problems with such use case. These problems may or may not affect the application, depending on its architecture, system configuration and used features.
First of all, when thread detachment is enabled, the "outer" DynamicThread
object is just a holder of an "inner" thread object. In that case, the address of this "outer" object will not be equal to the address of the reference returned by calling ThisThread::get()
from thread's function.
Another issue is that using an address gives no protection against accessing an object after it was deleted.
ThreadIdentifier tries to solve these issues, as the instance is tied to the actual executing thread and - to some degree - is unique. That's why the probability of accessing wrong or destructed thread via a "dangling" identifier is negligible.
|
inline |
ThreadIdentifier's constructor.
Similar to std::thread::id::id() - http://en.cppreference.com/w/cpp/thread/thread/id/id
Default-constructed identifier does not represent valid thread.
|
inline |
ThreadIdentifier's constructor.
[in] | threadControlBlock | is a reference to thread control block |
[in] | sequenceNumber | is the sequence number of threadControlBlock |
Thread * distortos::ThreadIdentifier::getThread | ( | ) | const |
Tries to obtain the thread represented by this identifier.
|
related |
ThreadIdentifier's inequality comparison operator.
Similar to std::operator!=(std::thread::id, std::thread::id) - http://en.cppreference.com/w/cpp/thread/thread/id/operator_cmp
[in] | left | is the object on the left-hand side of comparison |
[in] | right | is the object on the right-hand side of comparison |
|
related |
ThreadIdentifier's less-than comparison operator.
Similar to std::operator<(std::thread::id, std::thread::id) - http://en.cppreference.com/w/cpp/thread/thread/id/operator_cmp
[in] | left | is the object on the left-hand side of comparison |
[in] | right | is the object on the right-hand side of comparison |
|
related |
ThreadIdentifier's less-than-or-equal comparison operator.
Similar to std::operator<=(std::thread::id, std::thread::id) - http://en.cppreference.com/w/cpp/thread/thread/id/operator_cmp
[in] | left | is the object on the left-hand side of comparison |
[in] | right | is the object on the right-hand side of comparison |
|
related |
ThreadIdentifier's equality comparison operator.
Similar to std::operator==(std::thread::id, std::thread::id) - http://en.cppreference.com/w/cpp/thread/thread/id/operator_cmp Similar to pthread_equal() - http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_equal.html
[in] | left | is the object on the left-hand side of comparison |
[in] | right | is the object on the right-hand side of comparison |
|
related |
ThreadIdentifier's greater-than comparison operator.
Similar to std::operator>(std::thread::id, std::thread::id) - http://en.cppreference.com/w/cpp/thread/thread/id/operator_cmp
[in] | left | is the object on the left-hand side of comparison |
[in] | right | is the object on the right-hand side of comparison |
|
related |
ThreadIdentifier's greater-than-or-equal comparison operator.
Similar to std::operator>=(std::thread::id, std::thread::id) - http://en.cppreference.com/w/cpp/thread/thread/id/operator_cmp
[in] | left | is the object on the left-hand side of comparison |
[in] | right | is the object on the right-hand side of comparison |
|
private |
expected sequence number of threadControlBlock_
|
private |
pointer to thread control block