Error message only when initialization hadn't been done

In a multithread environment, sogo_backend_init is registering the thread
only for the first one that calls this function, then the others threads
(even if they call sogo_backend_init) won't be registered because
moduleInitialized was YES.

We just want to ensure sogo_backend_init is called at least once (per process,
not per thread).
pull/49/head
Jesús García Sáez 2014-07-02 10:40:05 +02:00 committed by Julio García
parent 41f2e917e7
commit 7f2ee7be89
1 changed files with 8 additions and 9 deletions

View File

@ -53,18 +53,17 @@
static Class MAPIStoreContextK = Nil;
static BOOL leakDebugging = NO;
static BOOL initialization_done = NO;
#define NS_CURRENT_THREAD_REGISTER() \
BOOL __nsrct_thread_registered = GSRegisterCurrentThread(); \
if (__nsrct_thread_registered) { \
DEBUG(0, ("[SOGo: %s:%d] Current Thread not registered! You should call sogo_backend_init() first. Current thread: %p, pid: %d\n", \
if (!initialization_done) { \
DEBUG(0, ("[SOGo: %s:%d] You should call sogo_backend_init() first. Current thread: %p, pid: %d\n", \
__FUNCTION__, __LINE__, GSCurrentThread(), getpid())); \
}
#define NS_CURRENT_THREAD_TRY_UNREGISTER() \
if (__nsrct_thread_registered) { \
DEBUG(0, ("[SOGo: %s:%d] Unregister current thread. You should have called sogo_backend_init(). Current thread: %p, pid: %d\n", \
__FUNCTION__, __LINE__, GSCurrentThread(), getpid())); \
GSUnregisterCurrentThread(); \
GSUnregisterCurrentThread(); \
}
#define TRYCATCH_START @try {
@ -140,15 +139,15 @@ sogo_backend_init (void)
Class MAPIApplicationK;
NSUserDefaults *ud;
SoProductRegistry *registry;
static BOOL moduleInitialized = NO;
char *argv[] = { SAMBA_PREFIX "/sbin/samba", NULL };
if (moduleInitialized) {
GSRegisterCurrentThread();
if (initialization_done) {
DEBUG(0, ("SOGo backend already initialized.\n"));
return MAPISTORE_SUCCESS;
}
GSRegisterCurrentThread ();
pool = [NSAutoreleasePool new];
/* Here we work around a bug in GNUstep which decodes XML user
@ -191,7 +190,7 @@ sogo_backend_init (void)
[pool release];
DEBUG(0, ("[SOGo: %s:%d] backend init SUCCESS. Current thread: %p, pid: %d\n", __FUNCTION__, __LINE__, GSCurrentThread(), getpid()));
moduleInitialized = YES;
initialization_done = YES;
return MAPISTORE_SUCCESS;
}