diff options
author | Ingo Huerner <ingo.huerner@xse.de> | 2014-11-18 11:41:29 +0100 |
---|---|---|
committer | Ingo Huerner <ingo.huerner@xse.de> | 2014-11-18 11:41:29 +0100 |
commit | 0c1d8f050ea759f7547d5ce1b62601a061280c98 (patch) | |
tree | d0822f99e4786512a792ca81c344bee16dda36c7 | |
parent | 441b3ce710ec6b7f1e6360cdf29e5c4243af9f1e (diff) | |
download | persistence-client-library-0c1d8f050ea759f7547d5ce1b62601a061280c98.tar.gz |
Make pclInitLibrary multicore safe
-rw-r--r-- | src/persistence_client_library.c | 273 | ||||
-rw-r--r-- | src/persistence_client_library_data_organization.c | 2 | ||||
-rw-r--r-- | src/persistence_client_library_data_organization.h | 6 | ||||
-rw-r--r-- | src/persistence_client_library_file.c | 24 | ||||
-rw-r--r-- | src/persistence_client_library_key.c | 22 |
5 files changed, 178 insertions, 149 deletions
diff --git a/src/persistence_client_library.c b/src/persistence_client_library.c index 538f3c6..7dff4f5 100644 --- a/src/persistence_client_library.c +++ b/src/persistence_client_library.c @@ -41,6 +41,7 @@ #include <stdlib.h> #include <dlfcn.h> #include <dbus/dbus.h> +#include <pthread.h> @@ -54,6 +55,8 @@ static int gShutdownMode = 0; /// global shutdown cancel counter static int gCancelCounter = 0; +static pthread_mutex_t gInitMutex = PTHREAD_MUTEX_INITIALIZER; + #if USE_APPCHECK /// global flag static int gAppCheckFlag = -1; @@ -66,6 +69,9 @@ int customAsyncInitClbk(int errcode) return 1; } +// forward declaration +static int private_pclInitLibrary(const char* appName, int shutdownMode); +static int private_pclDeinitLibrary(void); /* security check for valid application: @@ -120,100 +126,114 @@ int pclInitLibrary(const char* appName, int shutdownMode) { int rval = 1; + pthread_mutex_lock(&gInitMutex); + if(gPclInitCounter == 0) + { + DLT_REGISTER_CONTEXT(gPclDLTContext,"PCL","Context for persistence client library logging"); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclInitLibrary => I N I T Persistence Client Library - "), DLT_STRING(appName), + DLT_STRING("- init counter: "), DLT_INT(gPclInitCounter) ); + + rval = private_pclInitLibrary(appName, shutdownMode); + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclInitLibrary - I N I T Persistence Client Library - "), DLT_STRING(gAppId), + DLT_STRING("- ONLY INCREMENT init counter: "), DLT_INT(gPclInitCounter) ); + } + + gPclInitCounter++; // increment after private init, otherwise atomic access is too early + pthread_mutex_unlock(&gInitMutex); + + return rval; +} + + + +static int private_pclInitLibrary(const char* appName, int shutdownMode) +{ + int rval = 1; + #if USE_XSTRACE_PERS xsm_send_user_event("%s - %d\n", __FUNCTION__, __LINE__); #endif - if(gPclInitialized == PCLnotInitialized) - { - gShutdownMode = shutdownMode; - DLT_REGISTER_CONTEXT(gPclDLTContext,"PCL","Context for persistence client library logging"); - DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclInitLibrary => I N I T Persistence Client Library - "), DLT_STRING(appName), - DLT_STRING("- init counter: "), DLT_INT(gPclInitialized) ); + gShutdownMode = shutdownMode; - char blacklistPath[DbPathMaxLen] = {0}; + char blacklistPath[DbPathMaxLen] = {0}; - doInitAppcheck(appName); // check if we have a trusted application + doInitAppcheck(appName); // check if we have a trusted application #if USE_FILECACHE - DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("Using the filecache!!!")); - pfcInitCache(appName); + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("Using the filecache!!!")); + pfcInitCache(appName); #endif - pthread_mutex_lock(&gDbusPendingRegMtx); // block until pending received + pthread_mutex_lock(&gDbusPendingRegMtx); // block until pending received - // Assemble backup blacklist path - sprintf(blacklistPath, "%s%s/%s", CACHEPREFIX, appName, gBackupFilename); + // Assemble backup blacklist path + sprintf(blacklistPath, "%s%s/%s", CACHEPREFIX, appName, gBackupFilename); - if(readBlacklistConfigFile(blacklistPath) == -1) - { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclInitLibrary - failed to access blacklist:"), DLT_STRING(blacklistPath)); - } + if(readBlacklistConfigFile(blacklistPath) == -1) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclInitLibrary - failed to access blacklist:"), DLT_STRING(blacklistPath)); + } #if USE_XSTRACE_PERS - xsm_send_user_event("%s - %d\n", __FUNCTION__, __LINE__); + xsm_send_user_event("%s - %d\n", __FUNCTION__, __LINE__); #endif - if(setup_dbus_mainloop() == -1) - { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary - Failed to setup main loop")); - pthread_mutex_unlock(&gDbusPendingRegMtx); - return EPERS_DBUS_MAINLOOP; - } + if(setup_dbus_mainloop() == -1) + { + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary - Failed to setup main loop")); + pthread_mutex_unlock(&gDbusPendingRegMtx); + return EPERS_DBUS_MAINLOOP; + } #if USE_XSTRACE_PERS - xsm_send_user_event("%s - %d\n", __FUNCTION__, __LINE__); + xsm_send_user_event("%s - %d\n", __FUNCTION__, __LINE__); #endif - if(gShutdownMode != PCL_SHUTDOWN_TYPE_NONE) - { - // register for lifecycle dbus messages - if(register_lifecycle(shutdownMode) == -1) - { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary => Failed to register to lifecycle dbus interface")); - pthread_mutex_unlock(&gDbusPendingRegMtx); - return EPERS_REGISTER_LIFECYCLE; - } - } + if(gShutdownMode != PCL_SHUTDOWN_TYPE_NONE) + { + // register for lifecycle dbus messages + if(register_lifecycle(shutdownMode) == -1) + { + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary => Failed to register to lifecycle dbus interface")); + pthread_mutex_unlock(&gDbusPendingRegMtx); + return EPERS_REGISTER_LIFECYCLE; + } + } #if USE_PASINTERFACE - DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("PAS interface is enabled!!")); - if(register_pers_admin_service() == -1) - { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary - Failed to register to pers admin dbus interface")); - pthread_mutex_unlock(&gDbusPendingRegMtx); - return EPERS_REGISTER_ADMIN; - } - else - { - DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclInitLibrary - Successfully established IPC protocol for PCL.")); - } + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("PAS interface is enabled!!")); + if(register_pers_admin_service() == -1) + { + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclInitLibrary - Failed to register to pers admin dbus interface")); + pthread_mutex_unlock(&gDbusPendingRegMtx); + return EPERS_REGISTER_ADMIN; + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclInitLibrary - Successfully established IPC protocol for PCL.")); + } #else - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("PAS interface is not enabled, enable with \"./configure --enable-pasinterface\"")); + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("PAS interface is not enabled, enable with \"./configure --enable-pasinterface\"")); #endif - // load custom plugins - if(load_custom_plugins(customAsyncInitClbk) < 0) - { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("Failed to load custom plugins")); - } + // load custom plugins + if(load_custom_plugins(customAsyncInitClbk) < 0) + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("Failed to load custom plugins")); + } - // initialize keyHandle array - init_key_handle_array(); + // initialize keyHandle array + init_key_handle_array(); - pers_unlock_access(); + pers_unlock_access(); - // assign application name - strncpy(gAppId, appName, MaxAppNameLen); - gAppId[MaxAppNameLen-1] = '\0'; + // assign application name + strncpy(gAppId, appName, MaxAppNameLen); + gAppId[MaxAppNameLen-1] = '\0'; - gPclInitialized++; - } - else if(gPclInitialized >= PCLinitialized) - { - gPclInitialized++; // increment init counter - DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclInitLibrary - I N I T Persistence Client Library - "), DLT_STRING(gAppId), - DLT_STRING("- ONLY INCREMENT init counter: "), DLT_INT(gPclInitialized) ); - } #if USE_XSTRACE_PERS xsm_send_user_event("%s - %d\n", __FUNCTION__, __LINE__); @@ -223,87 +243,98 @@ int pclInitLibrary(const char* appName, int shutdownMode) } - int pclDeinitLibrary(void) { + int rval = 1; + + pthread_mutex_lock(&gInitMutex); + + if(gPclInitCounter == 1) + { + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclDeinitLibrary - D E I N I T client library - "), DLT_STRING(gAppId), + DLT_STRING("- init counter: "), DLT_INT(gPclInitCounter)); + rval = private_pclDeinitLibrary(); + + gPclInitCounter--; // decrement init counter + DLT_UNREGISTER_CONTEXT(gPclDLTContext); + } + else if(gPclInitCounter > 1) + { + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclDeinitLibrary - D E I N I T client library - "), DLT_STRING(gAppId), + DLT_STRING("- ONLY DECREMENT init counter: "), DLT_INT(gPclInitCounter)); + gPclInitCounter--; // decrement init counter + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclDeinitLibrary - D E I N I T client library - "), DLT_STRING(gAppId), + DLT_STRING("- NOT INITIALIZED: ")); + rval = EPERS_NOT_INITIALIZED; + } + + pthread_mutex_unlock(&gInitMutex); + + return rval; +} + +static int private_pclDeinitLibrary(void) +{ int i = 0, rval = 1; #if USE_XSTRACE_PERS xsm_send_user_event("%s - %d\n", __FUNCTION__, __LINE__); #endif - if(gPclInitialized == PCLinitialized) - { - int* retval; - MainLoopData_u data; - data.message.cmd = (uint32_t)CMD_QUIT; - data.message.string[0] = '\0'; // no string parameter, set to 0 - - DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclDeinitLibrary - D E I N I T client library - "), DLT_STRING(gAppId), - DLT_STRING("- init counter: "), DLT_INT(gPclInitialized)); + int* retval; + MainLoopData_u data; + data.message.cmd = (uint32_t)CMD_QUIT; + data.message.string[0] = '\0'; // no string parameter, set to 0 - // unregister for lifecycle dbus messages - if(gShutdownMode != PCL_SHUTDOWN_TYPE_NONE) - rval = unregister_lifecycle(gShutdownMode); + // unregister for lifecycle dbus messages + if(gShutdownMode != PCL_SHUTDOWN_TYPE_NONE) + rval = unregister_lifecycle(gShutdownMode); #if USE_PASINTERFACE == 1 - rval = unregister_pers_admin_service(); - if(0 != rval) - { - DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclDeinitLibrary - Failed to de-initialize IPC protocol for PCL.")); - } - else - { - DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclDeinitLibrary - Successfully de-initialized IPC protocol for PCL.")); - } + rval = unregister_pers_admin_service(); + if(0 != rval) + { + DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("pclDeinitLibrary - Failed to de-initialize IPC protocol for PCL.")); + } + else + { + DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclDeinitLibrary - Successfully de-initialized IPC protocol for PCL.")); + } #endif - // unload custom client libraries - for(i=0; i<PersCustomLib_LastEntry; i++) + // unload custom client libraries + for(i=0; i<PersCustomLib_LastEntry; i++) + { + if(gPersCustomFuncs[i].custom_plugin_deinit != NULL) { - if(gPersCustomFuncs[i].custom_plugin_deinit != NULL) - { - // deinitialize plugin - gPersCustomFuncs[i].custom_plugin_deinit(); - // close library handle - dlclose(gPersCustomFuncs[i].handle); + // deinitialize plugin + gPersCustomFuncs[i].custom_plugin_deinit(); + // close library handle + dlclose(gPersCustomFuncs[i].handle); - invalidate_custom_plugin(i); - } + invalidate_custom_plugin(i); } + } - process_prepare_shutdown(Shutdown_Full); // close all db's and fd's and block access + process_prepare_shutdown(Shutdown_Full); // close all db's and fd's and block access - // send quit command to dbus mainloop - deliverToMainloop_NM(&data); + // send quit command to dbus mainloop + deliverToMainloop_NM(&data); - // wait until the dbus mainloop has ended - pthread_join(gMainLoopThread, (void**)&retval); + // wait until the dbus mainloop has ended + pthread_join(gMainLoopThread, (void**)&retval); - pthread_mutex_unlock(&gDbusPendingRegMtx); - pthread_mutex_unlock(&gDbusInitializedMtx); + pthread_mutex_unlock(&gDbusPendingRegMtx); + pthread_mutex_unlock(&gDbusInitializedMtx); - gPclInitialized = PCLnotInitialized; #if USE_FILECACHE pfcDeinitCache(); #endif - DLT_UNREGISTER_CONTEXT(gPclDLTContext); - } - else if(gPclInitialized > PCLinitialized) - { - DLT_LOG(gPclDLTContext, DLT_LOG_INFO, DLT_STRING("pclDeinitLibrary - D E I N I T client library - "), DLT_STRING(gAppId), - DLT_STRING("- ONLY DECREMENT init counter: "), DLT_INT(gPclInitialized)); - gPclInitialized--; // decrement init counter - } - else - { - DLT_LOG(gPclDLTContext, DLT_LOG_WARN, DLT_STRING("pclDeinitLibrary - D E I N I T client library - "), DLT_STRING(gAppId), - DLT_STRING("- NOT INITIALIZED: ")); - rval = EPERS_NOT_INITIALIZED; - } - #if USE_XSTRACE_PERS xsm_send_user_event("%s - %d\n", __FUNCTION__, __LINE__); diff --git a/src/persistence_client_library_data_organization.c b/src/persistence_client_library_data_organization.c index c2d26f5..28d9d9a 100644 --- a/src/persistence_client_library_data_organization.c +++ b/src/persistence_client_library_data_organization.c @@ -85,7 +85,7 @@ char gAppId[MaxAppNameLen] = { [0 ... MaxAppNameLen-1] = 0}; int gMaxKeyValDataSize = defaultMaxKeyValDataSize; -unsigned int gPclInitialized = PCLnotInitialized; +unsigned int gPclInitCounter = 0; DltContext gPclDLTContext; diff --git a/src/persistence_client_library_data_organization.h b/src/persistence_client_library_data_organization.h index 7e0fa72..b202472 100644 --- a/src/persistence_client_library_data_organization.h +++ b/src/persistence_client_library_data_organization.h @@ -119,10 +119,6 @@ enum _PersistenceConstantDef ResIsFile = 1, /// flag to indicate that access is not locked AccessNoLock = 1, - /// indication if PCL is not initialized - PCLnotInitialized = 0, - /// indication if PCL is initialized - PCLinitialized = 1, /// flag to identify if file will be closed FileClosed = 1, /// flag to identify if file has been opened @@ -257,7 +253,7 @@ extern int gMaxKeyValDataSize; extern DltContext gPclDLTContext; /// flag to indicate if client library has been initialized -extern unsigned int gPclInitialized; +extern unsigned int gPclInitCounter; /// change signal string diff --git a/src/persistence_client_library_file.c b/src/persistence_client_library_file.c index 3ea7670..0d038d8 100644 --- a/src/persistence_client_library_file.c +++ b/src/persistence_client_library_file.c @@ -75,7 +75,7 @@ int pclFileClose(int fd) //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileClose fd: "), DLT_INT(fd)); - if(gPclInitialized >= PCLinitialized) + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { if(doAppcheck() == 1) { @@ -101,9 +101,11 @@ int pclFileClose(int fd) } else { + fsync(fd); rval = close(fd); } #else + fsync(fd); rval = close(fd); #endif @@ -127,7 +129,7 @@ int pclFileGetSize(int fd) { int size = EPERS_NOT_INITIALIZED; - if(gPclInitialized >= PCLinitialized) + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { struct stat buf; @@ -169,7 +171,7 @@ void* pclFileMapData(void* addr, long size, long offset, int fd) #else //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileMapData fd: "), DLT_INT(fd)); - if(gPclInitialized >= PCLinitialized) + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked { @@ -190,7 +192,7 @@ int pclFileOpen(unsigned int ldbid, const char* resource_id, unsigned int user_n { int handle = EPERS_NOT_INITIALIZED; - if(gPclInitialized >= PCLinitialized) + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { int shared_DB = 0; int wantBackup = 1; @@ -380,7 +382,7 @@ int pclFileReadData(int fd, void * buffer, int buffer_size) int readSize = EPERS_NOT_INITIALIZED; //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileReadData fd: "), DLT_INT(fd)); - if(gPclInitialized >= PCLinitialized) + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { #if USE_FILECACHE if(get_file_cache_status(fd) == 1) @@ -406,7 +408,7 @@ int pclFileRemove(unsigned int ldbid, const char* resource_id, unsigned int user //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileReadData "), DLT_INT(ldbid), DLT_STRING(resource_id)); - if(gPclInitialized >= PCLinitialized) + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked { @@ -455,7 +457,7 @@ int pclFileSeek(int fd, long int offset, int whence) //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileSeek fd:"), DLT_INT(fd)); - if(gPclInitialized >= PCLinitialized) + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked { @@ -489,7 +491,7 @@ int pclFileUnmapData(void* address, long size) //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileUnmapData")); - if(gPclInitialized >= PCLinitialized) + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked { @@ -512,7 +514,7 @@ int pclFileWriteData(int fd, const void * buffer, int buffer_size) //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileWriteData fd:"), DLT_INT(fd)); - if(gPclInitialized >= PCLinitialized) + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { if(AccessNoLock != isAccessLocked() ) // check if access to persistent data is locked { @@ -581,7 +583,7 @@ int pclFileCreatePath(unsigned int ldbid, const char* resource_id, unsigned int { int handle = EPERS_NOT_INITIALIZED; - if(gPclInitialized >= PCLinitialized) + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { int shared_DB = 0; PersistenceInfo_s dbContext; @@ -734,7 +736,7 @@ int pclFileReleasePath(int pathHandle) //DLT_LOG(gDLTContext, DLT_LOG_INFO, DLT_STRING("pclFileClose fd: "), DLT_INT(fd)); - if(gPclInitialized >= PCLinitialized) + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { int permission = get_ossfile_permission(pathHandle); if(permission != -1) // permission is here also used for range check diff --git a/src/persistence_client_library_key.c b/src/persistence_client_library_key.c index 249c8e0..396f0b7 100644 --- a/src/persistence_client_library_key.c +++ b/src/persistence_client_library_key.c @@ -48,7 +48,7 @@ int pclKeyHandleOpen(unsigned int ldbid, const char* resource_id, unsigned int u int rval = 0; int handle = EPERS_NOT_INITIALIZED; - if(gPclInitialized >= PCLinitialized ) + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { if(doAppcheck() == 1) { @@ -95,7 +95,7 @@ int pclKeyHandleClose(int key_handle) { int rval = EPERS_NOT_INITIALIZED; - if(gPclInitialized >= PCLinitialized) + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { if(doAppcheck() == 1) { @@ -135,7 +135,7 @@ int pclKeyHandleGetSize(int key_handle) { int size = EPERS_NOT_INITIALIZED; - if(gPclInitialized >= PCLinitialized) + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { if(doAppcheck() == 1) { @@ -173,7 +173,7 @@ int pclKeyHandleReadData(int key_handle, unsigned char* buffer, int buffer_size) { int size = EPERS_NOT_INITIALIZED; - if(gPclInitialized >= PCLinitialized) + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { if(doAppcheck() == 1) { @@ -236,7 +236,7 @@ int handleRegNotifyOnChange(int key_handle, pclChangeNotifyCallback_t callback, { int rval = EPERS_NOT_INITIALIZED; - if(gPclInitialized >= PCLinitialized) + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { PersistenceKeyHandle_s persHandle; @@ -267,7 +267,7 @@ int pclKeyHandleWriteData(int key_handle, unsigned char* buffer, int buffer_size { int size = EPERS_NOT_INITIALIZED; - if(gPclInitialized >= PCLinitialized) + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { if(doAppcheck() == 1) { @@ -314,7 +314,7 @@ int pclKeyDelete(unsigned int ldbid, const char* resource_id, unsigned int user_ { int rval = EPERS_NOT_INITIALIZED; - if(gPclInitialized >= PCLinitialized) + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { if(doAppcheck() == 1) { @@ -365,7 +365,7 @@ int pclKeyGetSize(unsigned int ldbid, const char* resource_id, unsigned int user { int data_size = EPERS_NOT_INITIALIZED; - if(gPclInitialized >= PCLinitialized) + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { if(doAppcheck() == 1) { @@ -414,7 +414,7 @@ int pclKeyReadData(unsigned int ldbid, const char* resource_id, unsigned int use { int data_size = EPERS_NOT_INITIALIZED; - if(gPclInitialized >= PCLinitialized) + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { if(doAppcheck() == 1) { @@ -470,7 +470,7 @@ int pclKeyWriteData(unsigned int ldbid, const char* resource_id, unsigned int us { int data_size = EPERS_NOT_INITIALIZED; - if(gPclInitialized >= PCLinitialized) + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { if(doAppcheck() == 1) { @@ -570,7 +570,7 @@ int regNotifyOnChange(unsigned int ldbid, const char* resource_id, unsigned int { int rval = EPERS_NOT_INITIALIZED; - if(gPclInitialized >= PCLinitialized) + if(__sync_add_and_fetch(&gPclInitCounter, 0) > 0) { if(doAppcheck() == 1) { |