Browse Source

Use a mutex to make jack_client_open/jack_client_close thread safe, remove use of jack_init/jack_uninit.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2968 0c269be4-1314-0410-8aa9-9f06e86f4224
tags/1.90
sletz 17 years ago
parent
commit
28ef03b879
8 changed files with 34 additions and 94 deletions
  1. +4
    -0
      ChangeLog
  2. +1
    -1
      common/JackAPI.cpp
  3. +0
    -5
      common/JackConstants.h
  4. +4
    -79
      common/JackGlobals.cpp
  5. +3
    -0
      common/JackGlobals.h
  6. +10
    -3
      common/JackLibAPI.cpp
  7. +11
    -5
      common/JackServerAPI.cpp
  8. +1
    -1
      windows/JackWinMutex.h

+ 4
- 0
ChangeLog View File

@@ -23,6 +23,10 @@ Michael Voigt
Jackdmp changes log Jackdmp changes log
--------------------------- ---------------------------


2008-10-09 Stephane Letz <letz@grame.fr>
* Use a mutex to make jack_client_open/jack_client_close thread safe, remove use of jack_init/jack_uninit.

2008-10-08 Stephane Letz <letz@grame.fr> 2008-10-08 Stephane Letz <letz@grame.fr>
* Fix a SMP related bug introduced in rev 2957 : remove the __SMP__ flag and define LOCK for SMP in all cases. * Fix a SMP related bug introduced in rev 2957 : remove the __SMP__ flag and define LOCK for SMP in all cases.


+ 1
- 1
common/JackAPI.cpp View File

@@ -390,7 +390,7 @@ EXPORT const char* jack_port_type(const jack_port_t* port)
} }
} }


EXPORT jack_port_type_id_t jack_port_type_id (const jack_port_t *port)
EXPORT jack_port_type_id_t jack_port_type_id(const jack_port_t *port)
{ {
#ifdef __CLIENTDEBUG__ #ifdef __CLIENTDEBUG__
JackLibGlobals::CheckContext(); JackLibGlobals::CheckContext();


+ 0
- 5
common/JackConstants.h View File

@@ -24,9 +24,6 @@
#include "config.h" #include "config.h"
#endif #endif


//namespace Jack
//{

#define VERSION "1.90" #define VERSION "1.90"


#define BUFFER_SIZE_MAX 8192 #define BUFFER_SIZE_MAX 8192
@@ -91,6 +88,4 @@
#define EMPTY 0xFFFD #define EMPTY 0xFFFD
#define FREE 0xFFFC #define FREE 0xFFFC


//} // end of namespace

#endif #endif

+ 4
- 79
common/JackGlobals.cpp View File

@@ -19,85 +19,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


#include "JackGlobals.h" #include "JackGlobals.h"


static bool gKeyRealtimeInitialized = false;
static bool g_key_log_function_initialized = false;

jack_tls_key gRealTime; jack_tls_key gRealTime;
jack_tls_key g_key_log_function;

// Initialisation at library load time
#ifdef WIN32

static void jack_init()
{
if (!gKeyRealtimeInitialized) {
gKeyRealtimeInitialized = jack_tls_allocate_key(&gRealTime);
}
if (!g_key_log_function_initialized)
g_key_log_function_initialized = jack_tls_allocate_key(&g_key_log_function);
}

static void jack_uninit()
{
if (gKeyRealtimeInitialized) {
jack_tls_free_key(gRealTime);
gKeyRealtimeInitialized = false;
}
if (g_key_log_function_initialized) {
jack_tls_free_key(g_key_log_function);
g_key_log_function_initialized = false;
}
}

#ifdef __cplusplus
extern "C"
{
#endif
static bool gKeyRealtimeInitialized = jack_tls_allocate_key(&gRealTime);


BOOL WINAPI DllEntryPoint(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason) {
case DLL_PROCESS_ATTACH:
jack_init();
break;
case DLL_PROCESS_DETACH:
jack_uninit();
break;
}
return TRUE;
}

#ifdef __cplusplus
}
#endif

#else

__attribute__ ((constructor))
static void jack_init()
{
if (!gKeyRealtimeInitialized) {
gKeyRealtimeInitialized = jack_tls_allocate_key(&gRealTime);
}
if (!g_key_log_function_initialized)
g_key_log_function_initialized = jack_tls_allocate_key(&g_key_log_function);
}

__attribute__ ((destructor))
static void jack_uninit()
{
if (gKeyRealtimeInitialized) {
jack_tls_free_key(gRealTime);
gKeyRealtimeInitialized = false;
}
if (g_key_log_function_initialized) {
jack_tls_free_key(g_key_log_function);
g_key_log_function_initialized = false;
}
}
jack_tls_key g_key_log_function;
static bool g_key_log_function_initialized = jack_tls_allocate_key(&g_key_log_function);


#endif
JackMutex* gOpenMutex = new JackMutex();

+ 3
- 0
common/JackGlobals.h View File

@@ -22,7 +22,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


#include "JackPlatformPlug.h" #include "JackPlatformPlug.h"


using namespace Jack;

extern jack_tls_key gRealTime; extern jack_tls_key gRealTime;
extern jack_tls_key g_key_log_function; extern jack_tls_key g_key_log_function;
extern JackMutex* gOpenMutex;


#endif #endif

+ 10
- 3
common/JackLibAPI.cpp View File

@@ -27,6 +27,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "JackTools.h" #include "JackTools.h"
#include "JackSystemDeps.h" #include "JackSystemDeps.h"
#include "JackServerLaunch.h" #include "JackServerLaunch.h"
#include <assert.h>


using namespace Jack; using namespace Jack;


@@ -112,27 +113,33 @@ EXPORT jack_client_t* jack_client_open_aux(const char* ext_client_name, jack_opt


EXPORT jack_client_t* jack_client_open(const char* ext_client_name, jack_options_t options, jack_status_t* status, ...) EXPORT jack_client_t* jack_client_open(const char* ext_client_name, jack_options_t options, jack_status_t* status, ...)
{ {
assert(gOpenMutex);
gOpenMutex->Lock();
va_list ap; va_list ap;
va_start(ap, status); va_start(ap, status);
jack_client_t* res = jack_client_open_aux(ext_client_name, options, status, ap); jack_client_t* res = jack_client_open_aux(ext_client_name, options, status, ap);
va_end(ap); va_end(ap);
gOpenMutex->Unlock();
return res; return res;
} }


EXPORT int jack_client_close(jack_client_t* ext_client) EXPORT int jack_client_close(jack_client_t* ext_client)
{ {
assert(gOpenMutex);
gOpenMutex->Lock();
int res = -1;
jack_log("jack_client_close"); jack_log("jack_client_close");
JackClient* client = (JackClient*)ext_client; JackClient* client = (JackClient*)ext_client;
if (client == NULL) { if (client == NULL) {
jack_error("jack_client_close called with a NULL client"); jack_error("jack_client_close called with a NULL client");
return -1;
} else { } else {
int res = client->Close();
res = client->Close();
delete client; delete client;
JackLibGlobals::Destroy(); // jack library destruction JackLibGlobals::Destroy(); // jack library destruction
jack_log("jack_client_close res = %d", res); jack_log("jack_client_close res = %d", res);
return res;
} }
gOpenMutex->Unlock();
return res;
} }


EXPORT int jack_get_client_pid(const char *name) EXPORT int jack_get_client_pid(const char *name)


+ 11
- 5
common/JackServerAPI.cpp View File

@@ -49,7 +49,7 @@ extern "C"
using namespace Jack; using namespace Jack;


// beware!!! things can go nasty if one client is started with JackNoStartServer and another without it // beware!!! things can go nasty if one client is started with JackNoStartServer and another without it
bool g_nostart;
static bool g_nostart;


EXPORT jack_client_t* jack_client_open_aux(const char* ext_client_name, jack_options_t options, jack_status_t* status, va_list ap) EXPORT jack_client_t* jack_client_open_aux(const char* ext_client_name, jack_options_t options, jack_status_t* status, va_list ap)
{ {
@@ -115,29 +115,35 @@ EXPORT jack_client_t* jack_client_open_aux(const char* ext_client_name, jack_opt


EXPORT jack_client_t* jack_client_open(const char* ext_client_name, jack_options_t options, jack_status_t* status, ...) EXPORT jack_client_t* jack_client_open(const char* ext_client_name, jack_options_t options, jack_status_t* status, ...)
{ {
assert(gOpenMutex);
gOpenMutex->Lock();
va_list ap; va_list ap;
va_start(ap, status); va_start(ap, status);
jack_client_t* res = jack_client_open_aux(ext_client_name, options, status, ap);
jack_client_t* res = jack_client_open_aux(ext_client_name, options, status, ap);
va_end(ap); va_end(ap);
gOpenMutex->Unlock();
return res; return res;
} }


EXPORT int jack_client_close(jack_client_t* ext_client) EXPORT int jack_client_close(jack_client_t* ext_client)
{ {
assert(gOpenMutex);
gOpenMutex->Lock();
int res = -1;
jack_log("jack_client_close"); jack_log("jack_client_close");
JackClient* client = (JackClient*)ext_client; JackClient* client = (JackClient*)ext_client;
if (client == NULL) { if (client == NULL) {
jack_error("jack_client_close called with a NULL client"); jack_error("jack_client_close called with a NULL client");
return -1;
} else { } else {
int res = client->Close();
res = client->Close();
delete client; delete client;
if (!g_nostart) { if (!g_nostart) {
JackServerGlobals::Destroy(); // jack server destruction JackServerGlobals::Destroy(); // jack server destruction
} }
jack_log("jack_client_close res = %d", res); jack_log("jack_client_close res = %d", res);
return res;
} }
gOpenMutex->Unlock();
return res;
} }


EXPORT int jack_get_client_pid(const char *name) EXPORT int jack_get_client_pid(const char *name)


+ 1
- 1
windows/JackWinMutex.h View File

@@ -55,7 +55,7 @@ class JackWinMutex


bool Trylock() bool Trylock()
{ {
return (WAIT_OBJECT_0 == WaitForSingleObject(fMutex, 0));
return (WAIT_OBJECT_0 == WaitForSingleObject(fMutex, 0));
} }


void Unlock() void Unlock()


Loading…
Cancel
Save