bool ItemJSBinding::addExtender(ChromiumDLL::JavaScriptExtenderI* extender) { if (!extender) return false; bool found = false; g_ItemLock.lock(); for (size_t x=0; x<g_vExtenderList.size(); x++) { if (g_vExtenderList[x] == extender) { found = true; break; } } if (!found) g_vExtenderList.push_back(extender); g_ItemLock.unlock(); return !found; }
// master线程等待所有线程初始化完成 void wait_for_thread_init() { s_init_lock.Hold(); while (s_init_count < s_net_setting.net_thread_num_) { pthread_cond_wait(&s_init_cond, &s_init_lock.GetMutex()); } s_init_lock.Release(); }
uint32 ItemJSBinding::AddItem(ScriptCoreItemI* item) { uint32 hash = UTIL::MISC::RSHash_CSTR(gcString("{0}", (uint64)item)); g_ItemLock.lock(); g_ItemMap[hash] = item; g_ItemLock.unlock(); return hash; }
void ItemJSBinding::RemoveItem(uint32 itemId) { g_ItemLock.lock(); auto it = g_ItemMap.find(itemId); if (it != g_ItemMap.end()) g_ItemMap.erase(it); g_ItemLock.unlock(); }
ScriptCoreItemI* ItemJSBinding::GetItem(uint32 itemId) { ScriptCoreItemI* ret = NULL; g_ItemLock.lock(); auto it = g_ItemMap.find(itemId); if (it != g_ItemMap.end()) ret= it->second; g_ItemLock.unlock(); return ret; }
// Called after a fork(), when we know we're alone again, to get // everything back in the proper order. void reinit() { mutex_.init(); waiting_to_stop_.init(); waiting_to_run_.init(); pending_threads_ = 1; should_stop_ = false; }
const char* ItemJSBinding::getRegistrationCode() { DesuraJSBase<ItemJSBinding>::getRegistrationCode(); g_ItemLock.lock(); for (size_t x=0; x<g_vExtenderList.size(); x++) { const char* code = g_vExtenderList[x]->getRegistrationCode(); m_szRegCode.append(code); } g_ItemLock.unlock(); return m_szRegCode.c_str(); }
JSObjHandle ItemJSBinding::execute(ChromiumDLL::JavaScriptFunctionArgs* args) { JSObjHandle ret = DesuraJSBase<ItemJSBinding>::execute(args); if (!ret->isException() || g_vExtenderList.empty()) return ret; g_ItemLock.lock(); for (size_t x=0; x<g_vExtenderList.size(); x++) { ret = g_vExtenderList[x]->execute(args); if (!ret->isException()) break; } g_ItemLock.unlock(); return ret; }
void restart() { mutex_.init(); condition_.init(); pause_condition_.init(); state = cUnknown; stop_ = false; pause_ = false; paused_ = false; run(); }
void log(const std::string& message) { mutex.lock(); os << "logger: " << message << "\n"; mutex.unlock(); }
void WildcardManager::needSpecial(WCSpecialInfo *info) { m_WCMutex.lock(); onNeedSpecialEvent(*info); m_WCMutex.unlock(); }
// worker线程初始化完成后通知master线程 void register_thread_init() { s_init_lock.Hold(); ++s_init_count; pthread_cond_signal(&s_init_cond); s_init_lock.Release(); }