You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.2KB

  1. /*
  2. Copyright (C) 2006-2009 Nasca Octavian Paul
  3. Author: Nasca Octavian Paul
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of version 2 of the GNU General Public License
  6. as published by the Free Software Foundation.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License (version 2) for more details.
  11. You should have received a copy of the GNU General Public License (version 2)
  12. along with this program; if not, write to the Free Software Foundation,
  13. Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  14. */
  15. #include "Mutex.h"
  16. Mutex::Mutex(){
  17. #ifdef WINDOWS
  18. InitializeCriticalSection(&mutex);
  19. #else
  20. pthread_mutex_init(&mutex,NULL);
  21. #endif
  22. };
  23. Mutex::~Mutex(){
  24. #ifdef WINDOWS
  25. DeleteCriticalSection(&mutex);
  26. #else
  27. pthread_mutex_destroy(&mutex);
  28. #endif
  29. };
  30. void Mutex::lock(){
  31. #ifdef WINDOWS
  32. EnterCriticalSection(&mutex);
  33. #else
  34. pthread_mutex_lock(&mutex);
  35. #endif
  36. };
  37. void Mutex::unlock(){
  38. #ifdef WINDOWS
  39. LeaveCriticalSection(&mutex);
  40. #else
  41. pthread_mutex_unlock(&mutex);
  42. #endif
  43. };