mirror of
https://github.com/Telecominfraproject/OpenNetworkLinux.git
synced 2025-11-02 19:28:18 +00:00
Implement support for the API shared locking implementation.
This commit is contained in:
@@ -48,6 +48,9 @@ include $(BUILDER)/so.mk
|
||||
|
||||
GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_CTOR_DTOR=1
|
||||
GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MODULES_INIT=1
|
||||
GLOBAL_CFLAGS += -DONLP_CONFIG_API_LOCK_GLOBAL_SHARED=1
|
||||
GLOBAL_CFLAGS += -DONLP_CONFIG_INCLUDE_SHLOCK_GLOBAL_INIT=1
|
||||
|
||||
GLOBAL_CFLAGS += -fPIC
|
||||
GLOBAL_LINK_LIBS += -lpthread $(LIBONLP_PLATFORM) $(LIBONLP_PLATFORM_DEFAULTS)
|
||||
|
||||
|
||||
@@ -62,9 +62,62 @@ onlp_api_unlock(void)
|
||||
}
|
||||
|
||||
#else
|
||||
#error GLOBAL_SHARED API Lock support is not yet implemented.
|
||||
|
||||
#include <onlplib/shlocks.h>
|
||||
|
||||
void
|
||||
onlp_api_lock_init(void)
|
||||
{
|
||||
onlp_shlock_global_init();
|
||||
}
|
||||
|
||||
void
|
||||
onlp_api_lock(const char* api)
|
||||
{
|
||||
onlp_shlock_global_take();
|
||||
}
|
||||
void
|
||||
onlp_api_unlock(void)
|
||||
{
|
||||
onlp_shlock_global_give();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* This function will perform a sanity test on the API locking implementation.
|
||||
*/
|
||||
#include <onlplib/file.h>
|
||||
|
||||
static int
|
||||
onlp_api_lock_test_locked__(void)
|
||||
{
|
||||
static int counter__ = 1;
|
||||
int readback = 0;
|
||||
const char* fname = "/tmp/onlp_api_lock_test";
|
||||
|
||||
fclose(fopen(fname, "w"));
|
||||
onlp_file_write_int(counter__, fname, NULL);
|
||||
onlp_file_read_int(&readback, fname, NULL);
|
||||
if(readback != counter__) {
|
||||
fprintf(stderr, "API LOCK TEST: write=%d read=%d", counter__, readback);
|
||||
return -1;
|
||||
}
|
||||
counter__++;
|
||||
return 0;
|
||||
}
|
||||
ONLP_LOCKED_API0(onlp_api_lock_test);
|
||||
|
||||
#else
|
||||
|
||||
int
|
||||
onlp_api_lock_test(void)
|
||||
{
|
||||
fprintf(stderr, "API Locking support not available in this build.\n");
|
||||
return 2;
|
||||
}
|
||||
|
||||
#endif /* ONLP_CONFIG_INCLUDE_API_LOCK */
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user