mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-22 21:32:31 +00:00
Make some small fixes to recent changes
This commit is contained in:
parent
c2590cf7a0
commit
179e048bba
5 changed files with 33 additions and 11 deletions
|
@ -16,7 +16,6 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/intrin/atomic.h"
|
||||
#include "libc/intrin/kmalloc.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
|
@ -27,13 +26,13 @@ static _Atomic(FILE *) __stdio_freelist;
|
|||
|
||||
FILE *__stdio_alloc(void) {
|
||||
FILE *f;
|
||||
f = atomic_load_explicit(&__stdio_freelist, memory_order_relaxed);
|
||||
f = atomic_load_explicit(&__stdio_freelist, memory_order_acquire);
|
||||
while (f) {
|
||||
if (atomic_compare_exchange_weak_explicit(
|
||||
&__stdio_freelist, &f,
|
||||
atomic_load_explicit(&f->next, memory_order_relaxed),
|
||||
memory_order_relaxed, memory_order_relaxed)) {
|
||||
atomic_store_explicit(&f->next, 0, memory_order_relaxed);
|
||||
atomic_load_explicit(&f->next, memory_order_acquire),
|
||||
memory_order_release, memory_order_relaxed)) {
|
||||
atomic_store_explicit(&f->next, 0, memory_order_release);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -48,13 +47,12 @@ FILE *__stdio_alloc(void) {
|
|||
|
||||
void __stdio_free(FILE *f) {
|
||||
FILE *g;
|
||||
_unassert(!atomic_load_explicit(&f->next, memory_order_relaxed));
|
||||
bzero(f, sizeof(*f));
|
||||
g = atomic_load_explicit(&__stdio_freelist, memory_order_relaxed);
|
||||
g = atomic_load_explicit(&__stdio_freelist, memory_order_acquire);
|
||||
for (;;) {
|
||||
atomic_store_explicit(&f->next, g, memory_order_relaxed);
|
||||
atomic_store_explicit(&f->next, g, memory_order_release);
|
||||
if (atomic_compare_exchange_weak_explicit(&__stdio_freelist, &g, f,
|
||||
memory_order_relaxed,
|
||||
memory_order_release,
|
||||
memory_order_relaxed)) {
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue