#include <grpc/support/port_platform.h>
#include <grpc/impl/codegen/gpr_types.h>
#include <grpc/impl/codegen/sync.h>
Go to the source code of this file.
Wake all threads waiting on *cv. Requires: *cv initialized.
Cause *cv no longer to be initialized, freeing any memory in use. Requires: cv initialized; no other concurrent operation on *cv.
— Condition variable interface —
A while-loop should be used with gpr_cv_wait() when waiting for conditions to become true. See the example below. Variables of type gpr_cv are uninitialized when first declared.
Initialize *cv. Requires: *cv uninitialized.
If any threads are waiting on *cv, wake at least one. Clients may treat this as an optimization of gpr_cv_broadcast() for use in the case where waking more than one waiter is not useful. Requires: *cv initialized.
GPRAPI int gpr_cv_wait | ( | gpr_cv * | cv, |
gpr_mu * | mu, | ||
gpr_timespec | abs_deadline | ||
) |
Atomically release *mu and wait on *cv. When the calling thread is woken from *cv or the deadline abs_deadline is exceeded, execute gpr_mu_lock(mu) and return whether the deadline was exceeded. Use abs_deadline==gpr_inf_future for no deadline. abs_deadline can be either an absolute deadline, or a GPR_TIMESPAN. May return even when not woken explicitly. Requires: *mu and *cv initialized; the calling thread holds an exclusive lock on *mu.
Return the value set by gpr_event_set(ev, ...), or NULL if no such call has completed. If the result is non-NULL, all operations that occurred prior to the gpr_event_set(ev, ...) set will be visible after this call returns. Requires: *ev initialized. This operation is faster than acquiring a mutex on most platforms.
Set *ev so that gpr_event_get() and gpr_event_wait() will return value. Requires: *ev initialized; value != NULL; no prior or concurrent calls to gpr_event_set(ev, ...) since initialization.
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_get(ev). Requires: *ev initialized. Use abs_deadline==gpr_inf_future for no deadline. When the event has been signalled before the call, this operation is faster than acquiring a mutex on most platforms.
Cause *mu no longer to be initialized, freeing any memory in use. Requires: mu initialized; no other concurrent operation on *mu.
— Mutex interface —
At most one thread may hold an exclusive lock on a mutex at any given time. Actions taken by a thread that holds a mutex exclusively happen after actions taken by all previous holders of the mutex. Variables of type gpr_mu are uninitialized when first declared.
Initialize *mu. Requires: *mu uninitialized.
Wait until no thread has a lock on *mu, cause the calling thread to own an exclusive lock on *mu, then return. May block indefinitely or crash if the calling thread has a lock on *mu. Requires: *mu initialized.
Without blocking, attempt to acquire an exclusive lock on *mu for the calling thread, then return non-zero iff success. Fail, if any thread holds the lock; succeeds with high probability if no thread holds the lock. Requires: *mu initialized.
Release an exclusive lock on *mu held by the calling thread. Requires: *mu initialized; the calling thread holds an exclusive lock on *mu.
— One-time initialization —
gpr_once must be declared with static storage class, and initialized with GPR_ONCE_INIT. e.g., static gpr_once once_var = GPR_ONCE_INIT;
Ensure that (*init_function)() has been called exactly once (for the specified gpr_once instance) and then return. If multiple threads call gpr_once() on the same gpr_once instance, one of them will call (*init_function)(), and the others will block until that call finishes.
GPRAPI void gpr_ref | ( | gpr_refcount * | r | ) |
GPRAPI void gpr_ref_init | ( | gpr_refcount * | r, |
int | n | ||
) |
— Reference counting —
These calls act on the type gpr_refcount. It requires no destruction.
Initialize *r to value n.
GPRAPI int gpr_ref_is_unique | ( | gpr_refcount * | r | ) |
GPRAPI void gpr_ref_non_zero | ( | gpr_refcount * | r | ) |
GPRAPI void gpr_refn | ( | gpr_refcount * | r, |
int | n | ||
) |
GPRAPI void gpr_stats_inc | ( | gpr_stats_counter * | c, |
intptr_t | inc | ||
) |
GPRAPI void gpr_stats_init | ( | gpr_stats_counter * | c, |
intptr_t | n | ||
) |
— Stats counters —
These calls act on the integral type gpr_stats_counter. It requires no destruction. Static instances may be initialized with gpr_stats_counter c = GPR_STATS_INIT; Beware: These operations do not imply memory barriers. Do not use them to synchronize other events.
Initialize *c to the value n.
GPRAPI intptr_t gpr_stats_read | ( | const gpr_stats_counter * | c | ) |
GPRAPI int gpr_unref | ( | gpr_refcount * | r | ) |