Jack2  1.9.11-RC1
JackLinuxFutex.h
1 /*
2 Copyright (C) 2004-2008 Grame
3 Copyright (C) 2016 Filipe Coelho
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14 
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 */
20 
21 #ifndef __JackLinuxFutex__
22 #define __JackLinuxFutex__
23 
24 #include "JackSynchro.h"
25 #include "JackCompilerDeps.h"
26 #include <stddef.h>
27 
28 namespace Jack
29 {
30 
41 class SERVER_EXPORT JackLinuxFutex : public detail::JackSynchro
42 {
43 
44  private:
45  struct FutexData {
46  int futex; // futex, needs to be 1st member
47  bool internal; // current internal state
48  bool wasInternal; // initial internal state, only changes in allocate
49  bool needsChange; // change state on next wait call
50  int externalCount; // how many external clients have connected
51  };
52 
53  int fSharedMem;
54  FutexData* fFutex;
55  bool fPrivate;
56 
57  protected:
58 
59  void BuildName(const char* name, const char* server_name, char* res, int size);
60 
61  public:
62 
63  JackLinuxFutex():JackSynchro(), fSharedMem(-1), fFutex(NULL), fPrivate(false)
64  {}
65 
66  bool Signal();
67  bool SignalAll();
68  bool Wait();
69  bool TimedWait(long usec);
70 
71  bool Allocate(const char* name, const char* server_name, int value, bool internal = false);
72  bool Connect(const char* name, const char* server_name);
73  bool ConnectInput(const char* name, const char* server_name);
74  bool ConnectOutput(const char* name, const char* server_name);
75  bool Disconnect();
76  void Destroy();
77 
78  void MakePrivate(bool priv);
79 };
80 
81 } // end of namespace
82 
83 
84 #endif
85 
Inter process synchronization using POSIX semaphore.
An inter process synchronization primitive.
Definition: JackSynchro.h:35
Inter process synchronization using Linux futex.