34 #ifndef GRPC_IMPL_CODEGEN_SYNC_H
35 #define GRPC_IMPL_CODEGEN_SYNC_H
59 #if defined(GPR_POSIX_SYNC)
61 #elif defined(GPR_WIN32)
63 #elif !defined(GPR_CUSTOM_SYNC)
64 #error Unable to determine platform for sync
216 typedef struct queue {
229 void queue_init(queue *q) {
238 void queue_destroy(queue *q) {
245 void queue_append(queue *q,
int x) {
253 while (q->length == N) {
256 if (q->length == 0) {
261 q->elem[(q->head + q->length) % N] = x;
268 int queue_try_append(queue *q,
int x) {
271 if (q->length != N) {
272 if (q->length == 0) {
275 q->elem[(q->head + q->length) % N] = x;
287 int queue_remove(queue *q,
int *head,
gpr_timespec abs_deadline) {
295 while (q->length == 0 &&
296 !
gpr_cv_wait(&q->non_empty, &q->mu, abs_deadline)) {
298 if (q->length != 0) {
300 if (q->length == N) {
303 *head = q->elem[q->head];
304 q->head = (q->head + 1) % N;
GPRAPI void * gpr_event_get(gpr_event *ev)
GPRAPI void gpr_event_set(gpr_event *ev, void *value)
Definition: sync_generic.h:47
GPRAPI intptr_t gpr_stats_read(const gpr_stats_counter *c)
GPRAPI gpr_timespec gpr_inf_future(gpr_clock_type type)
GPRAPI void gpr_stats_init(gpr_stats_counter *c, intptr_t n)
GPRAPI int gpr_mu_trylock(gpr_mu *mu)
GPRAPI void gpr_cv_destroy(gpr_cv *cv)
pthread_once_t gpr_once
Definition: sync_posix.h:43
GPRAPI void gpr_mu_destroy(gpr_mu *mu)
GPRAPI void gpr_mu_unlock(gpr_mu *mu)
GPRAPI void gpr_cv_signal(gpr_cv *cv)
GPRAPI void gpr_event_init(gpr_event *ev)
Definition: sync_generic.h:50
pthread_cond_t gpr_cv
Definition: sync_posix.h:42
GPRAPI void gpr_once_init(gpr_once *once, void(*init_routine)(void))
Definition: sync_win32.h:39
GPRAPI void gpr_mu_lock(gpr_mu *mu)
GPRAPI void gpr_ref_init(gpr_refcount *r, int n)
GPRAPI int gpr_cv_wait(gpr_cv *cv, gpr_mu *mu, gpr_timespec abs_deadline)
GPRAPI void gpr_stats_inc(gpr_stats_counter *c, intptr_t inc)
GPRAPI int gpr_unref(gpr_refcount *r)
GPRAPI void gpr_cv_broadcast(gpr_cv *cv)
GPRAPI void gpr_cv_init(gpr_cv *cv)
GPRAPI void gpr_ref(gpr_refcount *r)
GPRAPI void gpr_mu_init(gpr_mu *mu)
GPRAPI void gpr_refn(gpr_refcount *r, int n)
GPRAPI void * gpr_event_wait(gpr_event *ev, gpr_timespec abs_deadline)
Definition: sync_generic.h:41