Make improvements

- Document redbean's argon2 module
- Fix regressions in cthreads library
- Make testlib work better with threads
- Give the cthreads library lots of love
- Remove some of the stdio assembly code
- Implement getloadavg() across platforms
- Code size optimizations for errnos, etc.
- Only check for signals in main thread on Windows
- Make errnos for dup2 / dup3 consistent with posix

This change also fixes a bug in the argon2 module, where the NUL
terminator was being included in the hash encoded ascii string. This
shouldn't require any database migrations to folks who found this module
and productionized it, since the argon2 library treats it as a c string.
This commit is contained in:
Justine Tunney 2022-05-27 13:25:46 -07:00
parent cb67223051
commit de5de19004
234 changed files with 1728 additions and 1993 deletions

View file

@ -8,56 +8,58 @@
*/
#endif
#include "libc/calls/calls.h"
#include "libc/intrin/kprintf.h"
#include "libc/log/log.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/thread/create.h"
#include "libc/thread/self.h"
#include "libc/thread/detach.h"
#include "libc/thread/join.h"
#include "libc/thread/self.h"
#include "libc/thread/sem.h"
#include "libc/time/time.h"
cthread_sem_t semaphore;
_Thread_local int test_tls = 0x12345678;
__thread int test_tls = 0x12345678;
int worker(void* arg) {
void* p;
arch_prctl(ARCH_GET_FS, &p);
static void *worker(void *arg) {
int tid;
cthread_t self;
cthread_sem_signal(&semaphore);
cthread_t self = cthread_self();
int tid = self->tid;
sleep(1);
//sleep(10000);
printf("[%p] %d -> 0x%x\n", self, tid, test_tls);
(void)arg;
return 4;
self = cthread_self();
tid = self->tid;
printf("[%p] %d -> %#x\n", self, tid, test_tls);
if (test_tls != 0x12345678) {
printf(".tdata test #2 failed\n");
}
return (void *)4;
}
int main() {
cthread_t self = cthread_self();
int tid = self->tid;
printf("[%p] %d -> 0x%x\n", self, tid, test_tls);
int rc, tid;
void *exitcode;
cthread_t self, thread;
self = cthread_self();
tid = self->tid;
printf("[%p] %d -> %#x\n", self, tid, test_tls);
if (test_tls != 0x12345678) {
printf(".tdata test #1 failed\n");
}
cthread_sem_init(&semaphore, 0);
cthread_t thread;
int rc = cthread_create(&thread, NULL, &worker, NULL);
rc = cthread_create(&thread, NULL, &worker, NULL);
if (rc == 0) {
cthread_sem_wait(&semaphore, 0, NULL);
//printf("thread created: %p\n", thread);
sleep(1);
printf("thread created: %p\n", thread);
#if 1
cthread_join(thread, &rc);
cthread_join(thread, &exitcode);
#else
rc = cthread_detach(thread);
sleep(2);
exitcode = cthread_detach(thread);
#endif
cthread_sem_signal(&semaphore);
cthread_sem_wait(&semaphore, 0, NULL);
//printf("thread joined: %p -> %d\n", thread, rc);
printf("thread joined: %p -> %p\n", thread, exitcode);
} else {
printf("ERROR: thread could not be started: %d\n", rc);
fprintf(stderr, "ERROR: thread could not be started: %d\n", rc);
}
return 0;
}