This source file includes following definitions.
- worker
- TEST_IMPL
- TEST_IMPL
- TEST_IMPL
#include "uv.h"
#include "task.h"
#include <string.h>
#include <errno.h>
typedef struct {
uv_barrier_t barrier;
int delay;
volatile int posted;
} worker_config;
static void worker(void* arg) {
worker_config* c = arg;
if (c->delay)
uv_sleep(c->delay);
uv_barrier_wait(&c->barrier);
}
TEST_IMPL(barrier_1) {
uv_thread_t thread;
worker_config wc;
memset(&wc, 0, sizeof(wc));
ASSERT(0 == uv_barrier_init(&wc.barrier, 2));
ASSERT(0 == uv_thread_create(&thread, worker, &wc));
uv_sleep(100);
uv_barrier_wait(&wc.barrier);
ASSERT(0 == uv_thread_join(&thread));
uv_barrier_destroy(&wc.barrier);
return 0;
}
TEST_IMPL(barrier_2) {
uv_thread_t thread;
worker_config wc;
memset(&wc, 0, sizeof(wc));
wc.delay = 100;
ASSERT(0 == uv_barrier_init(&wc.barrier, 2));
ASSERT(0 == uv_thread_create(&thread, worker, &wc));
uv_barrier_wait(&wc.barrier);
ASSERT(0 == uv_thread_join(&thread));
uv_barrier_destroy(&wc.barrier);
return 0;
}
TEST_IMPL(barrier_3) {
uv_thread_t thread;
worker_config wc;
memset(&wc, 0, sizeof(wc));
ASSERT(0 == uv_barrier_init(&wc.barrier, 2));
ASSERT(0 == uv_thread_create(&thread, worker, &wc));
uv_barrier_wait(&wc.barrier);
ASSERT(0 == uv_thread_join(&thread));
uv_barrier_destroy(&wc.barrier);
return 0;
}