| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #ifndef NETDATA_COMPLETION_H |
| 4 | #define NETDATA_COMPLETION_H |
| 5 | |
| 6 | #include "../libnetdata.h" |
| 7 | |
| 8 | struct completion { |
| 9 | netdata_mutex_t mutex; |
| 10 | netdata_cond_t cond; |
| 11 | volatile unsigned completed; |
| 12 | volatile unsigned completed_jobs; |
| 13 | }; |
| 14 | |
| 15 | void completion_reset(struct completion *p); |
| 16 | |
| 17 | void completion_init(struct completion *p); |
| 18 | |
| 19 | void completion_destroy(struct completion *p); |
| 20 | |
| 21 | void completion_wait_for(struct completion *p); |
| 22 | |
| 23 | // Wait for at most `timeout` seconds. Return true on success, false on |
| 24 | // error or timeout. |
| 25 | bool completion_timedwait_for(struct completion *p, uint64_t timeout_s); |
| 26 | |
| 27 | void completion_mark_complete(struct completion *p); |
| 28 | |
| 29 | unsigned completion_wait_for_a_job(struct completion *p, unsigned completed_jobs); |
| 30 | unsigned completion_wait_for_a_job_with_timeout(struct completion *p, unsigned completed_jobs, uint64_t timeout_ms); |
| 31 | void completion_mark_complete_a_job(struct completion *p); |
| 32 | bool completion_is_done(struct completion *p); |
| 33 | |
| 34 | #endif /* NETDATA_COMPLETION_H */ |