Added command-line option -n, which allows to disable locking.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@8853 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/drd/tests/circular_buffer.c b/drd/tests/circular_buffer.c
index 8fc8e5e..3f927b1 100644
--- a/drd/tests/circular_buffer.c
+++ b/drd/tests/circular_buffer.c
@@ -42,6 +42,7 @@
} buffer_t;
static int quiet = 0;
+static int use_locking = 1;
static __inline__
int fetch_and_add(int* p, int i)
@@ -65,7 +66,8 @@
{
int out;
sem_wait(&b->data);
- pthread_mutex_lock(&b->mutex_out);
+ if (use_locking)
+ pthread_mutex_lock(&b->mutex_out);
out = fetch_and_add(&b->out, 1);
if (out >= BUFFER_MAX)
{
@@ -73,7 +75,8 @@
out -= BUFFER_MAX;
}
*d = b->buffer[out];
- pthread_mutex_unlock(&b->mutex_out);
+ if (use_locking)
+ pthread_mutex_unlock(&b->mutex_out);
if (! quiet)
{
printf("received %d from buffer[%d]\n", *d, out);
@@ -86,7 +89,8 @@
{
int in;
sem_wait(&b->free);
- pthread_mutex_lock(&b->mutex_in);
+ if (use_locking)
+ pthread_mutex_lock(&b->mutex_in);
in = fetch_and_add(&b->in, 1);
if (in >= BUFFER_MAX)
{
@@ -94,7 +98,8 @@
in -= BUFFER_MAX;
}
b->buffer[in] = *d;
- pthread_mutex_unlock(&b->mutex_in);
+ if (use_locking)
+ pthread_mutex_unlock(&b->mutex_in);
if (! quiet)
{
printf("sent %d to buffer[%d]\n", *d, in);
@@ -145,10 +150,13 @@
int i;
int optchar;
- while ((optchar = getopt(argc, argv, "q")) != EOF)
+ while ((optchar = getopt(argc, argv, "nq")) != EOF)
{
switch (optchar)
{
+ case 'n':
+ use_locking = 0;
+ break;
case 'q':
quiet = 1;
break;