34 #ifndef GRPC_SUPPORT_SYNC_H
35 #define GRPC_SUPPORT_SYNC_H
191 typedef struct queue {
204 void queue_init(queue *q) {
213 void queue_destroy(queue *q) {
220 void queue_append(queue *q,
int x) {
228 while (q->length == N) {
231 if (q->length == 0) {
236 q->elem[(q->head + q->length) % N] = x;
243 int queue_try_append(queue *q,
int x) {
246 if (q->length != N) {
247 if (q->length == 0) {
250 q->elem[(q->head + q->length) % N] = x;
262 int queue_remove(queue *q,
int *head,
gpr_timespec abs_deadline) {
270 while (q->length == 0 &&
271 !
gpr_cv_wait(&q->non_empty, &q->mu, abs_deadline)) {
273 if (q->length != 0) {
275 if (q->length == N) {
278 *head = q->elem[q->head];
279 q->head = (q->head + 1) % N;
GPRAPI void gpr_stats_init(gpr_stats_counter *c, intptr_t n)
GPRAPI int gpr_cv_wait(gpr_cv *cv, gpr_mu *mu, gpr_timespec abs_deadline)
GPRAPI void gpr_event_init(gpr_event *ev)
Definition: sync_generic.h:47
pthread_once_t gpr_once
Definition: sync_posix.h:43
GPRAPI void gpr_cv_destroy(gpr_cv *cv)
GPRAPI void gpr_mu_init(gpr_mu *mu)
GPRAPI intptr_t gpr_stats_read(const gpr_stats_counter *c)
GPRAPI void gpr_cv_broadcast(gpr_cv *cv)
Definition: sync_generic.h:50
GPRAPI void gpr_stats_inc(gpr_stats_counter *c, intptr_t inc)
pthread_cond_t gpr_cv
Definition: sync_posix.h:42
GPRAPI void gpr_ref_init(gpr_refcount *r, int n)
Definition: sync_windows.h:39
GPRAPI int gpr_mu_trylock(gpr_mu *mu)
GPRAPI void gpr_event_set(gpr_event *ev, void *value)
GPRAPI void gpr_cv_init(gpr_cv *cv)
GPRAPI void gpr_ref_non_zero(gpr_refcount *r)
GPRAPI void * gpr_event_get(gpr_event *ev)
GPRAPI gpr_timespec gpr_inf_future(gpr_clock_type type)
GPRAPI void gpr_mu_lock(gpr_mu *mu)
GPRAPI void gpr_once_init(gpr_once *once, void(*init_routine)(void))
Definition: gpr_types.h:63
GPRAPI void gpr_mu_unlock(gpr_mu *mu)
GPRAPI void gpr_ref(gpr_refcount *r)
GPRAPI void gpr_cv_signal(gpr_cv *cv)
GPRAPI void gpr_refn(gpr_refcount *r, int n)
Definition: sync_generic.h:41
GPRAPI void gpr_mu_destroy(gpr_mu *mu)
GPRAPI void * gpr_event_wait(gpr_event *ev, gpr_timespec abs_deadline)
GPRAPI int gpr_unref(gpr_refcount *r)