mirror of
https://github.com/QB64-Phoenix-Edition/QB64pe.git
synced 2024-09-20 09:04:43 +00:00
ecfc71ef95
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.
26 lines
685 B
C
26 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
|