Make some small fixes to recent changes

This commit is contained in:
Justine Tunney 2022-11-03 05:45:33 -07:00
parent c2590cf7a0
commit 179e048bba
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
5 changed files with 33 additions and 11 deletions

View file

@ -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;
}