123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #include "sp_exlock.h"
- #include<iostream>
- #include<memory>
- #include<map>
- #include <winpr/windows.h>
- #include <winpr/synch.h>
- using namespace std;
- map<int, CRITICAL_SECTION*> 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();
- }
|