Commit d09d9246 authored by bbguimaraes's avatar bbguimaraes
Browse files

wip

parent 59659481
......@@ -25,20 +25,20 @@ static const u64 sleep_dur_ns = 1000 * 1000;
static bool queue3_push(struct queue3 *q, struct task t) {
const size_t w = (q->w + 1) % q->size;
while(atomic_load(&q->r) == w)
while(atomic_load_explicit(&q->r, memory_order_acquire) == w)
if(!sleep_ns(sleep_dur_ns))
return false;
q->tasks[q->w] = t;
atomic_store(&q->w, w);
atomic_store_explicit(&q->w, w, memory_order_release);
return true;
}
static bool queue3_pop(struct queue3 *q, struct task *t) {
while(atomic_load(&q->w) == q->r)
while(atomic_load_explicit(&q->w, memory_order_acquire) == q->r)
if(!sleep_ns(sleep_dur_ns))
false;
const struct task ret = q->tasks[q->r];
atomic_store(&q->r, (q->r + 1) % q->size);
atomic_store_explicit(&q->r, (q->r + 1) % q->size, memory_order_release);
*t = ret;
return true;
}
......
#ifndef CODEX_UTIL_DEF_H
#define CODEX_UTIL_DEF_H
#ifdef __cplusplus
#include <cstdint>
using u64 = std::uint64_t;
#else
#include <stdint.h>
typedef uint64_t u64;
#endif
#endif
#ifndef CODEX_UTIL_UTIL_H
#define CODEX_UTIL_UTIL_H
namespace codex::literals {
inline constexpr std::size_t operator ""_zu(unsigned long long int i) {
return {i};
}
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment