Changeset 6672c56 in nscp for service


Ignore:
Timestamp:
11/10/09 00:02:12 (4 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
773ad32
Parents:
7f9c823
Message:
  • Fixed a few bugs in the old_settings store.
  • Swapped out all mutexes from the core (NSClient++)
Location:
service
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • service/NSClient++.cpp

    r7f9c823 r6672c56  
    10131013  std::wstring moduleList = _T(""); 
    10141014  { 
    1015     ReadLock readLock(&m_mutexRW, true, 10000); 
    1016     if (!readLock.IsLocked()) { 
     1015    boost::shared_lock<boost::shared_mutex> readLock(m_mutexRW, boost::get_system_time() + boost::posix_time::seconds(5)); 
     1016    if (!readLock.owns_lock()) { 
    10171017      LOG_ERROR(_T("FATAL ERROR: Could not get read-mutex.")); 
    10181018      return -1; 
     
    10591059 */ 
    10601060void NSClientT::addPlugins(const std::list<std::wstring> plugins) { 
    1061   ReadLock readLock(&m_mutexRW, true, 10000); 
    1062   if (!readLock.IsLocked()) { 
     1061  boost::shared_lock<boost::shared_mutex> readLock(m_mutexRW, boost::get_system_time() + boost::posix_time::seconds(10)); 
     1062  if (!readLock.owns_lock()) { 
    10631063    LOG_ERROR(_T("FATAL ERROR: Could not get read-mutex.")); 
    10641064    return; 
     
    10741074void NSClientT::unloadPlugins(bool unloadLoggers) { 
    10751075  { 
    1076     WriteLock writeLock(&m_mutexRW, true, 10000); 
    1077     if (!writeLock.IsLocked()) { 
     1076    boost::unique_lock<boost::shared_mutex> writeLock(m_mutexRW, boost::get_system_time() + boost::posix_time::seconds(10)); 
     1077    if (!writeLock.owns_lock()) { 
    10781078      LOG_ERROR(_T("FATAL ERROR: Could not get read-mutex.")); 
    10791079      return; 
     
    10841084  } 
    10851085  { 
    1086     ReadLock readLock(&m_mutexRW, true, 10000); 
    1087     if (!readLock.IsLocked()) { 
     1086    boost::shared_lock<boost::shared_mutex> readLock(m_mutexRW, boost::get_system_time() + boost::posix_time::milliseconds(5000)); 
     1087    if (!readLock.owns_lock()) { 
    10881088      LOG_ERROR(_T("FATAL ERROR: Could not get read-mutex.")); 
    10891089      return; 
     
    11081108  } 
    11091109  { 
    1110     WriteLock writeLock(&m_mutexRW, true, 10000); 
    1111     if (!writeLock.IsLocked()) { 
     1110    boost::unique_lock<boost::shared_mutex> writeLock(m_mutexRW, boost::get_system_time() + boost::posix_time::seconds(10)); 
     1111    if (!writeLock.owns_lock()) { 
    11121112      LOG_ERROR(_T("FATAL ERROR: Could not get read-mutex.")); 
    11131113      return; 
     
    11341134  bool hasBroken = false; 
    11351135  { 
    1136     ReadLock readLock(&m_mutexRW, true, 10000); 
    1137     if (!readLock.IsLocked()) { 
     1136    boost::shared_lock<boost::shared_mutex> readLock(m_mutexRW, boost::get_system_time() + boost::posix_time::milliseconds(5000)); 
     1137    if (!readLock.owns_lock()) { 
    11381138      LOG_ERROR(_T("FATAL ERROR: Could not get read-mutex.")); 
    11391139      return; 
     
    11851185  plugin->load_dll(); 
    11861186  { 
    1187     WriteLock writeLock(&m_mutexRW, true, 10000); 
    1188     if (!writeLock.IsLocked()) { 
     1187    boost::unique_lock<boost::shared_mutex> writeLock(m_mutexRW, boost::get_system_time() + boost::posix_time::seconds(10)); 
     1188    if (!writeLock.owns_lock()) { 
    11891189      LOG_ERROR(_T("FATAL ERROR: Could not get read-mutex.")); 
    11901190      return plugin; 
     
    12021202 
    12031203std::wstring NSClientT::describeCommand(std::wstring command) { 
    1204   ReadLock readLock(&m_mutexRWcmdDescriptions, true, 5000); 
    1205   if (!readLock.IsLocked()) { 
     1204  boost::shared_lock<boost::shared_mutex> readLock(m_mutexRWcmdDescriptions, boost::get_system_time() + boost::posix_time::seconds(5)); 
     1205  if (!readLock.owns_lock()) { 
    12061206    LOG_ERROR(_T("FATAL ERROR: Could not get read-mutex when trying to get command list.")); 
    12071207    return _T("Failed to get mutex when describing command: ") + command; 
     
    12141214std::list<std::wstring> NSClientT::getAllCommandNames() { 
    12151215  std::list<std::wstring> lst; 
    1216   ReadLock readLock(&m_mutexRWcmdDescriptions, true, 5000); 
    1217   if (!readLock.IsLocked()) { 
     1216  boost::shared_lock<boost::shared_mutex> readLock(m_mutexRWcmdDescriptions, boost::get_system_time() + boost::posix_time::seconds(5)); 
     1217  if (!readLock.owns_lock()) { 
    12181218    LOG_ERROR(_T("FATAL ERROR: Could not get read-mutex when trying to get command list.")); 
    12191219    return lst; 
     
    12251225} 
    12261226void NSClientT::registerCommand(std::wstring cmd, std::wstring desc) { 
    1227   WriteLock writeLock(&m_mutexRWcmdDescriptions, true, 10000); 
    1228   if (!writeLock.IsLocked()) { 
     1227  boost::unique_lock<boost::shared_mutex> writeLock(m_mutexRWcmdDescriptions, boost::get_system_time() + boost::posix_time::seconds(10)); 
     1228  if (!writeLock.owns_lock()) { 
    12291229    LOG_ERROR_STD(_T("FATAL ERROR: Failed to describe command:") + cmd); 
    12301230    return; 
     
    13131313    } 
    13141314  } else { 
    1315     ReadLock readLock(&m_mutexRW, true, 5000); 
    1316     if (!readLock.IsLocked()) { 
     1315    boost::shared_lock<boost::shared_mutex> readLock(m_mutexRW, boost::get_system_time() + boost::posix_time::milliseconds(5000)); 
     1316    if (!readLock.owns_lock()) { 
    13171317      LOG_ERROR(_T("FATAL ERROR: Could not get read-mutex.")); 
    13181318      return NSCAPI::returnUNKNOWN; 
     
    13521352 
    13531353void NSClientT::listPlugins() { 
    1354   ReadLock readLock(&m_mutexRW, true, 10000); 
    1355   if (!readLock.IsLocked()) { 
     1354  boost::shared_lock<boost::shared_mutex> readLock(m_mutexRW, boost::get_system_time() + boost::posix_time::milliseconds(5000)); 
     1355  if (!readLock.owns_lock()) { 
    13561356    LOG_ERROR(_T("FATAL ERROR: Could not get read-mutex.")); 
    13571357    return; 
     
    14181418      file_stl = file_stl.substr(pos); 
    14191419    { 
    1420       ReadLock readLock(&m_mutexRW, true, 5000); 
    1421       if (!readLock.IsLocked()) { 
     1420      boost::shared_lock<boost::shared_mutex> readLock(m_mutexRW, boost::get_system_time() + boost::posix_time::milliseconds(5000)); 
     1421      if (!readLock.owns_lock()) { 
    14221422        log_broken_message(_T("Message was lost as the (mutexRW) core was locked: ") + message); 
    14231423        return; 
    14241424      } 
    1425       boost::unique_lock<boost::timed_mutex> lock(messageMutex, boost::get_system_time() + boost::posix_time::milliseconds(5000)); 
     1425      boost::unique_lock<boost::timed_mutex> lock(messageMutex, boost::get_system_time() + boost::posix_time::seconds(5)); 
    14261426      if (!lock.owns_lock()) { 
    14271427        log_broken_message(_T("Message was lost as the core was locked: ") + message); 
     
    14881488} 
    14891489std::wstring NSClientT::getBasePath(void) { 
    1490   boost::unique_lock<boost::timed_mutex> lock(internalVariables, boost::get_system_time() + boost::posix_time::milliseconds(5000)); 
     1490  boost::unique_lock<boost::timed_mutex> lock(internalVariables, boost::get_system_time() + boost::posix_time::seconds(5)); 
    14911491  if (!lock.owns_lock()) { 
    14921492    LOG_ERROR(_T("FATAL ERROR: Could not get mutex.")); 
  • service/NSClient++.h

    r7f9c823 r6672c56  
    2424#include <service/system_service.hpp> 
    2525#include "NSCPlugin.h" 
    26 #include <Mutex.h> 
     26//#include <Mutex.h> 
    2727#include <NSCAPI.h> 
    28 #include <MutexRW.h> 
     28//#include <MutexRW.h> 
    2929#include <map> 
    3030#include <com_helpers.hpp> 
     
    3232#include <boost/thread/thread.hpp> 
    3333#include <boost/thread/locks.hpp> 
     34#include <boost/thread/shared_mutex.hpp> 
     35 
    3436 
    3537/** 
     
    101103  boost::timed_mutex internalVariables; 
    102104  boost::timed_mutex messageMutex; 
    103   MutexRW m_mutexRW; 
    104   MutexRW m_mutexRWcmdDescriptions; 
     105  boost::shared_mutex m_mutexRW; 
     106  boost::shared_mutex m_mutexRWcmdDescriptions; 
    105107  cmdMap cmdDescriptions_; 
    106108  typedef enum log_status {log_unknown, log_looking, log_debug, log_nodebug }; 
Note: See TracChangeset for help on using the changeset viewer.