Implement POSIX threads API

This commit is contained in:
Justine Tunney 2022-09-05 08:26:03 -07:00
parent af24f21556
commit 9be364d40a
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
95 changed files with 6029 additions and 317 deletions

View file

@ -19,20 +19,18 @@
#include "libc/assert.h"
#include "libc/errno.h"
#include "libc/intrin/pthread.h"
#include "libc/str/str.h"
/**
* Destroys mutex.
*
* @return 0 on success, or error number on failure
* @raise EINVAL if mutex is locked in our implementation
*/
int pthread_mutex_destroy(pthread_mutex_t *mutex) {
int rc;
if (!mutex->lock && !mutex->waits) {
rc = 0;
} else {
assert(!"dead lock");
rc = EDEADLK;
if (mutex->lock || mutex->waits) {
assert(!"deadlock");
return EINVAL;
}
bzero(mutex, sizeof(*mutex));
*mutex = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER;
return 0;
}