#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include "Condition.h"
Go to the source code of this file.
◆ _Class
◆ _Condition()
Class * _Condition |
( |
void |
| ) |
|
Definition at line 141 of file Condition.c.
141 {
144
147 .name = "Condition",
148 .superclass =
_Lock(),
150 .interfaceOffset = offsetof(
Condition, interface),
151 .interfaceSize = sizeof(ConditionInterface),
153 });
154 });
155
156 return clazz;
157}
Class * _initialize(const ClassDef *def)
Initializes the given Class.
static void initialize(Class *clazz)
#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.
POSIX Threads conditional variables.
Class * _Lock(void)
The Lock archetype.
◆ _signal()
Definition at line 86 of file Condition.c.
86 {
87
88 int err = pthread_cond_signal(self->condition);
89 assert(err == 0);
90}
◆ _wait()
Definition at line 96 of file Condition.c.
96 {
97
98 int err = pthread_cond_wait(self->condition, self->
lock.lock);
99 assert(err == 0);
100}
◆ broadcast()
Definition at line 57 of file Condition.c.
57 {
58
59 int err = pthread_cond_broadcast(self->condition);
60 assert(err == 0);
61}
◆ dealloc()
static void dealloc |
( |
Object * |
self | ) |
|
|
static |
- See also
- Object::dealloc(Object *)
Definition at line 41 of file Condition.c.
41 {
42
44
45 pthread_cond_destroy(this->condition);
46 free(this->condition);
47
49}
#define super(type, obj, method,...)
Object is the root Class of The Objectively Class hierarchy.
void dealloc(Object *self)
Frees all resources held by this Object.
◆ init()
Definition at line 67 of file Condition.c.
67 {
68
70 if (self) {
71
72 self->condition = calloc(1, sizeof(pthread_cond_t));
73 assert(self->condition);
74
75 const int err = pthread_cond_init(self->condition, NULL);
76 assert(err == 0);
77 }
78
79 return self;
80}
Condition * init(Condition *self)
Initializes this Condition.
◆ initialize()
static void initialize |
( |
Class * |
clazz | ) |
|
|
static |
- See also
- Class::initialize(Class *)
Definition at line 126 of file Condition.c.
126 {
127
129
135}
static void _signal(Condition *self)
static void _wait(Condition *self)
ident interface
The interface of the Class.
_Bool waitUntilDate(Condition *self, const Date *date)
Waits until the specified Date for this Condition to be signaled.
void signal(Condition *self)
Signals a single Thread waiting on this Condition.
void broadcast(Condition *self)
Signals all Threads waiting on this Condition.
◆ waitUntilDate()
static _Bool waitUntilDate |
( |
Condition * |
self, |
|
|
const Date * |
date |
|
) |
| |
|
static |
Definition at line 106 of file Condition.c.
106 {
107
109
110 const struct timespec time = {
112 .tv_nsec =
date->
time.tv_usec * 1000
113 };
114
115 int err = pthread_cond_timedwait(self->condition,
lock->lock, &time);
116 assert(err == 0 || err == ETIMEDOUT);
117
118 return err == 0;
119}
Date * date(void)
Returns a new Date with the current Time.
void lock(Lock *self)
Acquire this lock, waiting indefinitely.