pth_detached_sem.vgtest \
pth_inconsistent_cond_wait.stderr.exp \
pth_inconsistent_cond_wait.vgtest \
+ pth_spinlock.stderr.exp \
+ pth_spinlock.vgtest \
recursive_mutex.stderr.exp \
recursive_mutex.stdout.exp \
recursive_mutex.vgtest \
pth_detached \
pth_detached_sem \
pth_inconsistent_cond_wait \
+ pth_spinlock \
recursive_mutex \
rwlock_race \
rwlock_test \
pth_inconsistent_cond_wait_SOURCES = pth_inconsistent_cond_wait.c
pth_inconsistent_cond_wait_LDADD = -lpthread
+pth_spinlock_SOURCES = pth_spinlock.c
+pth_spinlock_LDADD = -lpthread
+
recursive_mutex_SOURCES = recursive_mutex.c
recursive_mutex_LDADD = -lpthread
--- /dev/null
+/** pthread_spinloc_t test. */
+
+
+/* Make sure pthread_spinlock_t is available when compiling with older glibc
+ * versions (2.3 or before).
+ */
+#define _GNU_SOURCE
+
+#include <pthread.h>
+#include <stdio.h> /* fprintf() */
+#include <stdlib.h> /* atoi() */
+
+
+static pthread_barrier_t s_barrier;
+static pthread_spinlock_t s_spinlock;
+static int s_iterations;
+static int s_counter;
+
+
+static void* thread_func(void* arg)
+{
+ int i;
+
+ pthread_barrier_wait(&s_barrier);
+ for (i = s_iterations; i > 0; i--)
+ {
+ pthread_spin_lock(&s_spinlock);
+ s_counter++;
+ pthread_spin_unlock(&s_spinlock);
+ }
+ return 0;
+}
+
+int main(int argc, char** argv)
+{
+ int i;
+ const int n_threads = 10;
+ pthread_t tid[n_threads];
+
+ s_iterations = argc > 1 ? atoi(argv[1]) : 1000;
+
+ fprintf(stderr, "Start of test.\n");
+ pthread_barrier_init(&s_barrier, 0, n_threads);
+ pthread_spin_init(&s_spinlock, 0);
+ for (i = 0; i < n_threads; i++)
+ pthread_create(&tid[i], 0, thread_func, 0);
+ for (i = 0; i < n_threads; i++)
+ pthread_join(tid[i], 0);
+ pthread_spin_destroy(&s_spinlock);
+ pthread_barrier_destroy(&s_barrier);
+ if (s_counter == n_threads * s_iterations)
+ fprintf(stderr, "Test successful.\n");
+ else
+ fprintf(stderr, "Test failed: counter = %d, should be %d\n",
+ s_counter, n_threads * s_iterations);
+ return 0;
+}