Changeset 773ad32 in nscp for include


Ignore:
Timestamp:
11/10/09 18:25:49 (4 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2
Children:
b4ab033
Parents:
6672c56
Message:

swaped the mutexes for the settings subsysytem to boost

Location:
include/settings
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • include/settings/Settings.h

    rd5356c1 r773ad32  
    2424#include <string> 
    2525#include <map> 
    26 #include <Mutex.h> 
     26#include <boost/thread/thread.hpp> 
     27#include <boost/thread/locks.hpp> 
     28#include <strEx.h> 
    2729#define BUFF_LEN 4096 
    2830 
     
    615617    SettingsInterface* instance_; 
    616618    instance_list instances_; 
    617     MutexHandler mutexHandler_; 
     619    boost::timed_mutex mutexHandler_; 
    618620    /* 
    619621    struct key_description : public SettingsCore::key_description { 
     
    714716 
    715717    SettingsInterface* get() { 
    716       MutexLock mutex(mutexHandler_); 
    717       if (!mutex.hasMutex()) 
     718      boost::unique_lock<boost::timed_mutex> mutex(mutexHandler_, boost::get_system_time() + boost::posix_time::seconds(5)); 
     719      if (!mutex.owns_lock()) 
    718720        throw SettingsException(_T("Failed to get mutext, cant get settings instance")); 
    719721      if (instance_ == NULL) 
     
    724726    } 
    725727    SettingsInterface* get(SettingsCore::settings_type type) { 
    726       MutexLock mutex(mutexHandler_); 
    727       if (!mutex.hasMutex()) 
     728      boost::unique_lock<boost::timed_mutex> mutex(mutexHandler_, boost::get_system_time() + boost::posix_time::seconds(5)); 
     729      if (!mutex.owns_lock()) 
    728730        throw SettingsException(_T("Failed to get mutext, cant get settings instance")); 
    729731      return instance_unsafe(type); 
     
    783785        get_logger()->debug(__FILEW__, __LINE__, _T("Starting to migrate...")); 
    784786#endif 
    785         MutexLock mutex(mutexHandler_); 
    786         if (!mutex.hasMutex()) 
     787        boost::unique_lock<boost::timed_mutex> mutex(mutexHandler_, boost::get_system_time() + boost::posix_time::seconds(5)); 
     788        if (!mutex.owns_lock()) 
    787789          throw SettingsException(_T("migrate_type: Failed to get mutext, cant get settings instance")); 
    788790        SettingsInterface* iFrom = instance_unsafe(from); 
     
    803805    } 
    804806    SettingsCore::settings_type get_settings_type() { 
    805       MutexLock mutex(mutexHandler_); 
    806       if (!mutex.hasMutex()) 
     807      boost::unique_lock<boost::timed_mutex> mutex(mutexHandler_, boost::get_system_time() + boost::posix_time::seconds(5)); 
     808      if (!mutex.owns_lock()) 
    807809        throw SettingsException(_T("Failed to get mutext, cant get load settings")); 
    808810      if (instance_ == NULL) 
     
    823825    } 
    824826    bool has_type(SettingsCore::settings_type type) { 
    825       MutexLock mutex(mutexHandler_); 
    826       if (!mutex.hasMutex()) 
     827      boost::unique_lock<boost::timed_mutex> mutex(mutexHandler_, boost::get_system_time() + boost::posix_time::seconds(5)); 
     828      if (!mutex.owns_lock()) 
    827829        throw SettingsException(_T("has_type Failed to get mutext, cant get access settings")); 
    828830      instance_list::const_iterator cit = instances_.find(type); 
     
    830832    } 
    831833    void set_type(SettingsCore::settings_type type) { 
    832       MutexLock mutex(mutexHandler_); 
    833       if (!mutex.hasMutex()) 
     834      boost::unique_lock<boost::timed_mutex> mutex(mutexHandler_, boost::get_system_time() + boost::posix_time::seconds(5)); 
     835      if (!mutex.owns_lock()) 
    834836        throw SettingsException(_T("set_type Failed to get mutext, cant get access settings")); 
    835837      instance_list::const_iterator cit = instances_.find(type); 
     
    839841    } 
    840842    void add_type_impl(SettingsCore::settings_type type, SettingsInterface* impl) { 
    841       MutexLock mutex(mutexHandler_); 
    842       if (!mutex.hasMutex()) 
     843      boost::unique_lock<boost::timed_mutex> mutex(mutexHandler_, boost::get_system_time() + boost::posix_time::seconds(5)); 
     844      if (!mutex.owns_lock()) 
    843845        throw SettingsException(_T("add_type_impl Failed to get mutext, cant get access settings")); 
    844846      instance_list::iterator it = instances_.find(type); 
     
    11501152 
    11511153    void add_instance(SettingsInterface *instance) { 
    1152       MutexLock mutex(mutexHandler_); 
    1153       if (!mutex.hasMutex()) 
     1154      boost::unique_lock<boost::timed_mutex> mutex(mutexHandler_, boost::get_system_time() + boost::posix_time::seconds(5)); 
     1155      if (!mutex.owns_lock()) 
    11541156        throw SettingsException(_T("load_all_instance Failed to get mutext, cant get access settings")); 
    11551157      instance_list::iterator it = instances_.find(instance->get_type()); 
     
    11721174  private: 
    11731175    void destroy_all_instances() { 
    1174       MutexLock mutex(mutexHandler_); 
    1175       if (!mutex.hasMutex()) 
     1176      boost::unique_lock<boost::timed_mutex> mutex(mutexHandler_, boost::get_system_time() + boost::posix_time::seconds(5)); 
     1177      if (!mutex.owns_lock()) 
    11761178        throw SettingsException(_T("destroy_all_instances Failed to get mutext, cant get access settings")); 
    11771179      instance_ = NULL; 
     
    11861188    } 
    11871189    SettingsInterface *get_default_settings_instance_unsafe() { 
    1188       MutexLock mutex(mutexHandler_); 
    1189       if (!mutex.hasMutex()) 
     1190      boost::unique_lock<boost::timed_mutex> mutex(mutexHandler_, boost::get_system_time() + boost::posix_time::seconds(5)); 
     1191      if (!mutex.owns_lock()) 
    11901192        throw SettingsException(_T("destroy_all_instances Failed to get mutext, cant get access settings")); 
    11911193      instance_ = NULL; 
  • include/settings/settings_ini.hpp

    rf0eb62d r773ad32  
    55#include <settings/Settings.h> 
    66#include <simpleini/SimpleIni.h> 
     7#include <error.hpp> 
    78 
    89namespace Settings { 
Note: See TracChangeset for help on using the changeset viewer.