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.

96 lines
1.8KB

  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 __JackMutex__
  18. #define __JackMutex__
  19. #include <assert.h>
  20. #include "JackError.h"
  21. #include "JackPlatformPlug.h"
  22. namespace Jack
  23. {
  24. /*!
  25. \brief Base class for "lockable" objects.
  26. */
  27. class JackLockAble
  28. {
  29. protected:
  30. JackMutex fMutex;
  31. JackLockAble(const char* name = NULL)
  32. :fMutex(name)
  33. {}
  34. ~JackLockAble()
  35. {}
  36. public:
  37. bool Lock()
  38. {
  39. return fMutex.Lock();
  40. }
  41. bool Trylock()
  42. {
  43. return fMutex.Trylock();
  44. }
  45. bool Unlock()
  46. {
  47. return fMutex.Unlock();
  48. }
  49. };
  50. class JackLock
  51. {
  52. private:
  53. JackLockAble* fObj;
  54. public:
  55. JackLock(JackLockAble* obj): fObj(obj)
  56. {
  57. fObj->Lock();
  58. }
  59. JackLock(const JackLockAble* obj): fObj((JackLockAble*)obj)
  60. {
  61. fObj->Lock();
  62. }
  63. ~JackLock()
  64. {
  65. fObj->Unlock();
  66. }
  67. };
  68. } // namespace
  69. #endif