Fawkes API
Fawkes Development Version
|
#include <core/threading/mutex.h>
Public Types | |
enum | Type { NORMAL, RECURSIVE } |
Mutex type. More... | |
Public Member Functions | |
Mutex (Type type=NORMAL) | |
Constructor. More... | |
~Mutex () | |
Destructor. More... | |
void | lock () |
Lock this mutex. More... | |
bool | try_lock () |
Tries to lock the mutex. More... | |
void | unlock () |
Unlock the mutex. More... | |
void | stopby () |
Shortly stop by at the mutex. More... | |
Mutex mutual exclusion lock. This class is used in a multi-threading environment to lock access to resources. This is needed to prevent two threads from modifying a value at the same time or to prevent a thread from getting a dirty copy of a piece of data (the reader reads while a writer is writing, this could leave the data in a state where the reader reads half of the new and half of the old data).
As a rule of thumb you should lock the mutex as short as possible and as long as needed. Locking the mutex too long will lead in a bad performance of the multi-threaded application because many threads are waiting for the lock and are not doing anything useful. If you do not lock enough code (and so serialize it) it will cause pain and errors.
enum fawkes::Mutex::Type |
void fawkes::Mutex::lock | ( | ) |
Lock this mutex.
A call to lock() will block until the lock on the mutex could be aquired. If you want to avoid see consider using try_lock().
Definition at line 91 of file mutex.cpp.
Referenced by PlexilTimerThread::abort_timer(), fawkes::WaitCondition::abstimed_wait(), fawkes::NetworkNameResolverThread::address_resolution_failed(), fawkes::BlackBoardMemoryManager::alloc(), fawkes::Exception::append(), fawkes::openni::SkelIfObserver::bb_interface_created(), fawkes::BlackBoardInterfaceListener::bbil_remove_writer_interface(), fawkes::ModuleManager::close_module(), ColliThread::colli_goto(), ColliThread::colli_relgoto(), ColliThread::colli_stop(), firevision::FuseClient::disconnect(), fawkes::SyncPoint::emit(), firevision::FuseClient::enqueue_and_wait(), fawkes::MemoryConfiguration::erase_default(), fawkes::YamlConfiguration::erase_default(), fawkes::SQLiteConfiguration::exists(), LuaAgentContinuousExecutionThread::fam_event(), JacoBimanualGotoThread::final(), JacoGotoThread::final(), fawkes::BlackBoardMemoryManager::free(), fawkes::SQLiteConfiguration::get_bool(), fawkes::NetworkConfiguration::get_bool(), fawkes::SQLiteConfiguration::get_comment(), fawkes::NetworkConfiguration::get_comment(), fawkes::SQLiteConfiguration::get_default_comment(), fawkes::NetworkConfiguration::get_default_comment(), fawkes::SQLiteConfiguration::get_float(), fawkes::NetworkConfiguration::get_float(), fawkes::SQLiteConfiguration::get_int(), fawkes::NetworkConfiguration::get_int(), fawkes::LuaContext::get_lua_state(), fawkes::SQLiteConfiguration::get_string(), fawkes::NetworkConfiguration::get_string(), fawkes::SQLiteConfiguration::get_type(), fawkes::NetworkConfiguration::get_type(), fawkes::SQLiteConfiguration::get_uint(), fawkes::NetworkConfiguration::get_uint(), fawkes::NetworkConfiguration::get_value(), fawkes::DynamicMJPEGStreamWebReply::handle_buffer(), fawkes::SQLiteConfiguration::is_default(), fawkes::SQLiteConfiguration::load(), fawkes::BlackBoardMemoryManager::lock(), fawkes::SQLiteConfiguration::lock(), fawkes::NetworkConfiguration::lock(), LaserAcquisitionThread::lock_if_new_data(), IMUAcquisitionThread::lock_if_new_data(), JoystickAcquisitionThread::lock_if_new_data(), fawkes::SyncPoint::lock_until_next_wait(), SickTiM55xEthernetAcquisitionThread::loop(), JacoOpenraveThread::loop(), JacoBimanualGotoThread::loop(), HokuyoUrgAcquisitionThread::loop(), CruizCoreXG1010AcquisitionThread::loop(), JacoGotoThread::loop(), HokuyoUrgGbxAcquisitionThread::loop(), JoystickAcquisitionThread::loop(), MongoLogTransformsThread::loop(), IMUAcquisitionThread::loop(), firevision::FuseClient::loop(), LaserFilterThread::loop(), RosLaserScanThread::loop(), BBLoggerThread::loop(), ColliThread::loop(), LuaAgentContinuousExecutionThread::loop(), RosTfThread::loop(), fawkes::FawkesNetworkServerClientSendThread::loop(), fawkes::WebviewJpegStreamProducer::loop(), fawkes::FawkesNetworkClientSendThread::loop(), fawkes::DynamicMJPEGStreamWebReply::next_chunk(), fawkes::BlackBoardInterfaceManager::open_for_reading(), fawkes::BlackBoardInterfaceManager::open_for_writing(), fawkes::BlackBoardInterfaceManager::open_multiple_for_reading(), SickTiM55xCommonAcquisitionThread::parse_datagram(), MongoLogTransformsThread::prepare_finalize_user(), MongoLogPointCloudThread::prepare_finalize_user(), MongoLogImagesThread::prepare_finalize_user(), fawkes::Exception::prepend(), fawkes::Exception::print_trace(), Roomba500::query_sensors(), LuaAgentContinuousExecutionThread::read_interfaces(), Roomba500::read_sensors(), LaserAcquisitionThread::reset_distances(), fawkes::SQLiteConfiguration::set_bool(), fawkes::SQLiteConfiguration::set_comment(), fawkes::SQLiteConfiguration::set_default_bool(), fawkes::SQLiteConfiguration::set_default_comment(), fawkes::SQLiteConfiguration::set_default_float(), fawkes::SQLiteConfiguration::set_default_int(), fawkes::SQLiteConfiguration::set_default_string(), fawkes::SQLiteConfiguration::set_default_uint(), KatanaSensorAcquisitionThread::set_enabled(), fawkes::SQLiteConfiguration::set_float(), fawkes::SQLiteConfiguration::set_int(), fawkes::NetworkConfiguration::set_mirror_mode(), fawkes::ModuleManager::set_open_flags(), fawkes::SQLiteConfiguration::set_string(), fawkes::SQLiteConfiguration::set_uint(), JacoBimanualGotoThread::stop(), JacoGotoThread::stop(), fawkes::YamlConfiguration::try_lock(), firevision::FuseClient::wait(), fawkes::SyncPoint::wait(), LaserFilterThread::wait_done(), firevision::FuseClient::wait_greeting(), LuaAgentContinuousExecutionThread::write_interfaces(), and fawkes::RefCount::~RefCount().
void fawkes::Mutex::stopby | ( | ) |
bool fawkes::Mutex::try_lock | ( | ) |
Tries to lock the mutex.
This can also be used to check if a mutex is locked. The code for this can be:
This cannot be implemented in Mutex in a locked() method since this would lead to race conditions in many situations.
Definition at line 121 of file mutex.cpp.
Referenced by fawkes::Thread::detached(), fawkes::LuaContext::lock(), fawkes::PluginManager::lock(), fawkes::MessageQueue::lock(), fawkes::MemoryConfiguration::lock(), fawkes::YamlConfiguration::lock(), fawkes::LockPtr< fawkes::CLIPSEnvManager >::refmutex_ptr(), fawkes::BlackBoardMemoryManager::try_lock(), fawkes::SQLiteConfiguration::try_lock(), and fawkes::NetworkConfiguration::try_lock().
void fawkes::Mutex::unlock | ( | ) |
Unlock the mutex.
Definition at line 135 of file mutex.cpp.
Referenced by PlexilTimerThread::abort_timer(), fawkes::WaitCondition::abstimed_wait(), fawkes::BlackBoardMemoryManager::alloc(), fawkes::Exception::append(), fawkes::openni::SkelIfObserver::bb_interface_created(), ColliThread::colli_stop(), firevision::FuseClient::disconnect(), fawkes::SyncPoint::emit(), firevision::FuseClient::enqueue_and_wait(), fawkes::FawkesNetworkClient::enqueue_and_wait(), fawkes::SQLiteConfiguration::exists(), LuaAgentContinuousExecutionThread::fam_event(), JacoBimanualGotoThread::final(), JacoGotoThread::final(), fawkes::BlackBoardMemoryManager::free(), fawkes::SQLiteConfiguration::get_bool(), fawkes::NetworkConfiguration::get_bool(), fawkes::SQLiteConfiguration::get_comment(), fawkes::NetworkConfiguration::get_comment(), fawkes::SQLiteConfiguration::get_default_comment(), fawkes::NetworkConfiguration::get_default_comment(), fawkes::SQLiteConfiguration::get_float(), fawkes::NetworkConfiguration::get_float(), fawkes::SQLiteConfiguration::get_int(), fawkes::NetworkConfiguration::get_int(), fawkes::SQLiteConfiguration::get_string(), fawkes::NetworkConfiguration::get_string(), fawkes::SQLiteConfiguration::get_type(), fawkes::NetworkConfiguration::get_type(), fawkes::SQLiteConfiguration::get_uint(), fawkes::NetworkConfiguration::get_uint(), fawkes::NetworkConfiguration::get_value(), fawkes::DynamicMJPEGStreamWebReply::handle_buffer(), fawkes::SQLiteConfiguration::is_default(), fawkes::SQLiteConfiguration::load(), fawkes::LockPtr< fawkes::CLIPSEnvManager >::lock(), LaserAcquisitionThread::lock_if_new_data(), IMUAcquisitionThread::lock_if_new_data(), JoystickAcquisitionThread::lock_if_new_data(), fawkes::SyncPoint::lock_until_next_wait(), SickTiM55xEthernetAcquisitionThread::loop(), JacoOpenraveThread::loop(), JacoBimanualGotoThread::loop(), HokuyoUrgAcquisitionThread::loop(), CruizCoreXG1010AcquisitionThread::loop(), JacoGotoThread::loop(), HokuyoUrgGbxAcquisitionThread::loop(), JoystickAcquisitionThread::loop(), MongoLogTransformsThread::loop(), IMUAcquisitionThread::loop(), firevision::FuseClient::loop(), LaserFilterThread::loop(), RosLaserScanThread::loop(), MongoLogPointCloudThread::loop(), MongoLogImagesThread::loop(), BBLoggerThread::loop(), ColliThread::loop(), LuaAgentContinuousExecutionThread::loop(), RosTfThread::loop(), fawkes::FawkesNetworkServerClientSendThread::loop(), fawkes::WebviewJpegStreamProducer::loop(), fawkes::FawkesNetworkClientSendThread::loop(), fawkes::DynamicMJPEGStreamWebReply::next_chunk(), fawkes::BlackBoardInterfaceManager::open_for_reading(), fawkes::BlackBoardInterfaceManager::open_for_writing(), fawkes::BlackBoardInterfaceManager::open_multiple_for_reading(), SickTiM55xCommonAcquisitionThread::parse_datagram(), fawkes::Exception::prepend(), fawkes::Exception::print_trace(), Roomba500::query_sensors(), LuaAgentContinuousExecutionThread::read_interfaces(), Roomba500::read_sensors(), LaserAcquisitionThread::reset_distances(), fawkes::SQLiteConfiguration::set_bool(), fawkes::SQLiteConfiguration::set_comment(), fawkes::SQLiteConfiguration::set_default_bool(), fawkes::SQLiteConfiguration::set_default_comment(), fawkes::SQLiteConfiguration::set_default_float(), fawkes::SQLiteConfiguration::set_default_int(), fawkes::SQLiteConfiguration::set_default_string(), fawkes::SQLiteConfiguration::set_default_uint(), KatanaSensorAcquisitionThread::set_enabled(), fawkes::SQLiteConfiguration::set_float(), fawkes::SQLiteConfiguration::set_int(), fawkes::NetworkConfiguration::set_mirror_mode(), fawkes::SQLiteConfiguration::set_string(), fawkes::SQLiteConfiguration::set_uint(), JacoBimanualGotoThread::stop(), JacoGotoThread::stop(), fawkes::LuaContext::try_lock(), fawkes::PluginManager::try_lock(), fawkes::BlackBoardMemoryManager::try_lock(), fawkes::MessageQueue::try_lock(), fawkes::MemoryConfiguration::try_lock(), LaserAcquisitionThread::unlock(), IMUAcquisitionThread::unlock(), JoystickAcquisitionThread::unlock(), fawkes::BlackBoardMemoryManager::unlock(), fawkes::SQLiteConfiguration::unlock(), fawkes::NetworkConfiguration::unlock(), firevision::FuseClient::wait(), fawkes::SyncPoint::wait(), LaserFilterThread::wait_done(), firevision::FuseClient::wait_greeting(), LuaAgentContinuousExecutionThread::write_interfaces(), and fawkes::BoolMutexLocker::~BoolMutexLocker().