From 35c762e055e8599a7b9f0f5d613798a91281f1a4 Mon Sep 17 00:00:00 2001 From: Christian Thaeter Date: Tue, 27 Mar 2007 11:32:25 +0200 Subject: [PATCH] add a 'acquired' state to entered resources --- nobug.h | 28 ++++++++++++++-------------- nobug_resources.c | 7 +------ test_nobug_resources.c | 14 ++++---------- 3 files changed, 19 insertions(+), 30 deletions(-) diff --git a/nobug.h b/nobug.h index 0cf4e33..4937a37 100644 --- a/nobug.h +++ b/nobug.h @@ -705,8 +705,14 @@ NOBUG_ASSERTN_(nobug_resource_leave (handle, client), \ handle?handle->name:"", client, nobug_resource_error); \ nobug_assign_maybe(NULL, ## __VA_ARGS__, NULL)) -#define NOBUG_RESOURCE_STATE_HANDLE(handle, state) \ -handle->data = (char*)nobug_resource_states[NOBUG_CAT(NOBUG_RESOURCE_, state)] +#define NOBUG_RESOURCE_ACQUIRED_HANDLE(handle) \ +NOBUG_IF(NOBUG_MODE_ALPHA, \ + handle->data = (char*)nobug_resource_acquired) + + +#define NOBUG_RESOURCE_HANDLE(handle) \ +NOBUG_IF(NOBUG_MODE_ALPHA, \ + struct nobug_resource_record* handle) /* threading support @@ -1080,8 +1086,11 @@ NOBUG_MODE_SWITCH( \ #ifndef RESOURCE_LEAVE_HANDLE #define RESOURCE_LEAVE_HANDLE NOBUG_RESOURCE_LEAVE_HANDLE #endif -#ifndef RESOURCE_STATE_HANDLE -#define RESOURCE_STATE_HANDLE NOBUG_RESOURCE_STATE_HANDLE +#ifndef RESOURCE_ACQUIRED_HANDLE +#define RESOURCE_ACQUIRED_HANDLE NOBUG_RESOURCE_ACQUIRED_HANDLE +#endif +#ifndef RESOURCE_HANDLE +#define RESOURCE_HANDLE NOBUG_RESOURCE_HANDLE #endif #endif /* NOBUG_DISABLE_SHORTNAMES */ #endif /* NOBUG_LIBNOBUG_C */ @@ -1229,16 +1238,6 @@ struct nobug_resource_record extern void* nobug_resource_registry; extern const char* nobug_resource_error; extern FILE* nobug_resource_dump_target; -extern const char* nobug_resource_states[]; - -enum nobug_resource_state -{ - NOBUG_RESOURCE_WAITING, - NOBUG_RESOURCE_LOCKED, - - NOBUG_RESOURCE_EXPIRED /* must be the last! */ -}; - /* evil hack to make reference variables optional */ static inline void* @@ -1310,6 +1309,7 @@ extern pthread_mutex_t nobug_global_mutex; extern struct nobug_ringbuffer* nobug_default_ringbuffer; extern FILE* nobug_default_file; extern struct nobug_flag nobug_flag_NOBUG_ON; +extern const char* nobug_resource_acquired; void nobug_init (); diff --git a/nobug_resources.c b/nobug_resources.c index 433fadf..4edf93c 100644 --- a/nobug_resources.c +++ b/nobug_resources.c @@ -25,13 +25,8 @@ const char* nobug_resource_error = NULL; FILE* nobug_resource_dump_target = NULL; -const char* nobug_resource_states[] = - { - "waiting", - "locked", +const char* nobug_resource_acquired = "acquired"; - "expired" - }; int compare_resource_records (const void *a, const void *b) diff --git a/test_nobug_resources.c b/test_nobug_resources.c index 4151d4e..abde4dd 100644 --- a/test_nobug_resources.c +++ b/test_nobug_resources.c @@ -9,8 +9,8 @@ int main() { nobug_init(); - struct nobug_resource_record* t1; - struct nobug_resource_record* t2; + NOBUG_RESOURCE_HANDLE(t1); + NOBUG_RESOURCE_HANDLE(t2); RESOURCE_ANNOUNCE_NAME("type1", "test1", &t1); @@ -21,19 +21,13 @@ int main() RESOURCE_ENTER("test3", "user3"); - struct nobug_resource_record* e1; + NOBUG_RESOURCE_HANDLE(e1); RESOURCE_ENTER_HANDLE(t2, "user2", &e1); - - - RESOURCE_STATE_HANDLE(e1, WAITING); - - nobug_resource_dump_all (stderr); - - RESOURCE_STATE_HANDLE(e1, LOCKED); + RESOURCE_ACQUIRED_HANDLE(e1); nobug_resource_dump_all (stderr); -- 2.11.4.GIT