replace stdatomic.h with zinnia/atomic.h
This commit is contained in:
+2
-3
@@ -1,7 +1,7 @@
|
||||
#include <zinnia/alloc.h>
|
||||
#include <zinnia/atomic.h>
|
||||
#include <zinnia/utils.h>
|
||||
#include <zinnia/virt.h>
|
||||
#include <stdatomic.h>
|
||||
#include <stddef.h>
|
||||
|
||||
struct page* vm_pfndb = nullptr;
|
||||
@@ -12,8 +12,7 @@ static _Atomic(size_t) mapping_offset = 0;
|
||||
|
||||
uintptr_t vm_alloc(size_t length) {
|
||||
uintptr_t base = arch_mem_mapping_addr();
|
||||
size_t offset =
|
||||
atomic_fetch_add_explicit(&mapping_offset, ALIGN_UP(length, arch_mem_page_size()), memory_order_acquire);
|
||||
size_t offset = atomic_fetch_add(&mapping_offset, ALIGN_UP(length, arch_mem_page_size()), ATOMIC_ACQUIRE);
|
||||
|
||||
return base + offset;
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
#include <zinnia/alloc.h>
|
||||
#include <zinnia/atomic.h>
|
||||
#include <zinnia/cmdline.h>
|
||||
#include <zinnia/compiler.h>
|
||||
#include <zinnia/percpu.h>
|
||||
#include <zinnia/utils.h>
|
||||
#include <arch/percpu.h>
|
||||
#include <stdatomic.h>
|
||||
|
||||
extern uint8_t __ld_percpu_start[];
|
||||
extern uint8_t __ld_percpu_end[];
|
||||
@@ -37,7 +37,7 @@ struct percpu* percpu_new() {
|
||||
|
||||
struct percpu* cpu = HHDM_PTR(mem);
|
||||
cpu->self = cpu;
|
||||
cpu->id = atomic_fetch_add_explicit(&num_cpus, 1, memory_order_relaxed);
|
||||
cpu->id = atomic_fetch_add(&num_cpus, 1, ATOMIC_RELAXED);
|
||||
cpu->online = false;
|
||||
return cpu;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <zinnia/alloc.h>
|
||||
#include <zinnia/assert.h>
|
||||
#include <zinnia/atomic.h>
|
||||
#include <zinnia/errno.h>
|
||||
#include <zinnia/irq.h>
|
||||
#include <zinnia/list.h>
|
||||
@@ -12,7 +13,6 @@
|
||||
#include <zinnia/tailq.h>
|
||||
#include <zinnia/vma.h>
|
||||
#include <arch/sched.h>
|
||||
#include <stdatomic.h>
|
||||
#include <stdint.h>
|
||||
|
||||
static void idle_func(uintptr_t) {
|
||||
@@ -113,7 +113,7 @@ void sched_yield(struct scheduler* sched) {
|
||||
|
||||
void sched_block(struct scheduler* sched) {
|
||||
irq_lock();
|
||||
if (atomic_exchange_explicit(&sched->current->wake_pending, false, memory_order_acq_rel)) {
|
||||
if (atomic_exchange(&sched->current->wake_pending, false, ATOMIC_ACQ_REL)) {
|
||||
irq_unlock();
|
||||
return;
|
||||
}
|
||||
@@ -126,7 +126,7 @@ void sched_wake(struct task* task) {
|
||||
if (task->state == TASK_STATE_BLOCKED)
|
||||
sched_add_task(&percpu_get()->sched, task);
|
||||
else
|
||||
atomic_store_explicit(&task->wake_pending, true, memory_order_release);
|
||||
atomic_store(&task->wake_pending, true, ATOMIC_RELEASE);
|
||||
irq_unlock();
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ errno_t task_create(const char* name, struct vma* space, task_fn_t entry, uintpt
|
||||
return ENOMEM;
|
||||
|
||||
static atomic_size_t last_tid = 0;
|
||||
new_task->id = atomic_fetch_add_explicit(&last_tid, 1, memory_order_acquire);
|
||||
new_task->id = atomic_fetch_add(&last_tid, 1, ATOMIC_ACQUIRE);
|
||||
new_task->space = space;
|
||||
strncpy(new_task->name, name, sizeof(new_task->name));
|
||||
|
||||
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
#include <zinnia/atomic.h>
|
||||
#include <zinnia/irq.h>
|
||||
#include <zinnia/spin.h>
|
||||
#include <stdatomic.h>
|
||||
|
||||
void spin_init(struct spinlock* spin) {
|
||||
spin->next = 0;
|
||||
@@ -9,15 +9,15 @@ void spin_init(struct spinlock* spin) {
|
||||
|
||||
void spin_lock(struct spinlock* spin) {
|
||||
irq_lock();
|
||||
uint32_t my = atomic_fetch_add_explicit(&spin->next, 1, memory_order_relaxed);
|
||||
uint32_t my = atomic_fetch_add(&spin->next, 1, ATOMIC_RELAXED);
|
||||
|
||||
while (atomic_load_explicit(&spin->owner, memory_order_acquire) != my) {
|
||||
while (atomic_load(&spin->owner, ATOMIC_ACQUIRE) != my) {
|
||||
asm volatile("pause");
|
||||
}
|
||||
}
|
||||
|
||||
void spin_unlock(struct spinlock* spin) {
|
||||
uint32_t val = atomic_load_explicit(&spin->owner, memory_order_relaxed);
|
||||
atomic_store_explicit(&spin->owner, val + 1, memory_order_release);
|
||||
uint32_t val = atomic_load(&spin->owner, ATOMIC_RELAXED);
|
||||
atomic_store(&spin->owner, val + 1, ATOMIC_RELEASE);
|
||||
irq_unlock();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user