distortos  v0.7.0
object-oriented C++ RTOS for microcontrollers
distortos::ThreadIdentifier Class Reference

ThreadIdentifier class is an identifier of thread. More...

#include "distortos/ThreadIdentifier.hpp"

Collaboration diagram for distortos::ThreadIdentifier:
[legend]

Public Member Functions

constexpr ThreadIdentifier ()
 ThreadIdentifier's constructor. More...
 
 ThreadIdentifier (const internal::ThreadControlBlock &threadControlBlock, const uintptr_t sequenceNumber)
 ThreadIdentifier's constructor. More...
 
ThreadgetThread () const
 Tries to obtain the thread represented by this identifier. More...
 

Private Attributes

uintptr_t sequenceNumber_
 expected sequence number of threadControlBlock_ More...
 
const internal::ThreadControlBlockthreadControlBlock_
 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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ThreadIdentifier() [1/2]

constexpr distortos::ThreadIdentifier::ThreadIdentifier ( )
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.

◆ ThreadIdentifier() [2/2]

distortos::ThreadIdentifier::ThreadIdentifier ( const internal::ThreadControlBlock threadControlBlock,
const uintptr_t  sequenceNumber 
)
inline

ThreadIdentifier's constructor.

Parameters
[in]threadControlBlockis a reference to thread control block
[in]sequenceNumberis the sequence number of threadControlBlock

Member Function Documentation

◆ getThread()

Thread * distortos::ThreadIdentifier::getThread ( ) const

Tries to obtain the thread represented by this identifier.

Returns
pointer to thread represented by this identifier, nullptr if this identifier doesn't represent valid thread
Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator!=()

bool operator!= ( const ThreadIdentifier left,
const ThreadIdentifier right 
)
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

Parameters
[in]leftis the object on the left-hand side of comparison
[in]rightis the object on the right-hand side of comparison
Returns
false if left and right both refer to the same thread or if both of them are invalid, true otherwise

◆ operator<()

bool operator< ( const ThreadIdentifier left,
const ThreadIdentifier right 
)
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

Parameters
[in]leftis the object on the left-hand side of comparison
[in]rightis the object on the right-hand side of comparison
Returns
true if left should be ordered before right, false otherwise
Here is the call graph for this function:

◆ operator<=()

bool operator<= ( const ThreadIdentifier left,
const ThreadIdentifier right 
)
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

Parameters
[in]leftis the object on the left-hand side of comparison
[in]rightis the object on the right-hand side of comparison
Returns
false if left should be ordered before right, true otherwise

◆ operator==()

bool operator== ( const ThreadIdentifier left,
const ThreadIdentifier right 
)
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

Parameters
[in]leftis the object on the left-hand side of comparison
[in]rightis the object on the right-hand side of comparison
Returns
true if left and right both refer to the same thread or if both of them are invalid, false otherwise
Here is the call graph for this function:

◆ operator>()

bool operator> ( const ThreadIdentifier left,
const ThreadIdentifier right 
)
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

Parameters
[in]leftis the object on the left-hand side of comparison
[in]rightis the object on the right-hand side of comparison
Returns
true if right should be ordered before left, false otherwise

◆ operator>=()

bool operator>= ( const ThreadIdentifier left,
const ThreadIdentifier right 
)
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

Parameters
[in]leftis the object on the left-hand side of comparison
[in]rightis the object on the right-hand side of comparison
Returns
false if right should be ordered before left, true otherwise

Member Data Documentation

◆ sequenceNumber_

uintptr_t distortos::ThreadIdentifier::sequenceNumber_
private

expected sequence number of threadControlBlock_

◆ threadControlBlock_

const internal::ThreadControlBlock* distortos::ThreadIdentifier::threadControlBlock_
private

pointer to thread control block


The documentation for this class was generated from the following files: