#include "sp_exlock.h" #include #include #include #include #include using namespace std; map g_modLockArr; void sp_mod_mgr_lockEx(int EntityId) { auto lock = g_modLockArr.find(EntityId); if (lock != g_modLockArr.end()) { //can find it EnterCriticalSection(lock->second); } else { CRITICAL_SECTION* cs = new CRITICAL_SECTION(); InitializeCriticalSection(cs); EnterCriticalSection(cs); g_modLockArr.insert(std::make_pair(EntityId, cs)); } } void sp_mod_mgr_unlockEx(int EntityId) { auto lock = g_modLockArr.find(EntityId); if (lock != g_modLockArr.end()) LeaveCriticalSection(lock->second); } void sp_mod_mgr_lockArrClean() { #if defined(_MSC_VER) for each (auto it in g_modLockArr) { DeleteCriticalSection(it.second); delete it.second; it.second = NULL; } #else for (auto it : g_modLockArr) { DeleteCriticalSection(it.second); delete it.second; it.second = NULL; } #endif //_MSC_VER g_modLockArr.clear(); }