Go to the documentation of this file.
19 #ifndef GRPC_SUPPORT_SYNC_H
20 #define GRPC_SUPPORT_SYNC_H
51 #if defined(GPR_CUSTOM_SYNC)
53 #elif defined(GPR_ABSEIL_SYNC)
55 #elif defined(GPR_POSIX_SYNC)
57 #elif defined(GPR_WINDOWS)
60 #error Unable to determine platform for sync
214 typedef struct queue {
227 void queue_init(queue *q) {
236 void queue_destroy(queue *q) {
243 void queue_append(queue *q,
int x) {
251 while (q->length == N) {
254 if (q->length == 0) {
259 q->elem[(q->head + q->length) % N] = x;
266 int queue_try_append(queue *q,
int x) {
269 if (q->length != N) {
270 if (q->length == 0) {
273 q->elem[(q->head + q->length) % N] = x;
285 int queue_remove(queue *q,
int *head,
gpr_timespec abs_deadline) {
293 while (q->length == 0 &&
294 !
gpr_cv_wait(&q->non_empty, &q->mu, abs_deadline)) {
296 if (q->length != 0) {
298 if (q->length == N) {
301 *head = q->elem[q->head];
302 q->head = (q->head + 1) % N;
GPRAPI void gpr_ref(gpr_refcount *r)
Increment the reference count *r.
pthread_mutex_t gpr_mu
Definition: sync_posix.h:44
GPRAPI void gpr_mu_destroy(gpr_mu *mu)
Cause *mu no longer to be initialized, freeing any memory in use.
GPRAPI void gpr_once_init(gpr_once *once, void(*init_function)(void))
— One-time initialization —
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 gpr_timespec gpr_inf_future(gpr_clock_type type)
The far future.
GPRAPI void gpr_event_init(gpr_event *ev)
— One-time event notification —
Definition: sync_generic.h:36
Definition: sync_generic.h:41
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.
pthread_once_t gpr_once
Definition: sync_posix.h:47
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.
pthread_cond_t gpr_cv
Definition: sync_posix.h:45
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)
Synchronization primitives for GPR.
Analogous to struct timespec.
Definition: time.h:48
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.