Go to the documentation of this file.
19 #ifndef GRPC_SUPPORT_SYNC_H
20 #define GRPC_SUPPORT_SYNC_H
182 typedef struct queue {
195 void queue_init(queue *q) {
204 void queue_destroy(queue *q) {
211 void queue_append(queue *q,
int x) {
219 while (q->length == N) {
222 if (q->length == 0) {
227 q->elem[(q->head + q->length) % N] = x;
234 int queue_try_append(queue *q,
int x) {
237 if (q->length != N) {
238 if (q->length == 0) {
241 q->elem[(q->head + q->length) % N] = x;
253 int queue_remove(queue *q,
int *head,
gpr_timespec abs_deadline) {
261 while (q->length == 0 &&
262 !
gpr_cv_wait(&q->non_empty, &q->mu, abs_deadline)) {
264 if (q->length != 0) {
266 if (q->length == N) {
269 *head = q->elem[q->head];
270 q->head = (q->head + 1) % N;
GPRAPI void gpr_ref(gpr_refcount *r)
Increment the reference count *r.
pthread_once_t gpr_once
Definition: sync_posix.h:48
GPRAPI void gpr_mu_destroy(gpr_mu *mu)
Cause *mu no longer to be initialized, freeing any memory in use.
pthread_cond_t gpr_cv
Definition: sync_posix.h:46
GPRAPI intptr_t gpr_stats_read(const gpr_stats_counter *c)
Return *c.
GPRAPI int gpr_cv_wait(gpr_cv *cv, gpr_mu *mu, gpr_timespec abs_deadline)
Atomically release *mu and wait on *cv.
GPRAPI void gpr_event_init(gpr_event *ev)
— One-time event notification —
Definition: sync_generic.h:36
Definition: sync_generic.h:41
GPRAPI gpr_timespec gpr_inf_future(gpr_clock_type type)
The zero time interval.
GPRAPI void gpr_ref_init(gpr_refcount *r, int n)
— Reference counting —
GPRAPI void gpr_cv_init(gpr_cv *cv)
— Condition variable interface —
GPRAPI void gpr_cv_destroy(gpr_cv *cv)
Cause *cv no longer to be initialized, freeing any memory in use.
GPRAPI void gpr_event_set(gpr_event *ev, void *value)
Set *ev so that gpr_event_get() and gpr_event_wait() will return value.
GPRAPI void gpr_stats_inc(gpr_stats_counter *c, intptr_t inc)
*c += inc.
GPRAPI void gpr_cv_signal(gpr_cv *cv)
If any threads are waiting on *cv, wake at least one.
GPRAPI void gpr_once_init(gpr_once *once, void(*init_routine)(void))
— One-time initialization —
GPRAPI void gpr_mu_lock(gpr_mu *mu)
Wait until no thread has a lock on *mu, cause the calling thread to own an exclusive lock on *mu,...
GPRAPI void gpr_cv_broadcast(gpr_cv *cv)
Wake all threads waiting on *cv.
GPRAPI int gpr_mu_trylock(gpr_mu *mu)
Without blocking, attempt to acquire an exclusive lock on *mu for the calling thread,...
Definition: sync_generic.h:28
GPRAPI void gpr_mu_unlock(gpr_mu *mu)
Release an exclusive lock on *mu held by the calling thread.
GPRAPI void * gpr_event_wait(gpr_event *ev, gpr_timespec abs_deadline)
Wait until *ev is set by gpr_event_set(ev, ...), or abs_deadline is exceeded, then return gpr_event_g...
GPRAPI int gpr_ref_is_unique(gpr_refcount *r)
Return non-zero iff the reference count of *r is one, and thus is owned by exactly one object.
GPRAPI void gpr_stats_init(gpr_stats_counter *c, intptr_t n)
— Stats counters —
GPRAPI int gpr_unref(gpr_refcount *r)
Decrement the reference count *r and return non-zero iff it has reached zero.
GPRAPI void gpr_refn(gpr_refcount *r, int n)
Increment the reference count *r by n.
GPRAPI void gpr_mu_init(gpr_mu *mu)
— Mutex interface —
Definition: sync_windows.h:26
Analogous to struct timespec.
Definition: gpr_types.h:47
GPRAPI void * gpr_event_get(gpr_event *ev)
Return the value set by gpr_event_set(ev, ...), or NULL if no such call has completed.
GPRAPI void gpr_ref_non_zero(gpr_refcount *r)
Increment the reference count *r.