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.

JackLinuxFutex.h 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. Copyright (C) 2004-2008 Grame
  3. Copyright (C) 2016 Filipe Coelho
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. #ifndef __JackLinuxFutex__
  17. #define __JackLinuxFutex__
  18. #include "JackSynchro.h"
  19. #include "JackCompilerDeps.h"
  20. #include <stddef.h>
  21. namespace Jack
  22. {
  23. /*!
  24. \brief Inter process synchronization using Linux futex.
  25. Based on the JackPosixSemaphore class.
  26. Adapted to work with linux futex to be as light as possible and also work in multiple architectures.
  27. Adds a new 'MakePrivate' function that makes the sync happen in the local process only,
  28. making it even faster for internal clients.
  29. */
  30. class SERVER_EXPORT JackLinuxFutex : public detail::JackSynchro
  31. {
  32. private:
  33. struct FutexData {
  34. int futex; // futex, needs to be 1st member
  35. bool internal; // current internal state
  36. bool wasInternal; // initial internal state, only changes in allocate
  37. bool needsChange; // change state on next wait call
  38. int externalCount; // how many external clients have connected
  39. };
  40. int fSharedMem;
  41. FutexData* fFutex;
  42. bool fPrivate;
  43. bool fPromiscuous;
  44. int fPromiscuousGid;
  45. protected:
  46. void BuildName(const char* name, const char* server_name, char* res, int size);
  47. public:
  48. JackLinuxFutex();
  49. bool Signal();
  50. bool SignalAll();
  51. bool Wait();
  52. bool TimedWait(long usec);
  53. bool Allocate(const char* name, const char* server_name, int value, bool internal = false);
  54. bool Connect(const char* name, const char* server_name);
  55. bool ConnectInput(const char* name, const char* server_name);
  56. bool ConnectOutput(const char* name, const char* server_name);
  57. bool Disconnect();
  58. void Destroy();
  59. void MakePrivate(bool priv);
  60. };
  61. } // end of namespace
  62. #endif