Serialize ZipOS handle IO across threads

This commit is contained in:
Justine Tunney 2023-02-23 06:24:49 -08:00
parent 0f1ead8943
commit a808b3e738
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
7 changed files with 18 additions and 6 deletions

View file

@ -21,6 +21,7 @@
#include "libc/intrin/asancodes.h"
#include "libc/intrin/cmpxchg.h"
#include "libc/str/str.h"
#include "libc/thread/thread.h"
#include "libc/zipos/zipos.internal.h"
void __zipos_free(struct Zipos *z, struct ZiposHandle *h) {
@ -28,6 +29,7 @@ void __zipos_free(struct Zipos *z, struct ZiposHandle *h) {
__asan_poison((char *)h + sizeof(struct ZiposHandle),
h->mapsize - sizeof(struct ZiposHandle), kAsanHeapFree);
}
pthread_mutex_destroy(&h->lock);
__zipos_lock();
do h->next = z->freelist;
while (!_cmpxchg(&z->freelist, h->next, h));