void bind_textdomain(const char* domain, const char* directory, const char* /*encoding*/) { LOG_G << "adding textdomain '" << domain << "' in directory '" << directory << "'\n"; std::lock_guard<std::mutex> lock(get_mutex()); get_manager().add_messages_domain(domain); get_manager().add_messages_path(directory); get_manager().update_locale(); }
void Semaphore_Mutex_Actions::release_action(const char*) { if (Force_Direct_Squeak_Interpreter_Access) return; OS_Mutex_Interface* mutex = get_mutex(); if (tracking) mutex->set_holder(-1); OS_Interface::abort_if_error("Semaphore_Mutex", mutex->unlock()); }
void TexturePlane::updateTextureAspectRatio() { get_mutex(&tex_param_mutex); if (texAspect_needs_update){ texAspect_needs_update = FALSE; textureAspect = new_textureAspect; texAmp = textureAspect*texWL/2.0; } release_mutex(&tex_param_mutex); }
void TexturePlane::updateTextureAmplitude(){ get_mutex(&tex_param_mutex); if (texAmp_needs_update){ texAmp_needs_update = FALSE; texAmp = new_texAmp; textureAspect = 2.0*texAmp/texWL; } release_mutex(&tex_param_mutex); }
std::string strftime(const std::string& format, const std::tm* time) { std::basic_ostringstream<char> dummy; std::lock_guard<std::mutex> lock(get_mutex()); dummy.imbue(get_manager().get_locale()); dummy << std::put_time(time, format.c_str()); return dummy.str(); }
void TexturePlane::updateTextureSize() { get_mutex(&tex_param_mutex); if (texSize_needs_update){ texSize_needs_update = FALSE; texWL = new_Size; texWN = 1.0/texWL; texAmp = textureAspect*texWL/2.0; } release_mutex(&tex_param_mutex); }
void TexturePlane::updateTextureWavelength(){ get_mutex(&tex_param_mutex); if (texWN_needs_update){ texWN_needs_update = FALSE; texWN = new_texWN; texWL = 1.0/texWN; textureAspect = 2.0*texAmp/texWL; } release_mutex(&tex_param_mutex); }
void sp_scalar_constructor_hook(void * px, std::size_t size, void * pn) { #ifdef BOOST_HAS_THREADS mutex_type::scoped_lock lock(get_mutex()); #endif get_map()[pn] = std::make_pair(px, size); }
void sp_scalar_destructor_hook(void *, std::size_t, void * pn) { #ifdef BOOST_HAS_THREADS mutex_type::scoped_lock lock(get_mutex()); #endif get_map().erase(pn); }
win_operating_system_info::init_dbghelp_library::init_dbghelp_library() { std::lock_guard<std::mutex> lock(get_mutex()); ::SymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS); if(!::SymInitialize(::GetCurrentProcess(), 0, TRUE)) { throw std::runtime_error(util::win::error_to_string("SymInitialize", ::GetLastError())); } }
bool ci_search(const std::string& s1, const std::string& s2) { std::lock_guard<std::mutex> lock(get_mutex()); const std::locale& locale = get_manager().get_locale(); std::string ls1 = bl::to_lower(s1, locale); std::string ls2 = bl::to_lower(s2, locale); return std::search(ls1.begin(), ls1.end(), ls2.begin(), ls2.end()) != ls1.end(); }
void GTSSvr::player_disconnected( GTS_Service* ps) { //处理断线 if( ps->player_ == 0) return; //防止多次disconnect通知 { ACE_Guard<ACE_Thread_Mutex> mon( get_mutex()); USED_PLAYERS_VECTOR::iterator fiter =NS_STL::find( used_players_.begin(), used_players_.end(), ps->player_); if( fiter == used_players_.end()) return; } //选服成功 //TODO:断线保持 /* if( ps->player_->is_ingame()) { MODULE_LOG_DEBUG( MODULE_TEMP, "userlost from client. user:[%d], and will keep living in 5 minutes.", ps->player_->uuid_.userid_); //断线保持注册 PRO::Pro_SvrDisconnKeep_req *req =PROTOCOL_NEW PRO::Pro_SvrDisconnKeep_req(); PRO_UUID_FILL( req, ps->player_->global_index_, ps->player_->uuid_); req->token_ =ps->player_->team_proxy_->token_; //保存的gts索引 req->gts_id_ =GLOBALCONFIG_INS->get_appsn(); req->proxy_index_ =ps->player_->team_proxy_->proxy_index_; this->send_to_cts( req); //选线成功之后断线,提供断线保持 player_linkkeep( ps->player_); } else */ { MODULE_LOG_DEBUG( MODULE_TEMP, "userlost from client. user:[%d]", ps->player_->uuid_.userid_); //其他情况走正常的断线流程 if( ps->player_->is_selteamsucc()) { PRO::Pro_SvrUserLost_NTF* ntf =PROTOCOL_NEW PRO::Pro_SvrUserLost_NTF(); PRO_UUID_FILL( ntf, ps->player_->global_index_, ps->player_->uuid_) this->send_to_cts( ntf); } //释放玩家资源 release_player( ps->player_); } }
void LGSModule::player_onlinetick_timer( ACE_UINT64 t) { if( used_players_.size() == 0) return; ACE_Guard<ACE_Thread_Mutex> mon( get_mutex()); for( size_t ii =0; ii < used_players_.size(); ++ii) { used_players_[ii]->main_tick( t); } }
void CThreadPool::wait() { lock(); while (!busyList.empty()) { struct timespec timeoutBusy; timeoutBusy.tv_sec = time(NULL) + 10; timeoutBusy.tv_nsec = 0; pthread_cond_timewait(&release_cond, get_mutex(), &timeoutBusy); } for (std::list<pthread_t>::iterator iter = idleList.begin(); iter != idleList.end(); iter++) { pthread_join(*iter, NULL); } unlock(); }
void Scheduler_Mutex_Actions::acquire_action(const char* why) { OS_Mutex_Interface* mutex = get_mutex(); // spin and receive to avoid deadlock; other core may be trying to send US something Timeout_Timer tt("scheduler mutex", 60, mutex->get_holder()); tt.start(); while (0 != mutex->try_lock()) { Timeout_Timer::check_all(); mutex->dec_and_check_recursion_depth(); Message_Statics::process_any_incoming_messages(false); // could check to ensure no_message mutex->check_and_inc_recursion_depth(); } if (tracking) mutex->set_holder(Logical_Core::my_rank()); }
std::string dsngettext (const char * domainname, const char *singular, const char *plural, int n) { //TODO: only the next line needs to be in the lock. std::lock_guard<std::mutex> lock(get_mutex()); std::string msgval = bl::dngettext(domainname, singular, plural, n, get_manager().get_locale()); if (msgval == singular) { const char* firsthat = std::strrchr (singular, '^'); if (firsthat == nullptr) msgval = singular; else msgval = firsthat + 1; } return msgval; }
void LGSSvr::release_player( Player* p) { ACE_Guard<ACE_Thread_Mutex> mon( get_mutex()); EMPTY_PLAYERS_LIST::iterator f =NS_STL::find( empty_players_.begin(), empty_players_.end(), p); if( f == empty_players_.end()) empty_players_.push_back( p); p->reset(); USED_PLAYERS_VECTOR::iterator fiter =NS_STL::find( used_players_.begin(), used_players_.end(), p); if( fiter != used_players_.end()) used_players_.erase( fiter); }
void GTSSvr::player_linkkeep( Player* p) { ACE_Guard<ACE_Thread_Mutex> mon( get_mutex()); //复位信息 p->team_proxy_->lnkkeep_reset(); //从使用队列中移出 USED_PLAYERS_VECTOR::iterator fiter =NS_STL::find( used_players_.begin(), used_players_.end(), p); if( fiter != used_players_.end()) used_players_.erase( fiter); p->~Player(); cache_players_.free( (void*)p); }
static void create_semaphore_serial(semaphore_t *sem) { if (!(sem)) return; get_mutex(&crit_sec_create_sem); if (!(sem->is_init)) create_semaphore(sem); release_mutex(&crit_sec_create_sem); }
Player* LGSSvr::get_emptyplayer() { if( empty_players_.size() == 0) return 0; ACE_Guard<ACE_Thread_Mutex> mon( get_mutex()); Player* player =empty_players_.front(); empty_players_.pop_front(); used_players_.push_back( player); player->prepare(); return player; }
CThreadWorker* CThreadPool::getWorker() { struct timespec timeoutWorker; timeoutWorker.tv_sec = time(NULL) + timeout; timeout.tv_nsec = 0; lock(); if (workerSet.empty()) { pthread_cond_timewait(&worker_cond, get_mutex(),&timeoutWorker); std::cout << "worker queue empty" << std::endl; unlock(); return NULL; } CThreadWorker* worker = workerSet.top(); workerSet.pop(); unlock(); return worker; }
int compare(const std::string& s1, const std::string& s2) { std::lock_guard<std::mutex> lock(get_mutex()); try { return std::use_facet<std::collate<char>>(get_manager().get_locale()).compare(s1.c_str(), s1.c_str() + s1.size(), s2.c_str(), s2.c_str() + s2.size()); } catch(const std::bad_cast&) { static bool bad_cast_once = false; if(!bad_cast_once) { ERR_G << "locale set-up for compare() is broken, falling back to std::string::compare()\n"; bad_cast_once = true; } return s1.compare(s2); } }
/* Please see header for specification */ VkPipeline Anvil::BasePipelineManager::get_pipeline(PipelineID in_pipeline_id) { std::unique_lock<std::recursive_mutex> mutex_lock; auto mutex_ptr = get_mutex(); Pipelines::const_iterator pipeline_iterator; Pipeline* pipeline_ptr = nullptr; VkPipeline result = VK_NULL_HANDLE; if (mutex_ptr != nullptr) { mutex_lock = std::move( std::unique_lock<std::recursive_mutex>(*mutex_ptr) ); } if (m_outstanding_pipelines.size() > 0) { bake(); } pipeline_iterator = m_baked_pipelines.find(in_pipeline_id); if (pipeline_iterator == m_baked_pipelines.end() ) { anvil_assert(!(pipeline_iterator == m_baked_pipelines.end()) ); goto end; } pipeline_ptr = pipeline_iterator->second.get(); if (pipeline_ptr->pipeline_create_info_ptr->is_proxy() ) { anvil_assert(!pipeline_ptr->pipeline_create_info_ptr->is_proxy() ); goto end; } result = pipeline_ptr->baked_pipeline; anvil_assert(result != VK_NULL_HANDLE); end: return result; }
void Semaphore_Mutex_Actions::acquire_action(const char*) { if (Force_Direct_Squeak_Interpreter_Access) return; // xxxxxx This code could/should be better factored across the various mutexes. -- dmu 4/09 // spin and receive to avoid deadlock; other core may be trying to send US something OS_Mutex_Interface* mutex = get_mutex(); assert_always(!mutex->is_held()); // deadlock check Timeout_Timer tt("semaphore mutex", check_assertions ? 300 : 60, mutex->get_holder()); tt.start(); while (!mutex->try_lock()) { Timeout_Timer::check_all(); mutex->dec_and_check_recursion_depth(); Message_Statics::process_any_incoming_messages(false); // could check to ensure no_message mutex->check_and_inc_recursion_depth(); } if (tracking) mutex->set_holder(Logical_Core::my_rank()); }
/* Please see header for specification */ bool Anvil::BasePipelineManager::delete_pipeline(PipelineID in_pipeline_id) { bool result = false; { std::unique_lock<std::recursive_mutex> mutex_lock; auto mutex_ptr = get_mutex(); Pipelines::iterator pipeline_iterator; if (mutex_ptr != nullptr) { mutex_lock = std::move( std::unique_lock<std::recursive_mutex>(*mutex_ptr) ); } pipeline_iterator = m_baked_pipelines.find(in_pipeline_id); if (pipeline_iterator != m_baked_pipelines.end() ) { m_baked_pipelines.erase(pipeline_iterator); } else { pipeline_iterator = m_outstanding_pipelines.find(in_pipeline_id); if (pipeline_iterator == m_outstanding_pipelines.end() ) { goto end; } m_outstanding_pipelines.erase(pipeline_iterator); } } /* All done */ result = true; end: return result; }
/** \brief Try to acquire the mutex, immediately return if the mutex * is already acquired by another thread * * \b os_mutexTryLock calls \b pthread_mutex_trylock to acquire * the posix \b mutex. */ os_result os_mutexTryLock (os_mutex *mutex) { os_result rv = os_resultFail; assert (mutex != NULL); #ifdef OSPL_STRICT_MEM assert (mutex->signature == OS_MUTEX_MAGIC_SIG); #endif if (mutex->name[0] != '\0') { STATUS result; SEM_ID id; id = get_mutex (mutex); result = semTake(id, NO_WAIT); if (result == OK) { cas_mutex_info_id (mutex, 0, id); rv = os_resultSuccess; } else { if (os_getErrno() == S_objLib_OBJ_UNAVAILABLE) { rv = os_resultBusy; } else { mutex_panic ("trylock: semTake failed", result); } } } else { int res = pthread_mutex_trylock (&mutex->info.posix_mutex); if (res == 0) { rv = os_resultSuccess; } else if (res == EBUSY) { rv = os_resultBusy; } else { mutex_panic ("pthread_mutex_trylock failed", res); } } return rv; }
/** \brief Acquire the mutex * * \b os_mutexLock calls \b pthread_mutex_lock to acquire * the posix \b mutex. */ os_result os_mutexLock_s (os_mutex *mutex) { assert (mutex != NULL); #ifdef OSPL_STRICT_MEM assert (mutex->signature == OS_MUTEX_MAGIC_SIG); #endif if (mutex->name[0] != '\0') { STATUS result; SEM_ID id; id = get_mutex (mutex); result = semTake (id, WAIT_FOREVER); if (result == ERROR) { return os_resultFail; } cas_mutex_info_id (mutex, 0, id); } else { int res = pthread_mutex_lock (&mutex->info.posix_mutex); if (res != 0) { return os_resultFail; } } return os_resultSuccess; }
int64_t hs_incr(HStore *store, char *key, int64_t value) { if (!store || !key || key[0] == '@') return 0; if (store->before > 0) return 0; pthread_mutex_t *lock = get_mutex(store, key); pthread_mutex_lock(lock); int64_t result = 0; int rlen = 0, flag = INCR_FLAG; char buf[25]; char *body = hs_get(store, key, &rlen, &flag); if (body != NULL) { if (flag != INCR_FLAG || rlen > 22) { fprintf(stderr, "try to incr %s but flag=0x%x, len=%d", key, flag, rlen); goto INCR_END; } result = strtoll(body, NULL, 10); if (result == 0 && errno == EINVAL) { fprintf(stderr, "incr %s failed: %s\n", key, buf); goto INCR_END; } } result += value; if (result < 0) result = 0; rlen = sprintf(buf, "%lld", (long long int) result); if (!hs_set(store, key, buf, rlen, INCR_FLAG, 0)) { // use timestamp later result = 0; // set failed } INCR_END: pthread_mutex_unlock(lock); if (body != NULL) free(body); return result; }
SimpleLogger::~SimpleLogger() { std::lock_guard<std::mutex> lock(get_mutex()); if (!LogPolicy::GetInstance().IsMute()) { const bool is_terminal = static_cast<bool>(isatty(fileno(stdout))); switch (level) { case logWARNING: std::cerr << (is_terminal ? RED : "") << os.str() << (is_terminal ? COL_RESET : "") << std::endl; break; case logDEBUG: #ifndef NDEBUG std::cout << (is_terminal ? YELLOW : "") << os.str() << (is_terminal ? COL_RESET : "") << std::endl; #endif break; default: //logINFO: std::cout << os.str() << (is_terminal ? COL_RESET : "") << std::endl; break; } } }
static mutex_t *create_mutex_serial(mutex_t *mutex) { if (!(mutex)) return NULL; /* critical section to avoid remote possibility of race on same *mutex -- see get_mutex comments above. module clients must initialize the present module with threads_wrapper_init(). */ get_mutex(&crit_sec_create_mutex); if (!(mutex->is_init)) create_mutex(mutex); release_mutex(&crit_sec_create_mutex); return mutex; }