static void acquire_release (void) { ACE_Process_Mutex mutex (mutex_name); // Make sure the constructor succeeded ACE_TEST_ASSERT (ACE_LOG_MSG->op_status () == 0); // To see if we really are the only holder of the mutex below, // we'll try to create a file with exclusive access. If the file // already exists, we're not the only one holding the mutex. ACE_TCHAR mutex_check[MAXPATHLEN+1]; ACE_OS::strncpy (mutex_check, mutex_name, MAXPATHLEN); ACE_OS::strncat (mutex_check, ACE_TEXT ("_checker"), MAXPATHLEN); // Grab the lock int mutex_acq = mutex.acquire (); ACE_TEST_ASSERT (mutex_acq == 0); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P) Mutex acquired %s\n"), mutex_name)); ACE_HANDLE checker_handle = ACE_OS::open (mutex_check, O_CREAT | O_EXCL); if (checker_handle == ACE_INVALID_HANDLE) { ACE_DEBUG ((LM_WARNING, ACE_TEXT ("(%P): %p\n"), ACE_TEXT ("checker file open"))); ACE_TEST_ASSERT (errno != EEXIST); } else ACE_OS::close (checker_handle); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P) Working....\n"))); // Do some "work", i.e., just sleep for a couple of seconds. ACE_OS::sleep (2); // Free up the check file for the next acquirer. ACE_OS::unlink (mutex_check); // Check if we need to release the mutex if (release_mutex == 1) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P) Releasing the mutex %s\n"), mutex_name)); int mutex_release = mutex.release (); ACE_TEST_ASSERT (mutex_release == 0); } }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { const ACE_TCHAR *name = argc > 1 ? argv[1] : ACE_TEXT("hello"); int iterations = argc > 2 ? ACE_OS::atoi (argv[2]) : 100; ACE_Process_Mutex pm (name); // Register a signal handler. ACE_Sig_Action sa ((ACE_SignalHandler) handler, SIGINT); ACE_UNUSED_ARG (sa); for (int i = 0; i < iterations && !done; i++) { ACE_DEBUG ((LM_DEBUG, "(%P|%t) = acquiring\n")); if (pm.acquire () == -1) ACE_DEBUG ((LM_DEBUG, "(%P|%t) = %p\n", "acquire failed")); else ACE_DEBUG ((LM_DEBUG, "(%P|%t) = acquired\n")); ACE_OS::sleep (3); if (pm.release () == -1) ACE_DEBUG ((LM_DEBUG, "(%P|%t) = %p\n", "release failed")); else ACE_DEBUG ((LM_DEBUG, "(%P|%t) = released\n")); if (pm.tryacquire () == -1) ACE_DEBUG ((LM_DEBUG, "(%P|%t) = %p\n", "tryacquire failed")); else ACE_DEBUG ((LM_DEBUG, "(%P|%t) = tryacquire\n")); if (pm.release () == -1) ACE_DEBUG ((LM_DEBUG, "(%P|%t) = %p\n", "release failed")); else ACE_DEBUG ((LM_DEBUG, "(%P|%t) = released\n")); } if (argc > 2) pm.remove (); return 0; }
void BSWScriptedAI::_loadFromDB() { // mutex block for process-safe request execute ACE_Process_Mutex mMutex = ACE_Process_Mutex("BSW_Lock"); debug_log("BSW: Loading table of creature %u spell on difficulty %u", m_creature->GetEntry(), currentDifficulty); char query[MAX_QUERY_LEN]; sprintf(query, "SELECT entry, spellID_N10, spellID_N25, spellID_H10, spellID_H25, timerMin_N10, timerMin_N25, timerMin_H10, timerMin_H25, timerMax_N10, timerMax_N25, timerMax_H10, timerMax_H25, data1, data2, data3, data4, locData_x, locData_y, locData_z, varData, StageMask_N, StageMask_H, CastType, isVisualEffect, isBugged, textEntry FROM `boss_spell_table` WHERE entry = %u;\r\n", m_creature->GetEntry()); mMutex.acquire(); QueryResult* Result = strSD2Pquery(query); mMutex.release(); if (Result) { uint32 uiCount = 0; do { BSWRecord m_BSWRecord; Field* pFields = Result->Fetch(); m_BSWRecord.id = uiCount; uint32 m_creatureEntry = pFields[0].GetUInt32(); for (uint8 j = 0; j < DIFFICULTY_LEVELS; ++j) m_BSWRecord.m_uiSpellEntry[j] = pFields[1+j].GetUInt32(); for (uint8 j = 0; j < DIFFICULTY_LEVELS; ++j) m_BSWRecord.m_uiSpellTimerMin[j] = pFields[1+DIFFICULTY_LEVELS+j].GetUInt32(); for (uint8 j = 0; j < DIFFICULTY_LEVELS; ++j) m_BSWRecord.m_uiSpellTimerMax[j] = pFields[1+DIFFICULTY_LEVELS*2+j].GetUInt32(); for (uint8 j = 0; j < DIFFICULTY_LEVELS; ++j) m_BSWRecord.m_uiSpellData[j] = pFields[1+DIFFICULTY_LEVELS*3+j].GetUInt32(); m_BSWRecord.LocData.x = pFields[1+DIFFICULTY_LEVELS*4].GetFloat(); m_BSWRecord.LocData.y = pFields[2+DIFFICULTY_LEVELS*4].GetFloat(); m_BSWRecord.LocData.z = pFields[3+DIFFICULTY_LEVELS*4].GetFloat(); m_BSWRecord.varData = pFields[4+DIFFICULTY_LEVELS*4].GetInt32(); m_BSWRecord.StageMaskN = pFields[5+DIFFICULTY_LEVELS*4].GetUInt32(); m_BSWRecord.StageMaskH = pFields[6+DIFFICULTY_LEVELS*4].GetUInt32(); m_BSWRecord.m_CastTarget = _getBSWCastType(pFields[7+DIFFICULTY_LEVELS*4].GetUInt8()); m_BSWRecord.m_IsVisualEffect = (pFields[8+DIFFICULTY_LEVELS*4].GetUInt8() == 0) ? false : true ; m_BSWRecord.m_IsBugged = (pFields[9+DIFFICULTY_LEVELS*4].GetUInt8() == 0) ? false : true ; m_BSWRecord.textEntry = pFields[10+DIFFICULTY_LEVELS*4].GetInt32(); m_BSWRecords.push_back(m_BSWRecord); if (m_creatureEntry != m_creature->GetEntry()) error_log("BSW: Unknown error while load boss_spell_table"); else ++uiCount; } while (Result->NextRow()); delete Result; debug_log("BSW: Loaded %u spell data records for creature %u", bossSpellCount(), m_creature->GetEntry()); } else { error_log("BSW: BSW table for creature %u is empty.", m_creature->GetEntry()); }; }
void BossSpellWorker::LoadSpellTable() { // mutex block for process-safe request execute ACE_Process_Mutex mMutex = ACE_Process_Mutex("BSW_Lock"); debug_log("BSW: Loading table of spells boss %u difficulty %u", bossID , currentDifficulty); char query[MAX_QUERY_LEN]; sprintf(query, "SELECT entry, spellID_N10, spellID_N25, spellID_H10, spellID_H25, timerMin_N10, timerMin_N25, timerMin_H10, timerMin_H25, timerMax_N10, timerMax_N25, timerMax_H10, timerMax_H25, data1, data2, data3, data4, locData_x, locData_y, locData_z, varData, StageMask_N, StageMask_H, CastType, isVisualEffect, isBugged, textEntry FROM `boss_spell_table` WHERE entry = %u;\r\n", bossID); mMutex.acquire(); QueryResult* Result = strSD2Pquery(query); mMutex.release(); if (Result) { uint32 uiCount = 0; do { Field* pFields = Result->Fetch(); m_BossSpell[uiCount].id = uiCount; uint32 bossEntry = pFields[0].GetUInt32(); for (uint8 j = 0; j < DIFFICULTY_LEVELS; ++j) m_BossSpell[uiCount].m_uiSpellEntry[j] = pFields[1+j].GetUInt32(); for (uint8 j = 0; j < DIFFICULTY_LEVELS; ++j) m_BossSpell[uiCount].m_uiSpellTimerMin[j] = pFields[1+DIFFICULTY_LEVELS+j].GetUInt32(); for (uint8 j = 0; j < DIFFICULTY_LEVELS; ++j) m_BossSpell[uiCount].m_uiSpellTimerMax[j] = pFields[1+DIFFICULTY_LEVELS*2+j].GetUInt32(); for (uint8 j = 0; j < DIFFICULTY_LEVELS; ++j) m_BossSpell[uiCount].m_uiSpellData[j] = pFields[1+DIFFICULTY_LEVELS*3+j].GetUInt32(); m_BossSpell[uiCount].LocData.x = pFields[1+DIFFICULTY_LEVELS*4].GetFloat(); m_BossSpell[uiCount].LocData.y = pFields[2+DIFFICULTY_LEVELS*4].GetFloat(); m_BossSpell[uiCount].LocData.z = pFields[3+DIFFICULTY_LEVELS*4].GetFloat(); m_BossSpell[uiCount].varData = pFields[4+DIFFICULTY_LEVELS*4].GetInt32(); m_BossSpell[uiCount].StageMaskN = pFields[5+DIFFICULTY_LEVELS*4].GetUInt32(); m_BossSpell[uiCount].StageMaskH = pFields[6+DIFFICULTY_LEVELS*4].GetUInt32(); m_BossSpell[uiCount].m_CastTarget = _getBSWCastType(pFields[7+DIFFICULTY_LEVELS*4].GetUInt8()); m_BossSpell[uiCount].m_IsVisualEffect = (pFields[8+DIFFICULTY_LEVELS*4].GetUInt8() == 0) ? false : true ; m_BossSpell[uiCount].m_IsBugged = (pFields[9+DIFFICULTY_LEVELS*4].GetUInt8() == 0) ? false : true ; m_BossSpell[uiCount].textEntry = pFields[10+DIFFICULTY_LEVELS*4].GetInt32(); if (bossEntry != bossID) error_log("BSW: Unknown error while load boss_spell_table"); else ++uiCount; } while (Result->NextRow()); _bossSpellCount = uiCount; delete Result; _fillEmptyDataField(); debug_log("BSW: Loaded %u boss spell data records for boss %u", uiCount, bossID); } else { error_log("BSW: Boss spell table for boss %u is empty.", bossID); _bossSpellCount = 0; }; }