HandleMutexManager.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "HandleMutexManager.h"
  2. #include "ErrorCode.h"
  3. Mutex CHandleMutexManager::m_mutexHandleMutex;
  4. map<string, Mutex*> CHandleMutexManager::m_mapHandleAndMutex;
  5. int CHandleMutexManager::InsertHandleMutex(string stringUuid)
  6. {
  7. Mutex::ScopedLock lock(m_mutexHandleMutex);
  8. if(m_mapHandleAndMutex.find(stringUuid) != m_mapHandleAndMutex.end())
  9. {
  10. //˵Ã÷¸ÃhandleµÄmutexÒÑ´æÔÚ
  11. return PHMS_SUCCESSFUL_RESULT;
  12. }
  13. m_mapHandleAndMutex.insert(map<string, Mutex*>::value_type(stringUuid, new Mutex));
  14. return PHMS_SUCCESSFUL_RESULT;
  15. }
  16. int CHandleMutexManager::DeleteHandleMutex(string stringUuid)
  17. {
  18. Mutex::ScopedLock lock(m_mutexHandleMutex);
  19. Mutex* pMutex = NULL;
  20. if(m_mapHandleAndMutex.find(stringUuid) != m_mapHandleAndMutex.end())
  21. {
  22. pMutex = m_mapHandleAndMutex[stringUuid];
  23. }
  24. if(pMutex != NULL)
  25. {
  26. m_mapHandleAndMutex.erase(stringUuid);
  27. delete pMutex;
  28. }
  29. else
  30. {
  31. return COMMON_INVALID_HANDLE;
  32. }
  33. return PHMS_SUCCESSFUL_RESULT;
  34. }
  35. Mutex* CHandleMutexManager::GetHandleMutex(string stringUuid)
  36. {
  37. Mutex::ScopedLock lock(m_mutexHandleMutex);
  38. Mutex* pMutex = NULL;
  39. if(m_mapHandleAndMutex.find(stringUuid) != m_mapHandleAndMutex.end())
  40. {
  41. pMutex = m_mapHandleAndMutex[stringUuid];
  42. }
  43. return pMutex;
  44. }