From 881d7aff4110fb7abffdfe18f05599cacc4e7c68 Mon Sep 17 00:00:00 2001 From: Christian Thaeter Date: Sat, 31 Mar 2007 01:58:47 +0200 Subject: [PATCH] add RESOURCE_LEAVE_LOOKUP which does not need a handle to the holder --- nobug.h | 10 ++++++++++ nobug_resources.c | 6 ++++++ test_nobug_resources.c | 8 +++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/nobug.h b/nobug.h index f0bcdce..de3b5ed 100644 --- a/nobug.h +++ b/nobug.h @@ -672,6 +672,12 @@ NOBUG_ASSERTN_(nobug_resource_leave (handle), \ handle?handle->name:"", nobug_resource_error); \ handle = NULL) +#define NOBUG_RESOURCE_LEAVE_LOOKUP(handle, state, uname) \ +NOBUG_IF(NOBUG_MODE_ALPHA, \ +NOBUG_ASSERTN_(nobug_resource_leave (nobug_resource_find(&handle->data, state, uname)), \ + "RESOURCE_LEAVE", __FILE__, __LINE__, "%s:%s %s %s", \ + handle->type, handle->name, uname, nobug_resource_error)) + /* threading support @@ -1024,6 +1030,9 @@ NOBUG_MODE_SWITCH( \ #ifndef RESOURCE_LEAVE #define RESOURCE_LEAVE NOBUG_RESOURCE_LEAVE #endif +#ifndef RESOURCE_LEAVE_LOOKUP +#define RESOURCE_LEAVE_LOOKUP NOBUG_RESOURCE_LEAVE_LOOKUP +#endif #ifndef RESOURCE_ACQUIRED #define RESOURCE_ACQUIRED NOBUG_RESOURCE_ACQUIRED #endif @@ -1177,6 +1186,7 @@ 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_entered; extern const char* nobug_resource_acquired; diff --git a/nobug_resources.c b/nobug_resources.c index a98d901..2169a23 100644 --- a/nobug_resources.c +++ b/nobug_resources.c @@ -168,6 +168,12 @@ nobug_resource_leave (struct nobug_resource_record* handle) { NOBUG_RESOURCE_LOCK; + if (!handle) + { + nobug_resource_error = "no handle"; + return 0; + } + struct nobug_resource_record* resource = (struct nobug_resource_record*) handle->data; diff --git a/test_nobug_resources.c b/test_nobug_resources.c index 2c1bba0..ffc4e41 100644 --- a/test_nobug_resources.c +++ b/test_nobug_resources.c @@ -16,8 +16,11 @@ int main() RESOURCE_ANNOUNCE("type1", "test1", t1); RESOURCE_HANDLE(e1); + RESOURCE_HANDLE(e2); RESOURCE_ENTER(t1, "user1", e1); + RESOURCE_ENTER(t1, "user2", e2); + nobug_resource_dump_all (stderr); @@ -25,7 +28,10 @@ int main() nobug_resource_dump_all (stderr); - RESOURCE_LEAVE(e1); + NOBUG_RESOURCE_LEAVE_LOOKUP(t1, nobug_resource_acquired, "user2"); + nobug_resource_dump_all (stderr); + + RESOURCE_LEAVE(e2); nobug_resource_dump_all (stderr); -- 2.11.4.GIT