Main MRPT website > C++ reference for MRPT 1.5.7
Classes | Namespaces | Enumerations | Functions
Threads (in #include <mrpt/system/threads.h>)

Detailed Description

Collaboration diagram for Threads (in #include <mrpt/system/threads.h>):

Classes

struct  mrpt::system::TThreadHandle
 This structure contains the information needed to interface the threads API on each platform: More...
 

Namespaces

 mrpt::system::detail
 Auxiliary classes used internally to MRPT.
 

Enumerations

enum  mrpt::system::TProcessPriority { mrpt::system::ppIdle = 0, mrpt::system::ppNormal, mrpt::system::ppHigh, mrpt::system::ppVeryHigh }
 The type for cross-platform process (application) priorities. More...
 
enum  mrpt::system::TThreadPriority {
  mrpt::system::tpLowests =-15, mrpt::system::tpLower = -2, mrpt::system::tpLow = -1, mrpt::system::tpNormal = 0,
  mrpt::system::tpHigh = 1, mrpt::system::tpHigher = 2, mrpt::system::tpHighest = 15
}
 The type for cross-platform thread priorities. More...
 

Functions

template<typename T >
TThreadHandle mrpt::system::createThread (void(*func)(T), T param)
 Creates a new thread from a function (or static method) with one generic parameter. More...
 
template<typename T >
TThreadHandle mrpt::system::createThreadRef (void(*func)(T &), T &param)
 
TThreadHandle mrpt::system::createThread (void(*func)(void))
 
template<typename CLASS , typename PARAM >
TThreadHandle mrpt::system::createThreadFromObjectMethod (CLASS *obj, void(CLASS::*func)(PARAM), PARAM param)
 Creates a new thread running a non-static method (so it will have access to "this") from another method of the same class - with one generic parameter. More...
 
template<typename CLASS , typename PARAM >
TThreadHandle mrpt::system::createThreadFromObjectMethodRef (CLASS *obj, void(CLASS::*func)(PARAM &), PARAM &param)
 
template<typename CLASS >
TThreadHandle mrpt::system::createThreadFromObjectMethod (CLASS *obj, void(CLASS::*func)(void))
 
void BASE_IMPEXP mrpt::system::joinThread (const TThreadHandle &threadHandle)
 Waits until the given thread ends. More...
 
unsigned long BASE_IMPEXP mrpt::system::getCurrentThreadId () MRPT_NO_THROWS
 Returns the ID of the current thread. More...
 
TThreadHandle BASE_IMPEXP mrpt::system::getCurrentThreadHandle () MRPT_NO_THROWS
 Returns a handle to the current thread. More...
 
void BASE_IMPEXP mrpt::system::exitThread () MRPT_NO_THROWS
 Explicit close of the current (running) thread. More...
 
void BASE_IMPEXP mrpt::system::getCurrentThreadTimes (time_t &creationTime, time_t &exitTime, double &cpuTime)
 Returns the creation and exit times of the current thread and its CPU time consumed. More...
 
void BASE_IMPEXP mrpt::system::changeThreadPriority (const TThreadHandle &threadHandle, TThreadPriority priority)
 Change the priority of the given thread - for Windows, see also changeCurrentProcessPriority() More...
 
void BASE_IMPEXP mrpt::system::terminateThread (TThreadHandle &threadHandle) MRPT_NO_THROWS
 Terminate a thread, giving it no choice to delete objects, etc (use only as a last resource) More...
 
void BASE_IMPEXP mrpt::system::changeCurrentProcessPriority (TProcessPriority priority)
 Change the priority of the given process (it applies to all the threads, plus independent modifiers for each thread). More...
 
unsigned int BASE_IMPEXP mrpt::system::getNumberOfProcessors ()
 Return the number of processors ("cores"), or 1 if it cannot be determined. More...
 
void BASE_IMPEXP mrpt::system::sleep (int time_ms) MRPT_NO_THROWS
 An OS-independent method for sending the current thread to "sleep" for a given period of time. More...
 
bool BASE_IMPEXP mrpt::system::launchProcess (const std::string &command)
 Executes the given command (which may contain a program + arguments), and waits until it finishes. More...
 

Enumeration Type Documentation

The type for cross-platform process (application) priorities.

See also
changeCurrentProcessPriority
Enumerator
ppIdle 
ppNormal 
ppHigh 
ppVeryHigh 

Definition at line 70 of file threads.h.

The type for cross-platform thread priorities.

See also
changeThreadPriority
Enumerator
tpLowests 
tpLower 
tpLow 
tpNormal 
tpHigh 
tpHigher 
tpHighest 

Definition at line 80 of file threads.h.

Function Documentation

void BASE_IMPEXP mrpt::system::changeCurrentProcessPriority ( TProcessPriority  priority)

Change the priority of the given process (it applies to all the threads, plus independent modifiers for each thread).

Definition at line 303 of file threads.cpp.

References mrpt::system::ppHigh, mrpt::system::ppIdle, mrpt::system::ppNormal, mrpt::system::ppVeryHigh, and THROW_EXCEPTION.

Referenced by mrpt::system::createThreadFromObjectMethod().

void BASE_IMPEXP mrpt::system::changeThreadPriority ( const TThreadHandle threadHandle,
TThreadPriority  priority 
)

Change the priority of the given thread - for Windows, see also changeCurrentProcessPriority()

Definition at line 250 of file threads.cpp.

References mrpt::system::tpHigh, mrpt::system::tpHigher, mrpt::system::tpHighest, mrpt::system::tpLow, mrpt::system::tpLower, mrpt::system::tpLowests, and mrpt::system::tpNormal.

Referenced by mrpt::system::createThreadFromObjectMethod().

template<typename T >
TThreadHandle mrpt::system::createThread ( void(*)(T)  func,
param 
)
inline

Creates a new thread from a function (or static method) with one generic parameter.

This function creates, and starts a new thread running some code given by a function. The thread function should end by returning as normal.

Parameters
funcThe function with the code to run in the thread.
paramThe parameter to be passed to the new thread function.
Returns
A structure that represents the thread (it contains its ID and, in Windows, its HANDLE).
Exceptions
std::exceptionIf the operation fails
See also
createThreadFromObjectMethod, joinThread, changeThreadPriority

Definition at line 181 of file threads.h.

References mrpt::system::detail::ThreadCreateFunctor< T >::createThread().

Referenced by mrpt::gui::WxSubsystem::createOneInstanceMainThread(), mrpt::detectors::CFaceDetection::init(), mrpt::hwdrivers::CImpinjRFID::initialize(), my_CriticalSections_Multi(), and my_CSemaphore().

TThreadHandle mrpt::system::createThread ( void(*)(void func)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 189 of file threads.h.

References mrpt::system::detail::ThreadCreateFunctorNoParams::createThread().

template<typename CLASS , typename PARAM >
TThreadHandle mrpt::system::createThreadFromObjectMethod ( CLASS *  obj,
void(CLASS::*)(PARAM)  func,
PARAM  param 
)
inline

Creates a new thread running a non-static method (so it will have access to "this") from another method of the same class - with one generic parameter.

This function creates, and starts a new thread running some code given by a function. The thread function should end by returning as normal. Example of usage:

class MyClass {
public:
void myThread(int n);
void someMethod() {
createThreadFromObjectMethod(this, &MyClass::myThread, 123 );
....
}
};
Parameters
funcThe function with the code to run in the thread.
paramThe parameter to be passed to the new thread function.
Returns
A structure that represents the thread (it contains its ID and, in Windows, its HANDLE).
Exceptions
std::exceptionIf the operation fails
See also
createThread, joinThread, changeThreadPriority

Definition at line 216 of file threads.h.

References mrpt::system::detail::ThreadCreateObjectFunctor< CLASS, PARAM >::createThread().

Referenced by mrpt::system::CFileSystemWatcher::CFileSystemWatcher(), mrpt::hmtslam::CHMTSLAM::CHMTSLAM(), mrpt::hwdrivers::CNTRIPClient::CNTRIPClient(), mrpt::hwdrivers::CIbeoLuxETH::initialize(), mrpt::hwdrivers::CCameraSensor::initialize(), mrpt::pbmap::PbMapLocaliser::PbMapLocaliser(), mrpt::pbmap::PbMapMaker::PbMapMaker(), mrpt::hwdrivers::CRovio::retrieve_video(), and mrpt::graphslam::optimizers::CLevMarqGSO< GRAPH_T >::updateState().

template<typename CLASS >
TThreadHandle mrpt::system::createThreadFromObjectMethod ( CLASS *  obj,
void(CLASS::*)(void func 
)
inline
template<typename CLASS , typename PARAM >
TThreadHandle mrpt::system::createThreadFromObjectMethodRef ( CLASS *  obj,
void(CLASS::*)(PARAM &)  func,
PARAM &  param 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 221 of file threads.h.

References mrpt::system::detail::ThreadCreateObjectFunctor< CLASS, PARAM >::createThread().

template<typename T >
TThreadHandle mrpt::system::createThreadRef ( void(*)(T &)  func,
T &  param 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 185 of file threads.h.

References mrpt::system::detail::ThreadCreateFunctor< T >::createThread().

Referenced by mrpt::utils::net::DNS_resolve_async().

void mrpt::system::exitThread ( )

Explicit close of the current (running) thread.

Do not use normally, it's better just to return from the running thread function.

See also
createThread

Definition at line 526 of file threads.cpp.

Referenced by mrpt::system::createThreadFromObjectMethod(), and mrpt::hwdrivers::CImpinjRFID::startDriver().

TThreadHandle mrpt::system::getCurrentThreadHandle ( )

Returns a handle to the current thread.

Definition at line 231 of file threads.cpp.

Referenced by mrpt::system::createThreadFromObjectMethod().

unsigned long mrpt::system::getCurrentThreadId ( )
void mrpt::system::getCurrentThreadTimes ( time_t &  creationTime,
time_t &  exitTime,
double &  cpuTime 
)

Returns the creation and exit times of the current thread and its CPU time consumed.

Parameters
creationTimeThe creation time of the thread.
exitTimeThe exit time of the thread, or undefined if it is still running.
cpuTimeThe CPU time consumed by the thread, in seconds.
Exceptions
std::exceptionIf the operation fails
See also
getCurrentThreadHandle, getCurrentThreadId, createThread

Definition at line 339 of file threads.cpp.

References FALSE, mrpt::format(), mrpt::system::getCurrentThreadId(), HANDLE(), info, int(), MRPT_END, MRPT_START, MRPT_UNUSED_PARAM, THROW_EXCEPTION, and mrpt::system::tokenize().

Referenced by mrpt::system::createThreadFromObjectMethod(), mrpt::hmtslam::CHMTSLAM::thread_3D_viewer(), mrpt::hmtslam::CHMTSLAM::thread_LSLAM(), and mrpt::hmtslam::CHMTSLAM::thread_TBI().

unsigned int mrpt::system::getNumberOfProcessors ( )

Return the number of processors ("cores"), or 1 if it cannot be determined.

Definition at line 486 of file threads.cpp.

References int().

Referenced by mrpt::system::createThreadFromObjectMethod().

void mrpt::system::joinThread ( const TThreadHandle threadHandle)
bool mrpt::system::launchProcess ( const std::string command)

Executes the given command (which may contain a program + arguments), and waits until it finishes.

Returns
false on any error, true otherwise

Definition at line 454 of file threads.cpp.

Referenced by mrpt::system::createThreadFromObjectMethod(), mrpt::vision::CFeatureExtraction::extractFeaturesSIFT(), and mrpt::vision::CFeatureExtraction::internal_computeSiftDescriptors().

void mrpt::system::sleep ( int  time_ms)

An OS-independent method for sending the current thread to "sleep" for a given period of time.

Parameters
time_msThe sleep period, in miliseconds.

Definition at line 57 of file threads.cpp.

References int(), mrpt::utils::CTicTac::Tac(), and mrpt::utils::CTicTac::Tic().

Referenced by mrpt::slam::CGridMapAligner::AlignPDF_correlation(), mrpt::hwdrivers::CEnoseModular::checkConnectionAndConnect(), mrpt::hwdrivers::CBoardENoses::checkConnectionAndConnect(), mrpt::hwdrivers::CBoardSonars::checkConnectionAndConnect(), mrpt::hwdrivers::CServoeNeck::checkConnectionAndConnect(), mrpt::hwdrivers::CSickLaserUSB::checkControllerIsConnected(), mrpt::hwdrivers::CImpinjRFID::connect(), mrpt::system::createThreadFromObjectMethod(), mrpt::gui::CBaseGUIWindow::createWxWindow(), mrpt::gui::CBaseGUIWindow::destroyWxWindow(), mrpt::detectors::CCascadeClassifierDetection::detectObjects_Impl(), mrpt::hwdrivers::CGillAnemometer::doProcess(), mrpt::hwdrivers::CRaePID::doProcess(), mrpt::hwdrivers::CIMUXSens_MT4::doProcess(), mrpt::hwdrivers::CIMUXSens::doProcess(), mrpt::hwdrivers::CSkeletonTracker::doProcess(), mrpt::hwdrivers::CNTRIPEmitter::doProcess(), mrpt::hwdrivers::CIMUIntersense::doProcess(), mrpt::hwdrivers::CGyroKVHDSP3000::doProcess(), mrpt::graphslam::deciders::CICPCriteriaERD< GRAPH_T >::dumpVisibilityErrorMsg(), mrpt::graphslam::deciders::CLoopCloserERD< GRAPH_T >::dumpVisibilityErrorMsg(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::dumpVisibilityErrorMsg(), mrpt::hwdrivers::CCameraSensor::getNextFrame(), mrpt::hwdrivers::CVelodyneScanner::getNextObservation(), mrpt::hwdrivers::CImageGrabber_OpenCV::getObservation(), mrpt::gui::CBaseGUIWindow::getPushedKey(), mrpt::hwdrivers::CNationalInstrumentsDAQ::grabbing_thread(), mrpt::utils::net::http_request(), mrpt::hwdrivers::CIMUIntersense::initialize(), mrpt::hwdrivers::CVelodyneScanner::internal_read_PCAP_packet(), mrpt::hwdrivers::CGPSInterface::JAVAD_sendMessage(), launchTestWithTimeout(), mrpt::hwdrivers::CGPSInterface::legacy_topcon_setup_commands(), mrpt::hwdrivers::CSickLaserSerial::LMS_setupSerialComms(), xsens::msleep(), my_CriticalSections_Multi(), my_CSemaphore(), mrpt::hwdrivers::CGPSInterface::OnConnectionEstablished(), mrpt::hwdrivers::CGPSInterface::OnConnectionShutdown(), mrpt::hwdrivers::COpenNI2Generic::open(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::pauseExec(), mrpt::hwdrivers::prepareVideoSourceFromUserSelection(), mrpt::hwdrivers::CNTRIPClient::private_ntrip_thread(), mrpt::hwdrivers::CBoardSonars::programI2CAddress(), mrpt::hwdrivers::CServoeNeck::queryFirmwareVersion(), mrpt::hwdrivers::CSerialPort::Read(), mrpt::hwdrivers::CSerialPort::ReadString(), mrpt::hwdrivers::CTuMicos::reset(), mrpt::hwdrivers::CRovio::retrieve_video(), mrpt::pbmap::PbMapLocaliser::run(), mrpt::pbmap::PbMapMaker::run(), mrpt::hwdrivers::CPtuDPerception::scan(), sem_thread_example(), mrpt::hwdrivers::CSickLaserSerial::SendCommandToSICK(), mrpt::hwdrivers::CServoeNeck::setRegisterValue(), mrpt::hwdrivers::CServoeNeck::setRegisterValueAndSpeed(), mrpt::hwdrivers::CCANBusReader::setupSerialComms(), mrpt::hwdrivers::CImpinjRFID::startDriver(), mrpt::hwdrivers::CNationalInstrumentsDAQ::stop(), mrpt::pbmap::PbMapLocaliser::stop_pbMapLocaliser(), mrpt::pbmap::PbMapMaker::stop_pbMapMaker(), mrpt::hmtslam::CHMTSLAM::thread_3D_viewer(), thread_example(), mrpt::hmtslam::CHMTSLAM::thread_LSLAM(), mrpt::hwdrivers::CCameraSensor::thread_save_images(), mrpt::hmtslam::CHMTSLAM::thread_TBI(), mrpt::hwdrivers::CRovio::thread_video(), mrpt::hwdrivers::CLMS100Eth::turnOn(), mrpt::hwdrivers::CGPSInterface::unsetJAVAD_AIM_mode(), mrpt::pbmap::PbMapMaker::viz_cb(), mrpt::hwdrivers::CCANBusReader::waitContinuousSampleFrame(), mrpt::hwdrivers::CSickLaserSerial::waitContinuousSampleFrame(), mrpt::gui::CBaseGUIWindow::waitForKey(), mrpt::gui::WxSubsystem::waitWxShutdownsIfNoWindows(), CGraphSlamHandler< GRAPH_T >::~CGraphSlamHandler(), and mrpt::hwdrivers::CIbeoLuxETH::~CIbeoLuxETH().

void mrpt::system::terminateThread ( TThreadHandle threadHandle)

Terminate a thread, giving it no choice to delete objects, etc (use only as a last resource)

Definition at line 538 of file threads.cpp.

Referenced by mrpt::system::createThreadFromObjectMethod(), and mrpt::system::CFileSystemWatcher::~CFileSystemWatcher().




Page generated by Doxygen 1.8.11 for MRPT 1.5.7 Git: 2190203 Tue May 15 02:01:15 2018 +0200 at miƩ may 16 12:40:16 CEST 2018