From 4abab5ad6c8465a7528ccdd5f49367da05f78bbd Mon Sep 17 00:00:00 2001 From: Vladimir Azarov Date: Tue, 1 Oct 2024 15:47:05 +0200 Subject: Initial version --- src/aio/aio_suspend.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/aio/aio_suspend.c (limited to 'src/aio/aio_suspend.c') diff --git a/src/aio/aio_suspend.c b/src/aio/aio_suspend.c new file mode 100644 index 0000000..1f0c9aa --- /dev/null +++ b/src/aio/aio_suspend.c @@ -0,0 +1,75 @@ +#include +#include +#include +#include "atomic.h" +#include "pthread_impl.h" +#include "aio_impl.h" + +int aio_suspend(const struct aiocb *const cbs[], int cnt, const struct timespec *ts) +{ + int i, tid = 0, ret, expect = 0; + struct timespec at; + volatile int dummy_fut = 0, *pfut; + int nzcnt = 0; + const struct aiocb *cb = 0; + + pthread_testcancel(); + + if (cnt<0) { + errno = EINVAL; + return -1; + } + + for (i=0; itv_sec; + if ((at.tv_nsec += ts->tv_nsec) >= 1000000000) { + at.tv_nsec -= 1000000000; + at.tv_sec++; + } + } + + for (;;) { + for (i=0; i__err; + expect = EINPROGRESS | 0x80000000; + a_cas(pfut, EINPROGRESS, expect); + break; + default: + pfut = &__aio_fut; + if (!tid) tid = __pthread_self()->tid; + expect = a_cas(pfut, 0, tid); + if (!expect) expect = tid; + /* Need to recheck the predicate before waiting. */ + for (i=0; i