Browse Source

Protect shared fSynchroTable access with a mutex.

tags/v1.9.10
Stephane Letz 12 years ago
parent
commit
e111f2ac8f
8 changed files with 20 additions and 9 deletions
  1. +3
    -0
      common/JackClient.cpp
  2. +1
    -0
      common/JackGlobals.cpp
  3. +2
    -1
      common/JackGlobals.h
  4. +11
    -2
      common/JackLibClient.cpp
  5. +0
    -1
      common/JackServerGlobals.cpp
  6. +0
    -1
      common/JackServerGlobals.h
  7. +0
    -1
      posix/JackSocketServerNotifyChannel.cpp
  8. +3
    -3
      windows/JackAtomic_os.h

+ 3
- 0
common/JackClient.cpp View File

@@ -117,7 +117,10 @@ int JackClient::Close()
} }


fChannel->Close(); fChannel->Close();
assert(JackGlobals::fSynchroMutex);
JackGlobals::fSynchroMutex->Lock();
fSynchroTable[GetClientControl()->fRefNum].Disconnect(); fSynchroTable[GetClientControl()->fRefNum].Disconnect();
JackGlobals::fSynchroMutex->Unlock();
JackGlobals::fClientTable[GetClientControl()->fRefNum] = NULL; JackGlobals::fClientTable[GetClientControl()->fRefNum] = NULL;
return result; return result;
} }


+ 1
- 0
common/JackGlobals.cpp View File

@@ -34,6 +34,7 @@ jack_tls_key JackGlobals::fKeyLogFunction;
static bool fKeyLogFunctionInitialized = jack_tls_allocate_key(&JackGlobals::fKeyLogFunction); static bool fKeyLogFunctionInitialized = jack_tls_allocate_key(&JackGlobals::fKeyLogFunction);


JackMutex* JackGlobals::fOpenMutex = new JackMutex(); JackMutex* JackGlobals::fOpenMutex = new JackMutex();
JackMutex* JackGlobals::fSynchroMutex = new JackMutex();
volatile bool JackGlobals::fServerRunning = false; volatile bool JackGlobals::fServerRunning = false;
JackClient* JackGlobals::fClientTable[CLIENT_NUM] = {}; JackClient* JackGlobals::fClientTable[CLIENT_NUM] = {};




+ 2
- 1
common/JackGlobals.h View File

@@ -41,8 +41,9 @@ struct JackGlobals {
static jack_tls_key fNotificationThread; static jack_tls_key fNotificationThread;
static jack_tls_key fKeyLogFunction; static jack_tls_key fKeyLogFunction;
static JackMutex* fOpenMutex; static JackMutex* fOpenMutex;
static JackMutex* fSynchroMutex;
static volatile bool fServerRunning; static volatile bool fServerRunning;
static JackClient* fClientTable[];
static JackClient* fClientTable[CLIENT_NUM];
static bool fVerbose; static bool fVerbose;
#ifndef WIN32 #ifndef WIN32
static jack_thread_creator_t fJackThreadCreator; static jack_thread_creator_t fJackThreadCreator;


+ 11
- 2
common/JackLibClient.cpp View File

@@ -84,6 +84,7 @@ JackLibClient::~JackLibClient()
int JackLibClient::Open(const char* server_name, const char* name, int uuid, jack_options_t options, jack_status_t* status) int JackLibClient::Open(const char* server_name, const char* name, int uuid, jack_options_t options, jack_status_t* status)
{ {
int shared_engine, shared_client, shared_graph, result; int shared_engine, shared_client, shared_graph, result;
bool res;
jack_log("JackLibClient::Open name = %s", name); jack_log("JackLibClient::Open name = %s", name);


strncpy(fServerName, server_name, sizeof(fServerName)); strncpy(fServerName, server_name, sizeof(fServerName));
@@ -122,7 +123,11 @@ int JackLibClient::Open(const char* server_name, const char* name, int uuid, jac
SetupDriverSync(false); SetupDriverSync(false);


// Connect shared synchro : the synchro must be usable in I/O mode when several clients live in the same process // Connect shared synchro : the synchro must be usable in I/O mode when several clients live in the same process
if (!fSynchroTable[GetClientControl()->fRefNum].Connect(name_res, fServerName)) {
assert(JackGlobals::fSynchroMutex);
JackGlobals::fSynchroMutex->Lock();
res = fSynchroTable[GetClientControl()->fRefNum].Connect(name_res, fServerName);
JackGlobals::fSynchroMutex->Unlock();
if (!res) {
jack_error("Cannot ConnectSemaphore %s client", name_res); jack_error("Cannot ConnectSemaphore %s client", name_res);
goto error; goto error;
} }
@@ -145,6 +150,8 @@ error:
int JackLibClient::ClientNotifyImp(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2) int JackLibClient::ClientNotifyImp(int refnum, const char* name, int notify, int sync, const char* message, int value1, int value2)
{ {
int res = 0; int res = 0;
assert(JackGlobals::fSynchroMutex);
JackGlobals::fSynchroMutex->Lock();


// Done all time // Done all time
switch (notify) { switch (notify) {
@@ -157,11 +164,13 @@ int JackLibClient::ClientNotifyImp(int refnum, const char* name, int notify, int


case kRemoveClient: case kRemoveClient:
jack_log("JackClient::RemoveClient name = %s, ref = %ld ", name, refnum); jack_log("JackClient::RemoveClient name = %s, ref = %ld ", name, refnum);
if (GetClientControl() && strcmp(GetClientControl()->fName, name) != 0)
if (GetClientControl() && strcmp(GetClientControl()->fName, name) != 0) {
res = fSynchroTable[refnum].Disconnect() ? 0 : -1; res = fSynchroTable[refnum].Disconnect() ? 0 : -1;
}
break; break;
} }


JackGlobals::fSynchroMutex->Unlock();
return res; return res;
} }




+ 0
- 1
common/JackServerGlobals.cpp View File

@@ -31,7 +31,6 @@ namespace Jack


JackServer* JackServerGlobals::fInstance; JackServer* JackServerGlobals::fInstance;
unsigned int JackServerGlobals::fUserCount; unsigned int JackServerGlobals::fUserCount;
int JackServerGlobals::fRTNotificationSocket;
std::map<std::string, JackDriverInfo*> JackServerGlobals::fSlavesList; std::map<std::string, JackDriverInfo*> JackServerGlobals::fSlavesList;
std::map<std::string, int> JackServerGlobals::fInternalsList; std::map<std::string, int> JackServerGlobals::fInternalsList;




+ 0
- 1
common/JackServerGlobals.h View File

@@ -39,7 +39,6 @@ struct SERVER_EXPORT JackServerGlobals
{ {
static JackServer* fInstance; static JackServer* fInstance;
static unsigned int fUserCount; static unsigned int fUserCount;
static int fRTNotificationSocket; // For debugging purpose
static std::map<std::string, JackDriverInfo*> fSlavesList; static std::map<std::string, JackDriverInfo*> fSlavesList;
static std::map<std::string, int> fInternalsList; static std::map<std::string, int> fInternalsList;




+ 0
- 1
posix/JackSocketServerNotifyChannel.cpp View File

@@ -34,7 +34,6 @@ int JackSocketServerNotifyChannel::Open(const char* server_name)
return -1; return -1;
} else { } else {
fRequestSocket.SetNonBlocking(true); fRequestSocket.SetNonBlocking(true);
JackServerGlobals::fRTNotificationSocket = fRequestSocket.GetFd();
return 0; return 0;
} }
} }


+ 3
- 3
windows/JackAtomic_os.h View File

@@ -64,9 +64,9 @@ static inline char CAS(volatile UInt32 value, UInt32 newvalue, volatile void* ad
"# CAS \n\t" "# CAS \n\t"
LOCK "cmpxchg %2, (%1) \n\t" LOCK "cmpxchg %2, (%1) \n\t"
"sete %0 \n\t" "sete %0 \n\t"
: "=a" (ret)
: "c" (addr), "d" (newvalue), "a" (value)
);
: "=a" (ret)
: "c" (addr), "d" (newvalue), "a" (value)
);
return ret; return ret;
} }




Loading…
Cancel
Save