mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 06:25:31 +00:00
convert to RUNTIME_CHECK
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include <isc/assertions.h>
|
||||
#include <isc/error.h>
|
||||
#include <isc/thread.h>
|
||||
#include <isc/result.h>
|
||||
#include <isc/rwlock.h>
|
||||
@@ -33,23 +34,26 @@ static void *
|
||||
run1(void *arg) {
|
||||
char *message = arg;
|
||||
|
||||
INSIST(isc_rwlock_lock(&lock, isc_rwlocktype_read) == ISC_R_SUCCESS);
|
||||
RUNTIME_CHECK(isc_rwlock_lock(&lock, isc_rwlocktype_read) ==
|
||||
ISC_R_SUCCESS);
|
||||
printf("%s got READ lock\n", message);
|
||||
sleep(1);
|
||||
printf("%s giving up READ lock\n", message);
|
||||
INSIST(isc_rwlock_unlock(&lock, isc_rwlocktype_read) ==
|
||||
RUNTIME_CHECK(isc_rwlock_unlock(&lock, isc_rwlocktype_read) ==
|
||||
ISC_R_SUCCESS);
|
||||
INSIST(isc_rwlock_lock(&lock, isc_rwlocktype_read) == ISC_R_SUCCESS);
|
||||
RUNTIME_CHECK(isc_rwlock_lock(&lock, isc_rwlocktype_read) ==
|
||||
ISC_R_SUCCESS);
|
||||
printf("%s got READ lock\n", message);
|
||||
sleep(1);
|
||||
printf("%s giving up READ lock\n", message);
|
||||
INSIST(isc_rwlock_unlock(&lock, isc_rwlocktype_read) ==
|
||||
RUNTIME_CHECK(isc_rwlock_unlock(&lock, isc_rwlocktype_read) ==
|
||||
ISC_R_SUCCESS);
|
||||
INSIST(isc_rwlock_lock(&lock, isc_rwlocktype_write) == ISC_R_SUCCESS);
|
||||
RUNTIME_CHECK(isc_rwlock_lock(&lock, isc_rwlocktype_write) ==
|
||||
ISC_R_SUCCESS);
|
||||
printf("%s got WRITE lock\n", message);
|
||||
sleep(1);
|
||||
printf("%s giving up WRITE lock\n", message);
|
||||
INSIST(isc_rwlock_unlock(&lock, isc_rwlocktype_write) ==
|
||||
RUNTIME_CHECK(isc_rwlock_unlock(&lock, isc_rwlocktype_write) ==
|
||||
ISC_R_SUCCESS);
|
||||
return (NULL);
|
||||
}
|
||||
@@ -58,23 +62,26 @@ static void *
|
||||
run2(void *arg) {
|
||||
char *message = arg;
|
||||
|
||||
INSIST(isc_rwlock_lock(&lock, isc_rwlocktype_write) == ISC_R_SUCCESS);
|
||||
RUNTIME_CHECK(isc_rwlock_lock(&lock, isc_rwlocktype_write) ==
|
||||
ISC_R_SUCCESS);
|
||||
printf("%s got WRITE lock\n", message);
|
||||
sleep(1);
|
||||
printf("%s giving up WRITE lock\n", message);
|
||||
INSIST(isc_rwlock_unlock(&lock, isc_rwlocktype_write) ==
|
||||
RUNTIME_CHECK(isc_rwlock_unlock(&lock, isc_rwlocktype_write) ==
|
||||
ISC_R_SUCCESS);
|
||||
INSIST(isc_rwlock_lock(&lock, isc_rwlocktype_write) == ISC_R_SUCCESS);
|
||||
RUNTIME_CHECK(isc_rwlock_lock(&lock, isc_rwlocktype_write) ==
|
||||
ISC_R_SUCCESS);
|
||||
printf("%s got WRITE lock\n", message);
|
||||
sleep(1);
|
||||
printf("%s giving up WRITE lock\n", message);
|
||||
INSIST(isc_rwlock_unlock(&lock, isc_rwlocktype_write) ==
|
||||
RUNTIME_CHECK(isc_rwlock_unlock(&lock, isc_rwlocktype_write) ==
|
||||
ISC_R_SUCCESS);
|
||||
INSIST(isc_rwlock_lock(&lock, isc_rwlocktype_read) == ISC_R_SUCCESS);
|
||||
RUNTIME_CHECK(isc_rwlock_lock(&lock, isc_rwlocktype_read) ==
|
||||
ISC_R_SUCCESS);
|
||||
printf("%s got READ lock\n", message);
|
||||
sleep(1);
|
||||
printf("%s giving up READ lock\n", message);
|
||||
INSIST(isc_rwlock_unlock(&lock, isc_rwlocktype_read) ==
|
||||
RUNTIME_CHECK(isc_rwlock_unlock(&lock, isc_rwlocktype_read) ==
|
||||
ISC_R_SUCCESS);
|
||||
return (NULL);
|
||||
}
|
||||
@@ -95,17 +102,19 @@ main(int argc, char *argv[]) {
|
||||
nworkers = 100;
|
||||
printf("%d workers\n", nworkers);
|
||||
|
||||
INSIST(isc_rwlock_init(&lock, 5, 10) == ISC_R_SUCCESS);
|
||||
RUNTIME_CHECK(isc_rwlock_init(&lock, 5, 10) == ISC_R_SUCCESS);
|
||||
|
||||
for (i = 0; i < nworkers; i++) {
|
||||
sprintf(name, "%02u", i);
|
||||
dupname = strdup(name);
|
||||
INSIST(dupname != NULL);
|
||||
RUNTIME_CHECK(dupname != NULL);
|
||||
if (i != 0 && i % 3 == 0)
|
||||
INSIST(isc_thread_create(run1, dupname, &workers[i]) ==
|
||||
RUNTIME_CHECK(isc_thread_create(run1, dupname,
|
||||
&workers[i]) ==
|
||||
ISC_R_SUCCESS);
|
||||
else
|
||||
INSIST(isc_thread_create(run2, dupname, &workers[i]) ==
|
||||
RUNTIME_CHECK(isc_thread_create(run2, dupname,
|
||||
&workers[i]) ==
|
||||
ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user