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 which suffices as unique id
13 RESOURCE_ANNOUNCE(test, "mutex", "my_mutex", example, resource);
15 // the following would be done in a different thread in a real program
17 RESOURCE_HANDLE(enter);
19 // announce that we want to use the resource
20 // &enter also suffices as unique pointer, which is all we need as identifer here
21 RESOURCE_WAIT(flag, resource, &enter, enter)
24 pthread_mutex_lock (&my_mutex);
25 // assume no errors, got it, change the state
26 RESOURCE_STATE(test, NOBUG_RESOURCE_EXCLUSIVE, enter);
29 ////////////////////////////////////////
30 // program does something useful here //
31 ////////////////////////////////////////
33 // we don't need it anymore
34 RESOURCE_LEAVE(test, enter) // << no semicolon
35 pthread_mutex_unlock (&my_mutex);
37 // back in the main thread
38 RESOURCE_FORGET(test, resource); // remove the resource from the public registry