1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-07-25 12:55:13 +00:00
QB64-PE/internal/c/libqb/include/completion.h
Matthew Kilgore ecfc71ef95 Add completion API
Completions are basically a oneshot flag, which provide a `wait()` call
that blocks until 'finish()' has been called on the completion.

The nice aspect of completions is that because it is a oneshot the order
does not matter - if 'finish()' is called before 'wait()' then 'wait()'
returns immediately. It makes the logic for waiting until a thread is
done finishing up some work easy to implement.
2022-06-11 22:47:06 -04:00

27 lines
685 B
C

#ifndef INCLUDE_LIBQB_COMPLETION_H
#define INCLUDE_LIBQB_COMPLETION_H
#include "mutex.h"
#include "condvar.h"
// A completion is a oneshot signal - it waits until finish is called and
// then never blocks again.
//
// Due to the oneshot nature the order wait() and finish() are called does not matter.
struct completion {
int finished;
struct libqb_mutex *mutex;
struct libqb_condvar *var;
};
void completion_init(struct completion *);
void completion_clear(struct completion *);
// Blocks until the completion is finished
void completion_wait(struct completion *);
// Finishes the completion, unblocks all waiters
void completion_finish(struct completion *);
#endif