Get rid of kmalloc()

This changes *NSYNC to allocate waiters on the stack so our locks don't
need to depend on dynamic memory. This make our runtiem simpler, and it
also fixes bugs with thread cancellation support.
This commit is contained in:
Justine Tunney 2023-09-11 21:34:53 -07:00
parent 77a7873057
commit a359de7893
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
57 changed files with 405 additions and 472 deletions

View file

@ -16,6 +16,7 @@
limitations under the License.
*/
#include "third_party/nsync/mu_semaphore.h"
#include "libc/calls/cp.internal.h"
#include "libc/dce.h"
#include "third_party/nsync/mu_semaphore.internal.h"
@ -36,28 +37,45 @@ void nsync_mu_semaphore_init (nsync_semaphore *s) {
}
}
/* Releases system resources associated with *s. */
void nsync_mu_semaphore_destroy (nsync_semaphore *s) {
if (IsXnuSilicon ()) {
return nsync_mu_semaphore_destroy_gcd (s);
} else if (IsNetbsd ()) {
return nsync_mu_semaphore_destroy_sem (s);
}
}
/* Wait until the count of *s exceeds 0, and decrement it. */
errno_t nsync_mu_semaphore_p (nsync_semaphore *s) {
errno_t err;
BEGIN_CANCELLATION_POINT;
if (IsXnuSilicon ()) {
return nsync_mu_semaphore_p_gcd (s);
err = nsync_mu_semaphore_p_gcd (s);
} else if (IsNetbsd ()) {
return nsync_mu_semaphore_p_sem (s);
err = nsync_mu_semaphore_p_sem (s);
} else {
return nsync_mu_semaphore_p_futex (s);
err = nsync_mu_semaphore_p_futex (s);
}
END_CANCELLATION_POINT;
return err;
}
/* Wait until one of:
the count of *s is non-zero, in which case decrement *s and return 0;
or abs_deadline expires, in which case return ETIMEDOUT. */
errno_t nsync_mu_semaphore_p_with_deadline (nsync_semaphore *s, nsync_time abs_deadline) {
errno_t err;
BEGIN_CANCELLATION_POINT;
if (IsXnuSilicon ()) {
return nsync_mu_semaphore_p_with_deadline_gcd (s, abs_deadline);
err = nsync_mu_semaphore_p_with_deadline_gcd (s, abs_deadline);
} else if (IsNetbsd ()) {
return nsync_mu_semaphore_p_with_deadline_sem (s, abs_deadline);
err = nsync_mu_semaphore_p_with_deadline_sem (s, abs_deadline);
} else {
return nsync_mu_semaphore_p_with_deadline_futex (s, abs_deadline);
err = nsync_mu_semaphore_p_with_deadline_futex (s, abs_deadline);
}
END_CANCELLATION_POINT;
return err;
}
/* Ensure that the count of *s is at least 1. */