MapLibre Native Core
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mbgl::util::Thread< Object > Class Template Reference

Manages a thread with Object. More...

#include <thread.hpp>

Public Member Functions

template<typename TupleArgs >
 Thread (std::function< void()> prioritySetter_, const std::string &name, TupleArgs &&args)
 
template<typename... Args>
 Thread (const std::string &name, Args &&... args)
 
template<typename... Args>
 Thread (const std::function< void()> &prioritySetter, const std::string &name, Args &&... args)
 
 ~Thread ()
 
ActorRef< std::decay_t< Object > > actor ()
 
void pause ()
 
void resume ()
 

Detailed Description

template<typename Object>
class mbgl::util::Thread< Object >

Manages a thread with Object.

Upon creation of this object, it launches a thread and creates an object of type Object in that thread. When the Thread<> object is destructed, the destructor waits for thread termination. The Thread<> constructor blocks until the thread and the Object are fully created, so after the object creation, it's safe to obtain the Object stored in this thread. The thread created will always have low priority on the platforms that support setting thread priority.

The following properties make this class different from ThreadPool:

  • Only one thread is created.
  • Object will live in a single thread, providing thread affinity.
  • It is safe to use ThreadLocal in an Object managed by Thread<>
  • A RunLoop is created for the Object thread.
  • Object can use Timer and do asynchronous I/O, like wait for sockets events.

Definition at line 40 of file thread.hpp.

Constructor & Destructor Documentation

◆ Thread() [1/3]

template<typename Object >
template<typename TupleArgs >
mbgl::util::Thread< Object >::Thread ( std::function< void()>  prioritySetter_,
const std::string &  name,
TupleArgs &&  args 
)
inline

Definition at line 43 of file thread.hpp.

◆ Thread() [2/3]

template<typename Object >
template<typename... Args>
mbgl::util::Thread< Object >::Thread ( const std::string &  name,
Args &&...  args 
)
inline

Definition at line 75 of file thread.hpp.

◆ Thread() [3/3]

template<typename Object >
template<typename... Args>
mbgl::util::Thread< Object >::Thread ( const std::function< void()> &  prioritySetter,
const std::string &  name,
Args &&...  args 
)
inline

Definition at line 79 of file thread.hpp.

◆ ~Thread()

template<typename Object >
mbgl::util::Thread< Object >::~Thread ( )
inline

Definition at line 82 of file thread.hpp.

Member Function Documentation

◆ actor()

template<typename Object >
ActorRef<std::decay_t<Object> > mbgl::util::Thread< Object >::actor ( )
inline

Returns a non-owning reference to Object that can be used to send messages to Object. It is safe to the non-owning reference to outlive this object and be used after the Thread<> gets destroyed.

Definition at line 107 of file thread.hpp.

◆ pause()

template<typename Object >
void mbgl::util::Thread< Object >::pause ( )
inline

Pauses the Object thread. It will prevent the object to wake up from events such as timers and file descriptor I/O. Messages sent to a paused Object will be queued and only processed after resume() is called.

Definition at line 115 of file thread.hpp.

◆ resume()

template<typename Object >
void mbgl::util::Thread< Object >::resume ( )
inline

Definition at line 137 of file thread.hpp.


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