Apply even more fixups

- Finish cleaning up the stdio unlocked APIs
- Make __cxa_finalize() properly thread safe
- Don't log locks if threads aren't being used
- Add some more mutex guards to places using _mmi
- Specific lock names now appear in the --ftrace logs
- Fix mkdeps.com generating invalid Makefiles sometimes
- Simplify and fix bugs in the test runner infrastructure
- Fix issue where sometimes some functions wouldn't be logged
This commit is contained in:
Justine Tunney 2022-06-12 11:47:20 -07:00
parent 4ddfc47d6e
commit 8cdec62f5b
87 changed files with 955 additions and 899 deletions

View file

@ -31,6 +31,16 @@
#include "libc/stdio/stdio.h"
#include "libc/sysv/consts/o.h"
static pthread_mutex_t __fflush_lock_obj;
void(__fflush_lock)(void) {
pthread_mutex_lock(&__fflush_lock_obj);
}
void(__fflush_unlock)(void) {
pthread_mutex_unlock(&__fflush_lock_obj);
}
/**
* Blocks until data from stream buffer is written out.
*
@ -41,7 +51,7 @@ int fflush_unlocked(FILE *f) {
int rc = 0;
size_t i;
if (!f) {
pthread_mutex_lock(&__fflush.lock);
__fflush_lock();
for (i = __fflush.handles.i; i; --i) {
if ((f = __fflush.handles.p[i - 1])) {
if (fflush(f) == -1) {
@ -49,7 +59,7 @@ int fflush_unlocked(FILE *f) {
}
}
}
pthread_mutex_unlock(&__fflush.lock);
__fflush_unlock();
} else if (f->fd != -1) {
if (__fflush_impl(f) == -1) {
rc = -1;
@ -64,7 +74,7 @@ textstartup int __fflush_register(FILE *f) {
int rc;
size_t i;
struct StdioFlush *sf;
pthread_mutex_lock(&__fflush.lock);
__fflush_lock();
sf = &__fflush;
if (!sf->handles.p) {
sf->handles.p = sf->handles_initmem;
@ -74,19 +84,19 @@ textstartup int __fflush_register(FILE *f) {
for (i = sf->handles.i; i; --i) {
if (!sf->handles.p[i - 1]) {
sf->handles.p[i - 1] = f;
pthread_mutex_unlock(&__fflush.lock);
__fflush_unlock();
return 0;
}
}
rc = append(&sf->handles, &f);
pthread_mutex_unlock(&__fflush.lock);
__fflush_unlock();
return rc;
}
void __fflush_unregister(FILE *f) {
size_t i;
struct StdioFlush *sf;
pthread_mutex_lock(&__fflush.lock);
__fflush_lock();
sf = &__fflush;
sf = pushpop(sf);
for (i = sf->handles.i; i; --i) {
@ -95,5 +105,5 @@ void __fflush_unregister(FILE *f) {
break;
}
}
pthread_mutex_unlock(&__fflush.lock);
__fflush_unlock();
}