1 .How to use the Resourcetracker
4 NOBUG_DEFINE_FLAG_LIMIT(test, LOG_DEBUG);
8 /* define a mutex and announce it */
9 pthread_mutex_t my_mutex = PTHREAD_MUTEX_INITIALIZER;
10 RESOURCE_HANDLE(resource);
12 /* 'example' is just a pointer to this function
13 which suffices as unique identifier */
14 RESOURCE_ANNOUNCE(test, "mutex", "my_mutex",
17 /* the following would be done in a
18 different thread in a real program */
21 RESOURCE_HANDLE(enter);
23 /* announce that we want to use the resource
24 &enter also suffices as unique pointer,
25 which is all we need as identifer here */
26 RESOURCE_WAIT(flag, resource, &enter, enter)
28 /* lock() might block */
29 pthread_mutex_lock (&my_mutex);
30 /* assume no errors, got it, change the state */
31 RESOURCE_STATE(test, NOBUG_RESOURCE_EXCLUSIVE, enter);
34 /***************************************
35 ** program does something useful here **
36 ***************************************/
38 /* we don't need it anymore */
39 RESOURCE_LEAVE(test, enter) /* << no semicolon! */
40 pthread_mutex_unlock (&my_mutex);
42 /* back in the main thread */
44 /* remove the resource from the public registry */
45 RESOURCE_FORGET(test, resource);