blob: b5ac86e4f1a72aab8322e676b76a621de87f983f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
// SPDX-License-Identifier: GPL-3.0-or-later
#include "completion.h"
void completion_init(struct completion *p)
{
p->completed = 0;
fatal_assert(0 == uv_cond_init(&p->cond));
fatal_assert(0 == uv_mutex_init(&p->mutex));
}
void completion_destroy(struct completion *p)
{
uv_cond_destroy(&p->cond);
uv_mutex_destroy(&p->mutex);
}
void completion_wait_for(struct completion *p)
{
uv_mutex_lock(&p->mutex);
while (0 == p->completed) {
uv_cond_wait(&p->cond, &p->mutex);
}
fatal_assert(1 == p->completed);
uv_mutex_unlock(&p->mutex);
}
void completion_mark_complete(struct completion *p)
{
uv_mutex_lock(&p->mutex);
p->completed = 1;
uv_cond_broadcast(&p->cond);
uv_mutex_unlock(&p->mutex);
}
|