34 #ifndef GRPC_SUPPORT_SYNC_H
35 #define GRPC_SUPPORT_SYNC_H
195 typedef struct queue {
208 void queue_init(queue *q) {
217 void queue_destroy(queue *q) {
224 void queue_append(queue *q,
int x) {
232 while (q->length == N) {
235 if (q->length == 0) {
240 q->elem[(q->head + q->length) % N] = x;
247 int queue_try_append(queue *q,
int x) {
250 if (q->length != N) {
251 if (q->length == 0) {
254 q->elem[(q->head + q->length) % N] = x;
266 int queue_remove(queue *q,
int *head,
gpr_timespec abs_deadline) {
274 while (q->length == 0 &&
275 !
gpr_cv_wait(&q->non_empty, &q->mu, abs_deadline)) {
277 if (q->length != 0) {
279 if (q->length == N) {
282 *head = q->elem[q->head];
283 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 int gpr_ref_is_unique(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)