Shaka Player Embedded
Public Member Functions | List of all members
shaka::ThreadEvent< T > Class Template Referencefinal

#include <thread_event.h>

Inheritance diagram for shaka::ThreadEvent< T >:
shaka::ThreadEventBase shaka::Waitable

Public Member Functions

 ThreadEvent (const std::string &name)
 
 ~ThreadEvent () override
 
GetValue ()
 
std::shared_future< T > future ()
 
template<typename _Mutex >
ResetAndWaitWhileUnlocked (std::unique_lock< _Mutex > &lock)
 
void Reset ()
 
void SignalAll ()
 
template<typename U >
void SignalAll (U &&value)
 
bool SignalAllIfNotSet ()
 
template<typename U >
bool SignalAllIfNotSet (U &&value)
 
- Public Member Functions inherited from shaka::ThreadEventBase
 ThreadEventBase (const std::string &name)
 
 ~ThreadEventBase () override
 
std::thread::id GetProvider () const override
 
void SetProvider (Thread *thread)
 
- Public Member Functions inherited from shaka::Waitable
 Waitable (const std::string &name)
 
virtual ~Waitable ()
 
std::string name () const
 

Detailed Description

template<typename T>
class shaka::ThreadEvent< T >

Describes something that needs to happen on a different thread. One (or more) threads will wait for this event; another thread will be "providing" the event. The event will only complete on the providing thread.

This object is internally thread-safe. To safely manage memory, it is suggested to use std::shared_ptr<T> to share this object.

Definition at line 70 of file thread_event.h.

Constructor & Destructor Documentation

§ ThreadEvent()

template<typename T>
shaka::ThreadEvent< T >::ThreadEvent ( const std::string &  name)
inlineexplicit

Definition at line 72 of file thread_event.h.

§ ~ThreadEvent()

template<typename T>
shaka::ThreadEvent< T >::~ThreadEvent ( )
inlineoverride

Definition at line 74 of file thread_event.h.

Member Function Documentation

§ future()

template<typename T>
std::shared_future<T> shaka::ThreadEvent< T >::future ( )
inline

Gets the future that is used for this event. It is not advised to use this as this won't include deadlock detection.

Definition at line 93 of file thread_event.h.

§ GetValue()

template<typename T>
T shaka::ThreadEvent< T >::GetValue ( )
inline

Definition at line 76 of file thread_event.h.

§ Reset()

template<typename T>
void shaka::ThreadEvent< T >::Reset ( )
inline

Resets the internal future so it can be used again. This asserts that there are no waiting threads, so it is important to call SignalAll() before this so any waiting threads will get the value.

Calls to get() after this call will need to wait until the next call to SignalAll().

Definition at line 180 of file thread_event.h.

§ ResetAndWaitWhileUnlocked()

template<typename T>
template<typename _Mutex >
T shaka::ThreadEvent< T >::ResetAndWaitWhileUnlocked ( std::unique_lock< _Mutex > &  lock)
inline

Resets this object, unlocks the given lock, and waits for this event to get another signal from another thread. This is similar to how the wait() method works on a std::condition_variable.

When this returns, the lock will be acquired again.

Definition at line 106 of file thread_event.h.

§ SignalAll() [1/2]

template<typename T>
void shaka::ThreadEvent< T >::SignalAll ( )
inline

Sets the result of the event. This can only be called once per-Reset(). Calling Reset() will allow this to be called again.

Definition at line 128 of file thread_event.h.

§ SignalAll() [2/2]

template<typename T>
template<typename U >
void shaka::ThreadEvent< T >::SignalAll ( U &&  value)
inline

Sets the result of the event. This can only be called once per-Reset(). Calling Reset() will allow this to be called again.

Definition at line 132 of file thread_event.h.

§ SignalAllIfNotSet() [1/2]

template<typename T>
bool shaka::ThreadEvent< T >::SignalAllIfNotSet ( )
inline

Sets the result of the event if it has not already been set. If this has already been set, this has no effect.

Returns
True if a signal was set, false if we were already set.

Definition at line 143 of file thread_event.h.

§ SignalAllIfNotSet() [2/2]

template<typename T>
template<typename U >
bool shaka::ThreadEvent< T >::SignalAllIfNotSet ( U &&  value)
inline

Sets the result of the event if it has not already been set. If this has already been set, this has no effect.

Returns
True if a signal was set, false if we were already set.

Definition at line 158 of file thread_event.h.


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