Use *NSYNC for POSIX threads locking APIs

Condition variables, barriers, and r/w locks now work very well.
This commit is contained in:
Justine Tunney 2022-09-11 11:02:07 -07:00
parent 3de35e196c
commit b5cb71ab84
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
197 changed files with 3734 additions and 3817 deletions

View file

@ -7,6 +7,7 @@ COSMOPOLITAN_C_START_
extern hidden bool __nocolor;
extern hidden int kCrashSigs[8];
extern hidden bool _wantcrashreports;
extern hidden bool g_isrunningundermake;
void __start_fatal(const char *, int) hidden;

View file

@ -16,9 +16,10 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/bits.h"
#include "libc/calls/strace.internal.h"
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/bits.h"
#include "libc/intrin/kprintf.h"
#include "libc/intrin/lockcmpxchg.h"
#include "libc/mem/mem.h"
@ -37,7 +38,7 @@ static bool hasleaks;
static noasan void CheckLeak(void *x, void *y, size_t n, void *a) {
if (n) {
if (IsAsan()) {
if (__asan_get_heap_size(x)) {
if (__asan_get_heap_size(x) && !__asan_is_leaky(x)) {
hasleaks = true;
}
} else {
@ -53,9 +54,10 @@ static noasan void OnMemory(void *x, void *y, size_t n, void *a) {
if (i < MAXLEAKS) {
++i;
kprintf("%p %,lu bytes [dlmalloc]", x, n);
if (IsAsan()) {
__asan_print_trace(x);
if (__asan_is_leaky(x)) {
kprintf(" [leaky]");
}
__asan_print_trace(x);
kprintf("\n");
} else if (i == MAXLEAKS) {
++i;
@ -79,6 +81,7 @@ static noasan bool HasLeaks(void) {
*/
noasan void CheckForMemoryLeaks(void) {
struct mallinfo mi;
if (!IsAsan()) return; // we need traces to exclude leaky
if (!_lockcmpxchg(&once, false, true)) {
kprintf("CheckForMemoryLeaks() may only be called once\n");
exit(1);

View file

@ -105,6 +105,7 @@ static void FreeSigAltStack(void *p) {
void ShowCrashReports(void) {
char *sp;
struct sigaltstack ss;
_wantcrashreports = true;
/* <SYNC-LIST>: showcrashreports.c, oncrashthunks.S, oncrash.c */
kCrashSigs[0] = SIGQUIT; /* ctrl+\ aka ctrl+break */
kCrashSigs[1] = SIGFPE; /* 1 / 0 */