Use re-entrant locks on stdio

This commit is contained in:
Justine Tunney 2022-05-22 08:13:13 -07:00
parent 4e9662cbc7
commit 1f229e4efc
78 changed files with 427 additions and 179 deletions

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/intrin/spinlock.h"
#include "libc/stdio/stdio.h"
#include "libc/sysv/consts/f.h"
#include "libc/sysv/consts/fd.h"
@ -41,7 +40,7 @@ FILE *freopen(const char *pathname, const char *mode, FILE *stream) {
FILE *res;
unsigned flags;
flags = fopenflags(mode);
_spinlock(&stream->lock);
flockfile(stream);
fflush_unlocked(stream);
if (pathname) {
/* open new stream, overwriting existing alloc */
@ -60,6 +59,6 @@ FILE *freopen(const char *pathname, const char *mode, FILE *stream) {
fcntl(stream->fd, F_SETFL, flags & ~O_CLOEXEC);
res = stream;
}
_spunlock(&stream->lock);
funlockfile(stream);
return res;
}