diff options
author | Jean-Francois Mauguit <jfmauguit@mac.com> | 2024-09-24 09:03:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-24 09:03:25 -0400 |
commit | bab614c421ed7ae329d26bf028c4a3b1d2450f5a (patch) | |
tree | 12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/replicant/nu/win-x86/LockFreeLIFO.c | |
parent | 4bde6044fddf053f31795b9eaccdd2a5a527d21f (diff) | |
parent | 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (diff) | |
download | winamp-bab614c421ed7ae329d26bf028c4a3b1d2450f5a.tar.gz |
Merge pull request #5 from WinampDesktop/community
Merge to main
Diffstat (limited to 'Src/replicant/nu/win-x86/LockFreeLIFO.c')
-rw-r--r-- | Src/replicant/nu/win-x86/LockFreeLIFO.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/Src/replicant/nu/win-x86/LockFreeLIFO.c b/Src/replicant/nu/win-x86/LockFreeLIFO.c new file mode 100644 index 00000000..ecffde9a --- /dev/null +++ b/Src/replicant/nu/win-x86/LockFreeLIFO.c @@ -0,0 +1,48 @@ +#include "LockFreeLIFO.h" +#include "foundation/atomics.h" + +/* win32 implementation */ + +void lifo_init(lifo_t *lifo) +{ + lifo->head = 0; + lifo->aba = 0; +} + +#if 0 // defined in LockFreeLIFO.asm +void lifo_push(lifo_t *lifo, queue_node_t *cl) +{ + queue_node_t *new_head = cl; + queue_node_t *old_head = 0; + do + { + old_head = (queue_node_t *)lifo->head; + new_head->Next = old_head; + } while (!nx_atomic_cmpxchg_pointer(old_head, new_head, (void * volatile *)&lifo->head)); +} + +queue_node_t *lifo_pop(lifo_t *lifo) +{ + lifo_t old_head, new_head; + do + { + old_head = *lifo; + if (!old_head.head) + return 0; + + new_head.head = old_head.head->Next; + new_head.aba = old_head.aba+1; + } while (!nx_atomic_cmpxchg2(*(int64_t *)&old_head, *(int64_t *)&new_head, (volatile int64_t *)&lifo->head)); + return (queue_node_t *)old_head.head; +} +#endif + +queue_node_t *lifo_malloc(size_t bytes) +{ + return _aligned_malloc(bytes, MEMORY_ALLOCATION_ALIGNMENT); +} + +void lifo_free(queue_node_t *ptr) +{ + _aligned_free(ptr); +}
\ No newline at end of file |