jack2 codebase
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.

71 lines
1.5KB

  1. /*
  2. Copyright (C) 2006 Grame
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. This library 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 GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with this library; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  14. Grame Research Laboratory, 9 rue du Garet, 69001 Lyon - France
  15. grame@grame.fr
  16. */
  17. #ifndef __JackWinMutex__
  18. #define __JackWinMutex__
  19. #include <windows.h>
  20. namespace Jack
  21. {
  22. /*!
  23. \brief Mutex abstraction.
  24. */
  25. class JackWinMutex
  26. {
  27. private:
  28. HANDLE fMutex;
  29. public:
  30. JackWinMutex()
  31. {
  32. // In recursive mode by default
  33. fMutex = (HANDLE)CreateMutex(0, FALSE, 0);
  34. }
  35. ~JackWinMutex()
  36. {
  37. CloseHandle(fMutex);
  38. }
  39. void Lock()
  40. {
  41. DWORD dwWaitResult = WaitForSingleObject(fMutex, INFINITE);
  42. }
  43. bool Trylock()
  44. {
  45. return (WAIT_OBJECT_0 == WaitForSingleObject(fMutex, 0));
  46. }
  47. void Unlock()
  48. {
  49. ReleaseMutex(fMutex);
  50. }
  51. };
  52. } // namespace
  53. #endif