BitShares-Core  5.0.0
BitShares blockchain implementation and command-line interface software
Public Member Functions | Static Public Member Functions | Friends | List of all members
fc::thread Class Reference

#include <thread.hpp>

Public Member Functions

 thread (const std::string &name="", thread_idle_notifier *notifier=0)
 
 thread (thread &&m)=delete
 
threadoperator= (thread &&t)=delete
 
const string & name () const
 returns the name given by set_name() for this thread More...
 
void set_name (const string &n)
 associates a name with this thread. More...
 
const char * current_task_desc () const
 
void debug (const std::string &d)
 print debug info about the state of every context / promise. More...
 
template<typename Functor >
auto async (Functor &&f, const char *desc FC_TASK_NAME_DEFAULT_ARG, priority prio=priority()) -> fc::future< decltype(f())>
 
void poke ()
 
template<typename Functor >
auto schedule (Functor &&f, const fc::time_point &when, const char *desc FC_TASK_NAME_DEFAULT_ARG, priority prio=priority()) -> fc::future< decltype(f())>
 
void quit ()
 
void signal (int)
 
bool is_running () const
 
bool is_current () const
 
priority current_priority () const
 
 ~thread ()
 
template<typename T1 , typename T2 >
int wait_any (const fc::future< T1 > &f1, const fc::future< T2 > &f2, const microseconds &timeout_us=microseconds::maximum())
 

Static Public Member Functions

static threadcurrent ()
 
static void cleanup ()
 

Friends

class promise_base
 
class task_base
 
class thread_d
 
class mutex
 
class detail::worker_pool
 
class non_preemptable_scope_check
 
void * detail::get_thread_specific_data (unsigned slot)
 
void detail::set_thread_specific_data (unsigned slot, void *new_value, void(*cleanup)(void *))
 
unsigned detail::get_next_unused_task_storage_slot ()
 
void * detail::get_task_specific_data (unsigned slot)
 
void detail::set_task_specific_data (unsigned slot, void *new_value, void(*cleanup)(void *))
 
void yield ()
 
void usleep (const microseconds &)
 
void sleep_until (const time_point &)
 
void exec ()
 
int wait_any (std::vector< promise_base::ptr > &&v, const microseconds &)
 
int wait_any_until (std::vector< promise_base::ptr > &&v, const time_point &tp)
 

Detailed Description

Definition at line 39 of file thread.hpp.

Constructor & Destructor Documentation

fc::thread::thread ( const std::string &  name = "",
thread_idle_notifier notifier = 0 
)

Definition at line 74 of file thread.cpp.

fc::thread::thread ( thread &&  m)
delete
fc::thread::~thread ( )

Definition at line 116 of file thread.cpp.

Member Function Documentation

template<typename Functor >
auto fc::thread::async ( Functor &&  f,
const char *desc  FC_TASK_NAME_DEFAULT_ARG,
priority  prio = priority() 
) -> fc::future<decltype(f())>
inline

Calls function f in this thread and returns a future<T> that can be used to wait on the result.

Parameters
fthe operation to perform
priothe priority relative to other tasks

Definition at line 87 of file thread.hpp.

void fc::thread::cleanup ( )
static

Definition at line 131 of file thread.cpp.

thread & fc::thread::current ( )
static

Returns the current thread. Note: Creates fc::thread object (but not a boost thread) if no current thread assigned yet (this can happend if current() is called from the main thread of application or from an existing "unknown" boost thread). In such cases, thread_d doesn't have access boost::thread object.

Definition at line 125 of file thread.cpp.

priority fc::thread::current_priority ( ) const

Definition at line 269 of file thread.cpp.

const char * fc::thread::current_task_desc ( ) const

Definition at line 154 of file thread.cpp.

void fc::thread::debug ( const std::string &  d)

print debug info about the state of every context / promise.

This method is helpful to figure out where your program is 'hung' by listing every async operation (context) and what it is blocked on (future).

Note
debug info is more useful if you provide a description for your async tasks and promises.

Definition at line 161 of file thread.cpp.

bool fc::thread::is_current ( ) const

Definition at line 479 of file thread.cpp.

bool fc::thread::is_running ( ) const
Returns
true unless quit() has been called.

Definition at line 264 of file thread.cpp.

const string & fc::thread::name ( ) const

returns the name given by set_name() for this thread

Definition at line 138 of file thread.cpp.

thread& fc::thread::operator= ( thread &&  t)
delete
void fc::thread::poke ( )

Definition at line 340 of file thread.cpp.

void fc::thread::quit ( )

This method will cancel all pending tasks causing them to throw cmt::error::thread_quit.

If the current thread is not this thread, then the current thread will wait for this thread to exit.

This is a blocking wait via boost::thread::join and other tasks in the current thread will not run while waiting for this thread to quit.

Todo:
make quit non-blocking of the calling thread by eliminating the call to boost::thread::join

Definition at line 174 of file thread.cpp.

template<typename Functor >
auto fc::thread::schedule ( Functor &&  f,
const fc::time_point when,
const char *desc  FC_TASK_NAME_DEFAULT_ARG,
priority  prio = priority() 
) -> fc::future<decltype(f())>
inline

Calls function f in this thread and returns a future<T> that can be used to wait on the result.

Parameters
fthe method to be called
priothe priority of this method relative to others
whendetermines when this call will happen, as soon as possible after when

Definition at line 110 of file thread.hpp.

void fc::thread::set_name ( const string &  n)

associates a name with this thread.

Definition at line 143 of file thread.cpp.

void fc::thread::signal ( int  sig)

Send signal to underlying native thread. Only for Linux and macOS

Definition at line 167 of file thread.cpp.

template<typename T1 , typename T2 >
int fc::thread::wait_any ( const fc::future< T1 > &  f1,
const fc::future< T2 > &  f2,
const microseconds timeout_us = microseconds::maximum() 
)
inline

Definition at line 150 of file thread.hpp.

Friends And Related Function Documentation

void* detail::get_task_specific_data ( unsigned  slot)
friend
void* detail::get_thread_specific_data ( unsigned  slot)
friend
void detail::set_task_specific_data ( unsigned  slot,
void *  new_value,
void(*)(void *)  cleanup 
)
friend
void detail::set_thread_specific_data ( unsigned  slot,
void *  new_value,
void(*)(void *)  cleanup 
)
friend
friend class detail::worker_pool
friend

Definition at line 162 of file thread.hpp.

void fc::thread::exec ( )
friend

Enters the main loop processing tasks until quit() is called.

Definition at line 375 of file thread.cpp.

friend class mutex
friend

Definition at line 161 of file thread.hpp.

friend class non_preemptable_scope_check
friend

Definition at line 169 of file thread.hpp.

friend class promise_base
friend

Definition at line 158 of file thread.hpp.

void fc::thread::sleep_until ( const time_point tp)
friend

Yields until the specified time in the future.

Definition at line 371 of file thread.cpp.

friend class task_base
friend

Definition at line 159 of file thread.hpp.

friend class thread_d
friend

Definition at line 160 of file thread.hpp.

void usleep ( const microseconds u)
friend

Yields to other ready tasks for u microseconds.

Definition at line 368 of file thread.cpp.

int wait_any ( std::vector< promise_base::ptr > &&  v,
const microseconds timeout_us = microseconds::maximum() 
)
friend

Definition at line 380 of file thread.cpp.

int fc::thread::wait_any_until ( std::vector< promise_base::ptr > &&  v,
const time_point tp 
)
friend

Definition at line 385 of file thread.cpp.

void yield ( )
friend

Yields to other ready tasks before returning.

Definition at line 365 of file thread.cpp.


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