34#define _Class _Condition
45 pthread_cond_destroy(this->condition);
46 free(this->condition);
51#pragma mark - Condition
59 int err = pthread_cond_broadcast(self->condition);
72 self->condition = calloc(1,
sizeof(pthread_cond_t));
73 assert(self->condition);
75 const int err = pthread_cond_init(self->condition, NULL);
88 int err = pthread_cond_signal(self->condition);
98 int err = pthread_cond_wait(self->condition, self->
lock.lock);
110 const struct timespec time = {
112 .tv_nsec =
date->
time.tv_usec * 1000
115 int err = pthread_cond_timedwait(self->condition,
lock->lock, &time);
116 assert(err == 0 || err == ETIMEDOUT);
121#pragma mark - Class lifecycle
148 .superclass =
_Lock(),
150 .interfaceOffset = offsetof(
Condition, interface),
151 .interfaceSize =
sizeof(ConditionInterface),
Class * _initialize(const ClassDef *def)
Initializes the given Class.
#define super(type, obj, method,...)
static void _signal(Condition *self)
static void _wait(Condition *self)
static void initialize(Class *clazz)
POSIX Threads conditional variables.
#define do_once(once, block)
Executes the given block at most one time.
ClassDefs are passed to _initialize via an archetype to initialize a Class.
The runtime representation of a Class.
ident interface
The interface of the Class.
POSIX Threads conditional variables.
_Bool waitUntilDate(Condition *self, const Date *date)
Waits until the specified Date for this Condition to be signaled.
Condition * init(Condition *self)
Initializes this Condition.
void signal(Condition *self)
Signals a single Thread waiting on this Condition.
Class * _Condition(void)
The Condition archetype.
void broadcast(Condition *self)
Signals all Threads waiting on this Condition.
Microsecond-precision immutable dates.
Date * date(void)
Returns a new Date with the current Time.
Class * _Lock(void)
The Lock archetype.
void lock(Lock *self)
Acquire this lock, waiting indefinitely.
Object is the root Class of The Objectively Class hierarchy.
void dealloc(Object *self)
Frees all resources held by this Object.