mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 14:58:30 +00:00
Clean up more code
The *NSYNC linked list API is good enough that it deserves to be part of the C libray, so this change writes an improved version of it which uses that offsetof() trick from the Linux Kernel. We vendor all of the *NSYNC tests in third_party which helped confirm the needed refactoring is safe This change also deletes more old code that didn't pan out. My goal here is to work towards a vision where the Cosmopolitan core libraries become less experimental and more focused on curation. This better reflects the current level of quality we've managed to achieve.
This commit is contained in:
parent
88612a2cd7
commit
0a24b4fc3c
268 changed files with 632 additions and 8688 deletions
|
@ -499,7 +499,7 @@ static void test_cv_timeout_stress (testing t) {
|
|||
nsync_time deadline;
|
||||
deadline = nsync_time_add (nsync_time_now (), nsync_time_ms (5000));
|
||||
do {
|
||||
memset ((void *) &s, 0, sizeof (s));
|
||||
bzero ((void *) &s, sizeof (s));
|
||||
s.loop_count = loop_count;
|
||||
s.cv_threads_per_value = 4;
|
||||
s.cv_reader_threads_per_value = 2;
|
||||
|
@ -519,7 +519,7 @@ static void test_mu_timeout_stress (testing t) {
|
|||
nsync_time deadline;
|
||||
deadline = nsync_time_add (nsync_time_now (), nsync_time_ms (5000));
|
||||
do {
|
||||
memset ((void *) &s, 0, sizeof (s));
|
||||
bzero ((void *) &s, sizeof (s));
|
||||
s.loop_count = loop_count;
|
||||
s.cv_threads_per_value = 0;
|
||||
s.cv_reader_threads_per_value = 0;
|
||||
|
@ -539,7 +539,7 @@ static void test_mu_cv_timeout_stress (testing t) {
|
|||
nsync_time deadline;
|
||||
deadline = nsync_time_add (nsync_time_now (), nsync_time_ms (5000));
|
||||
do {
|
||||
memset ((void *) &s, 0, sizeof (s));
|
||||
bzero ((void *) &s, sizeof (s));
|
||||
s.loop_count = loop_count;
|
||||
s.cv_threads_per_value = 4;
|
||||
s.cv_reader_threads_per_value = 1;
|
||||
|
|
8
third_party/nsync/testing/cv_test.c
vendored
8
third_party/nsync/testing/cv_test.c
vendored
|
@ -15,12 +15,12 @@
|
|||
│ See the License for the specific language governing permissions and │
|
||||
│ limitations under the License. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/nsync/cv.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "third_party/nsync/cv.h"
|
||||
#include "third_party/nsync/debug.h"
|
||||
#include "third_party/nsync/mu.h"
|
||||
#include "third_party/nsync/mu_wait.h"
|
||||
|
@ -51,7 +51,7 @@ static cv_queue *cv_queue_new (int limit) {
|
|||
cv_queue *q;
|
||||
int size = offsetof (struct cv_queue_s, data) + sizeof (q->data[0]) * limit;
|
||||
q = (cv_queue *) malloc (size);
|
||||
memset ((void *) q, 0, size);
|
||||
bzero ((void *) q, size);
|
||||
q->limit = limit;
|
||||
return (q);
|
||||
}
|
||||
|
@ -481,7 +481,7 @@ static void test_cv_debug (testing t) {
|
|||
int buflen;
|
||||
struct debug_state xs;
|
||||
struct debug_state *s = &xs;
|
||||
memset ((void *) s, 0, sizeof (*s));
|
||||
bzero ((void *) s, sizeof (*s));
|
||||
|
||||
/* Use nsync_*_debugger to check that they work. */
|
||||
tmp = nsync_mu_debugger (&s->mu);
|
||||
|
@ -708,7 +708,7 @@ static void test_cv_transfer (testing t) {
|
|||
TEST_LOG (t, ("transfer waiters %d wakeup_type %d cv_writers %d ccs_reader %d\n",
|
||||
waiters, wakeup_type, cv_writers, ccs_reader));
|
||||
}
|
||||
memset ((void *) cvt, 0, sizeof (*cvt));
|
||||
bzero ((void *) cvt, sizeof (*cvt));
|
||||
|
||||
/* Start the waiter threads that use condition variables. */
|
||||
for (i = 0; i < waiters-1; i++) {
|
||||
|
|
|
@ -149,8 +149,8 @@ static void example_cv_wait (testing t) {
|
|||
"five\n"
|
||||
"timeout 1s\n";
|
||||
|
||||
memset ((void *) &q, 0, sizeof (q));
|
||||
memset (&output, 0, sizeof (output));
|
||||
bzero ((void *) &q, sizeof (q));
|
||||
bzero (&output, sizeof (output));
|
||||
|
||||
closure_fork (closure_add_and_wait_cv (&add_and_wait_cv, &q,
|
||||
nsync_time_ms (500), NELEM (input), input));
|
||||
|
|
124
third_party/nsync/testing/dll_test.c
vendored
124
third_party/nsync/testing/dll_test.c
vendored
|
@ -15,11 +15,12 @@
|
|||
│ See the License for the specific language governing permissions and │
|
||||
│ limitations under the License. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/dll.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/intrin/dll.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "third_party/nsync/array.internal.h"
|
||||
#include "third_party/nsync/dll.h"
|
||||
#include "third_party/nsync/testing/smprintf.h"
|
||||
#include "third_party/nsync/testing/testing.h"
|
||||
// clang-format off
|
||||
|
@ -80,25 +81,25 @@ static char *a_string (const a_int *a) {
|
|||
|
||||
/* A list item for use in the tests below */
|
||||
struct list_item_s {
|
||||
nsync_dll_element_ e;
|
||||
struct Dll e;
|
||||
int i;
|
||||
};
|
||||
/* Return a pointer to the struct list_item_s containing nsync_dll_element_ *e_. */
|
||||
#define LIST_ITEM(e_) ((struct list_item_s *) ((e_)->container))
|
||||
/* Return a pointer to the struct list_item_s containing struct Dll *e_. */
|
||||
#define LIST_ITEM(e_) DLL_CONTAINER(struct list_item_s, e, e_)
|
||||
|
||||
|
||||
/* Check that list l contains elements containing the values in
|
||||
expected, by scanning both forwards and backwards through the list. Also
|
||||
verify that nsync_dll_first_() and nsync_dll_last_() return the first and last element
|
||||
found during those iterations, and that nsync_dll_is_empty_() yields the right value. */
|
||||
static void verify_list (testing t, const char *label, nsync_dll_list_ l,
|
||||
verify that dll_first() and dll_last() return the first and last element
|
||||
found during those iterations, and that dll_is_empty() yields the right value. */
|
||||
static void verify_list (testing t, const char *label, struct Dll *l,
|
||||
const a_int *expected, const char *file, int line) {
|
||||
nsync_dll_element_ *first;
|
||||
nsync_dll_element_ *last = NULL;
|
||||
nsync_dll_element_ *p;
|
||||
struct Dll *first;
|
||||
struct Dll *last = NULL;
|
||||
struct Dll *p;
|
||||
int i = 0;
|
||||
char *expected_str = a_string (expected);
|
||||
for (p = nsync_dll_first_ (l); p != NULL; p = nsync_dll_next_ (l, p)) {
|
||||
for (p = dll_first (l); p != NULL; p = dll_next (l, p)) {
|
||||
if (A (expected, i) != LIST_ITEM (p)->i) {
|
||||
TEST_ERROR (t, ("%s:%d; %s:expected=%s: expected %d as "
|
||||
"value %d in list, but found %d\n",
|
||||
|
@ -108,10 +109,10 @@ static void verify_list (testing t, const char *label, nsync_dll_list_ l,
|
|||
last = p;
|
||||
i++;
|
||||
}
|
||||
if (last != nsync_dll_last_ (l)) {
|
||||
if (last != dll_last (l)) {
|
||||
TEST_ERROR (t, ("%s:%d: %s:expected=%s: expected %p as "
|
||||
"last item in list, but found %p\n",
|
||||
file, line, label, expected_str, last, nsync_dll_last_ (l)));
|
||||
file, line, label, expected_str, last, dll_last (l)));
|
||||
}
|
||||
if (i != A_LEN (expected)) {
|
||||
TEST_ERROR (t, ("%s:%d: %s:expected=%s: expected %d items in "
|
||||
|
@ -120,7 +121,7 @@ static void verify_list (testing t, const char *label, nsync_dll_list_ l,
|
|||
}
|
||||
|
||||
first = NULL;
|
||||
for (p = nsync_dll_last_ (l); p != NULL; p = nsync_dll_prev_ (l, p)) {
|
||||
for (p = dll_last (l); p != NULL; p = dll_prev (l, p)) {
|
||||
i--;
|
||||
if (A (expected, i) != LIST_ITEM (p)->i) {
|
||||
TEST_ERROR (t, ("%s:%d: %s:expected=%s: expected %d as "
|
||||
|
@ -130,10 +131,10 @@ static void verify_list (testing t, const char *label, nsync_dll_list_ l,
|
|||
}
|
||||
first = p;
|
||||
}
|
||||
if (first != nsync_dll_first_ (l)) {
|
||||
if (first != dll_first (l)) {
|
||||
TEST_ERROR (t, ("%s:%d: %s:expected=%s: expected %p as "
|
||||
"first item in list, but found %p\n",
|
||||
file, line, label, expected_str, first, nsync_dll_last_ (l)));
|
||||
file, line, label, expected_str, first, dll_last (l)));
|
||||
}
|
||||
if (i != 0) {
|
||||
TEST_ERROR (t, ("%s:%d: %s:expected=%s: expected %d items "
|
||||
|
@ -142,43 +143,43 @@ static void verify_list (testing t, const char *label, nsync_dll_list_ l,
|
|||
A_LEN (expected), A_LEN (expected)-i));
|
||||
}
|
||||
|
||||
if ((A_LEN (expected) == 0) != nsync_dll_is_empty_ (l)) {
|
||||
TEST_ERROR (t, ("%s:%d: %s:expected=%s: expected nsync_dll_is_empty_() "
|
||||
if ((A_LEN (expected) == 0) != dll_is_empty (l)) {
|
||||
TEST_ERROR (t, ("%s:%d: %s:expected=%s: expected dll_is_empty() "
|
||||
"to yield %d but got %d\n",
|
||||
file, line, label, expected_str,
|
||||
(A_LEN (expected) == 0), nsync_dll_is_empty_ (l)));
|
||||
(A_LEN (expected) == 0), dll_is_empty (l)));
|
||||
}
|
||||
free (expected_str);
|
||||
}
|
||||
|
||||
/* Return a new list containing the count integers from start to
|
||||
start+count-1 by appending successive elements to the list.
|
||||
This exercises nsync_dll_make_last_in_list_() using singleton elements. */
|
||||
static nsync_dll_list_ make_list (int start, int count) {
|
||||
nsync_dll_list_ l = NULL;
|
||||
This exercises dll_make_last() using singleton elements. */
|
||||
static struct Dll *make_list (int start, int count) {
|
||||
struct Dll *l = NULL;
|
||||
int i;
|
||||
for (i = start; i != start+count; i++) {
|
||||
struct list_item_s *item =
|
||||
(struct list_item_s *) malloc (sizeof (*item));
|
||||
nsync_dll_init_ (&item->e, item);
|
||||
dll_init (&item->e);
|
||||
item->i = i;
|
||||
l = nsync_dll_make_last_in_list_ (l, &item->e);
|
||||
dll_make_last (&l, &item->e);
|
||||
}
|
||||
return (l);
|
||||
}
|
||||
|
||||
/* Return a new list containing the count integers from start to
|
||||
start+count-1 by prefixing the list with elements, starting with the last.
|
||||
It exercises nsync_dll_make_first_in_list_() using singleton elements. */
|
||||
static nsync_dll_list_ make_rlist (int start, int count) {
|
||||
nsync_dll_list_ l = NULL;
|
||||
It exercises dll_make_first() using singleton elements. */
|
||||
static struct Dll *make_rlist (int start, int count) {
|
||||
struct Dll *l = NULL;
|
||||
int i;
|
||||
for (i = start + count - 1; i != start-1; i--) {
|
||||
struct list_item_s *item =
|
||||
(struct list_item_s *) malloc (sizeof (*item));
|
||||
nsync_dll_init_ (&item->e, item);
|
||||
dll_init (&item->e);
|
||||
item->i = i;
|
||||
l = nsync_dll_make_first_in_list_ (l, &item->e);
|
||||
dll_make_first (&l, &item->e);
|
||||
}
|
||||
return (l);
|
||||
}
|
||||
|
@ -190,16 +191,16 @@ static void test_dll (testing t) {
|
|||
a_int expected;
|
||||
struct list_item_s *item;
|
||||
|
||||
nsync_dll_list_ empty = NULL;
|
||||
nsync_dll_list_ list = NULL;
|
||||
struct Dll *empty = NULL;
|
||||
struct Dll *list = NULL;
|
||||
|
||||
nsync_dll_list_ x10 = NULL;
|
||||
nsync_dll_list_ x20 = NULL;
|
||||
nsync_dll_list_ x30 = NULL;
|
||||
nsync_dll_list_ x40 = NULL;
|
||||
nsync_dll_list_ x50 = NULL;
|
||||
struct Dll *x10 = NULL;
|
||||
struct Dll *x20 = NULL;
|
||||
struct Dll *x30 = NULL;
|
||||
struct Dll *x40 = NULL;
|
||||
struct Dll *x50 = NULL;
|
||||
|
||||
memset (&expected, 0, sizeof (expected));
|
||||
bzero (&expected, sizeof (expected));
|
||||
|
||||
/* All lists are initially empty. */
|
||||
verify_list (t, "empty (0)", empty, &a_int_empty, __FILE__, __LINE__);
|
||||
|
@ -223,61 +224,60 @@ static void test_dll (testing t) {
|
|||
verify_list (t, "x50", x50, a_set (&expected, 50, 51, 52, -1), __FILE__, __LINE__);
|
||||
|
||||
/* Check that adding nothing to an empty list leaves it empty. */
|
||||
list = nsync_dll_make_first_in_list_ (list, NULL);
|
||||
dll_make_first (&list, NULL);
|
||||
verify_list (t, "list(1)", list, &a_int_empty, __FILE__, __LINE__);
|
||||
list = nsync_dll_make_first_in_list_ (list, nsync_dll_first_ (empty));
|
||||
dll_make_first (&list, dll_first (empty));
|
||||
verify_list (t, "list(2)", list, &a_int_empty, __FILE__, __LINE__);
|
||||
list = nsync_dll_make_first_in_list_ (list, nsync_dll_last_ (empty));
|
||||
dll_make_first (&list, dll_last (empty));
|
||||
verify_list (t, "list(3)", list, &a_int_empty, __FILE__, __LINE__);
|
||||
|
||||
/* Prefix an empty list with some elements. */
|
||||
list = nsync_dll_make_first_in_list_ (list, nsync_dll_first_ (x10));
|
||||
dll_make_first (&list, dll_first (x10));
|
||||
verify_list (t, "list(4)", list, a_set (&expected, 10, 11, 12, -1),
|
||||
__FILE__, __LINE__);
|
||||
|
||||
/* Check that adding nothing no a non-empty list leaves it unchanged. */
|
||||
list = nsync_dll_make_first_in_list_ (list, NULL);
|
||||
dll_make_first (&list, NULL);
|
||||
verify_list (t, "list(5)", list, a_set (&expected, 10, 11, 12, -1),
|
||||
__FILE__, __LINE__);
|
||||
list = nsync_dll_make_first_in_list_ (list, nsync_dll_first_ (empty));
|
||||
dll_make_first (&list, dll_first (empty));
|
||||
verify_list (t, "list(6)", list, a_set (&expected, 10, 11, 12, -1),
|
||||
__FILE__, __LINE__);
|
||||
list = nsync_dll_make_first_in_list_ (list, nsync_dll_last_ (empty));
|
||||
dll_make_first (&list, dll_last (empty));
|
||||
verify_list (t, "list(7)", list, a_set (&expected, 10, 11, 12, -1),
|
||||
__FILE__, __LINE__);
|
||||
|
||||
/* Check prefixing the list with some elements. */
|
||||
list = nsync_dll_make_first_in_list_ (list, nsync_dll_first_ (x20));
|
||||
dll_make_first (&list, dll_first (x20));
|
||||
verify_list (t, "list(8)", list,
|
||||
a_set (&expected, 20, 21, 22, 10, 11, 12, -1),
|
||||
__FILE__, __LINE__);
|
||||
|
||||
/* Check appending elements to list. */
|
||||
list = nsync_dll_make_last_in_list_ (list, nsync_dll_last_ (x30));
|
||||
dll_make_last (&list, dll_last (x30));
|
||||
verify_list (t, "list(9)", list,
|
||||
a_set (&expected, 20, 21, 22, 10, 11, 12, 30, 31, 32, -1),
|
||||
__FILE__, __LINE__);
|
||||
|
||||
/* Remove the first element. */
|
||||
item = (struct list_item_s *) nsync_dll_first_ (list)->container;
|
||||
list = nsync_dll_remove_ (list, &item->e);
|
||||
item = (struct list_item_s *) LIST_ITEM (dll_first (list));
|
||||
dll_remove (&list, &item->e);
|
||||
verify_list (t, "list(10)", list,
|
||||
a_set (&expected, 21, 22, 10, 11, 12, 30, 31, 32, -1),
|
||||
__FILE__, __LINE__);
|
||||
free (item);
|
||||
|
||||
/* Remove the last element. */
|
||||
item = (struct list_item_s *) nsync_dll_last_ (list)->container;
|
||||
list = nsync_dll_remove_ (list, &item->e);
|
||||
item = (struct list_item_s *) LIST_ITEM (dll_last (list));
|
||||
dll_remove (&list, &item->e);
|
||||
verify_list (t, "list(11)", list,
|
||||
a_set (&expected, 21, 22, 10, 11, 12, 30, 31, -1),
|
||||
__FILE__, __LINE__);
|
||||
free (item);
|
||||
|
||||
/* Remove the third element. */
|
||||
item = (struct list_item_s *) nsync_dll_next_ (list,
|
||||
nsync_dll_next_ (list, nsync_dll_first_ (list)))->container;
|
||||
list = nsync_dll_remove_ (list, &item->e);
|
||||
item = LIST_ITEM (dll_next (list, dll_next (list, dll_first (list))));
|
||||
dll_remove (&list, &item->e);
|
||||
verify_list (t, "list(12)",
|
||||
list, a_set (&expected, 21, 22, 11, 12, 30, 31, -1),
|
||||
__FILE__, __LINE__);
|
||||
|
@ -285,10 +285,10 @@ static void test_dll (testing t) {
|
|||
|
||||
/* Remove all elements. */
|
||||
a_set (&expected, 21, 22, 11, 12, 30, 31, -1);
|
||||
for (i = 0; !nsync_dll_is_empty_ (list); i++) {
|
||||
for (i = 0; !dll_is_empty (list); i++) {
|
||||
char buf[32];
|
||||
item = (struct list_item_s *) nsync_dll_first_ (list)->container;
|
||||
list = nsync_dll_remove_ (list, &item->e);
|
||||
item = LIST_ITEM (dll_first (list));
|
||||
dll_remove (&list, &item->e);
|
||||
a_remove_first (&expected);
|
||||
snprintf (buf, sizeof (buf), "list(13.%d)", i);
|
||||
verify_list (t, buf, list, &expected, __FILE__, __LINE__);
|
||||
|
@ -297,22 +297,22 @@ static void test_dll (testing t) {
|
|||
verify_list (t, "list(14)", list, &a_int_empty, __FILE__, __LINE__);
|
||||
|
||||
/* Append some elements to an empty list. */
|
||||
list = nsync_dll_make_last_in_list_ (list, nsync_dll_last_ (x40));
|
||||
dll_make_last (&list, dll_last (x40));
|
||||
verify_list (t, "list(15)", list,
|
||||
a_set (&expected, 40, 41, 42, -1), __FILE__, __LINE__);
|
||||
|
||||
/* Use nsync_dll_splice_after_() to put {50, 51, 52} just after 41, which is
|
||||
/* Use dll_splice_after() to put {50, 51, 52} just after 41, which is
|
||||
next (first (list)). */
|
||||
nsync_dll_splice_after_ (nsync_dll_next_ (list, nsync_dll_first_ (list)), nsync_dll_first_ (x50));
|
||||
dll_splice_after (dll_next (list, dll_first (list)), dll_first (x50));
|
||||
verify_list (t, "list(16)", list,
|
||||
a_set (&expected, 40, 41, 50, 51, 52, 42, -1),
|
||||
__FILE__, __LINE__);
|
||||
|
||||
A_FREE (&expected);
|
||||
|
||||
while (!nsync_dll_is_empty_ (list)) {
|
||||
item = (struct list_item_s *) nsync_dll_first_ (list)->container;
|
||||
list = nsync_dll_remove_ (list, &item->e);
|
||||
while (!dll_is_empty (list)) {
|
||||
item = LIST_ITEM (dll_first (list));
|
||||
dll_remove (&list, &item->e);
|
||||
free (item);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ typedef struct starve_data_s {
|
|||
|
||||
/* initialize *sd */
|
||||
static void starve_data_init (starve_data *sd, int threads) {
|
||||
memset ((void *) sd, 0, sizeof (*sd));
|
||||
bzero ((void *) sd, sizeof (*sd));
|
||||
sd->not_yet_started = threads;
|
||||
sd->not_yet_done = threads;
|
||||
sd->start = nsync_time_now ();
|
||||
|
|
18
third_party/nsync/testing/mu_test.c
vendored
18
third_party/nsync/testing/mu_test.c
vendored
|
@ -15,11 +15,11 @@
|
|||
│ See the License for the specific language governing permissions and │
|
||||
│ limitations under the License. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/nsync/mu.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/thread/thread.h"
|
||||
#include "third_party/nsync/cv.h"
|
||||
#include "third_party/nsync/mu.h"
|
||||
#include "third_party/nsync/mu_wait.h"
|
||||
#include "third_party/nsync/testing/closure.h"
|
||||
#include "third_party/nsync/testing/smprintf.h"
|
||||
|
@ -116,7 +116,7 @@ static void test_mu_nthread (testing t) {
|
|||
do {
|
||||
int i;
|
||||
test_data td;
|
||||
memset ((void *) &td, 0, sizeof (td));
|
||||
bzero ((void *) &td, sizeof (td));
|
||||
td.t = t;
|
||||
td.n_threads = 5;
|
||||
td.loop_count = loop_count;
|
||||
|
@ -155,7 +155,7 @@ static void test_mutex_nthread (testing t) {
|
|||
do {
|
||||
int i;
|
||||
test_data td;
|
||||
memset ((void *) &td, 0, sizeof (td));
|
||||
bzero ((void *) &td, sizeof (td));
|
||||
td.t = t;
|
||||
td.n_threads = 5;
|
||||
td.loop_count = loop_count;
|
||||
|
@ -196,7 +196,7 @@ static void test_rwmutex_nthread (testing t) {
|
|||
do {
|
||||
int i;
|
||||
test_data td;
|
||||
memset ((void *) &td, 0, sizeof (td));
|
||||
bzero ((void *) &td, sizeof (td));
|
||||
td.t = t;
|
||||
td.n_threads = 5;
|
||||
td.loop_count = loop_count;
|
||||
|
@ -249,7 +249,7 @@ static void test_try_mu_nthread (testing t) {
|
|||
do {
|
||||
int i;
|
||||
test_data td;
|
||||
memset ((void *) &td, 0, sizeof (td));
|
||||
bzero ((void *) &td, sizeof (td));
|
||||
td.t = t;
|
||||
td.n_threads = 5;
|
||||
td.loop_count = loop_count;
|
||||
|
@ -281,7 +281,7 @@ typedef struct counter_s {
|
|||
/* Return a counter with initial value "initial". */
|
||||
static counter *counter_new (int initial) {
|
||||
counter *c = (counter *) malloc (sizeof (*c));
|
||||
memset ((void *) c, 0, sizeof (*c));
|
||||
bzero ((void *) c, sizeof (*c));
|
||||
c->value = initial;
|
||||
return (c);
|
||||
}
|
||||
|
@ -1023,7 +1023,7 @@ static void contended_state_run_test (contended_state *cs, testing t,
|
|||
nsync_mu locks, with small critical sections. */
|
||||
static void benchmark_mu_contended (testing t) {
|
||||
contended_state cs;
|
||||
memset ((void *) &cs, 0, sizeof (cs));
|
||||
bzero ((void *) &cs, sizeof (cs));
|
||||
contended_state_run_test (&cs, t, &cs.mu, (void (*) (void*))&nsync_mu_lock,
|
||||
(void (*) (void*))&nsync_mu_unlock);
|
||||
}
|
||||
|
@ -1032,7 +1032,7 @@ static void benchmark_mu_contended (testing t) {
|
|||
pthread_mutex_t locks, with small critical sections. */
|
||||
static void benchmark_mutex_contended (testing t) {
|
||||
contended_state cs;
|
||||
memset ((void *) &cs, 0, sizeof (cs));
|
||||
bzero ((void *) &cs, sizeof (cs));
|
||||
pthread_mutex_init (&cs.mutex, NULL);
|
||||
contended_state_run_test (&cs, t, &cs.mutex, &void_pthread_mutex_lock,
|
||||
&void_pthread_mutex_unlock);
|
||||
|
@ -1043,7 +1043,7 @@ static void benchmark_mutex_contended (testing t) {
|
|||
pthread_rwlock_t locks, with small critical sections. */
|
||||
static void benchmark_wmutex_contended (testing t) {
|
||||
contended_state cs;
|
||||
memset ((void *) &cs, 0, sizeof (cs));
|
||||
bzero ((void *) &cs, sizeof (cs));
|
||||
pthread_rwlock_init (&cs.rwmutex, NULL);
|
||||
contended_state_run_test (&cs, t, &cs.rwmutex, &void_pthread_rwlock_wrlock,
|
||||
&void_pthread_rwlock_unlock);
|
||||
|
|
|
@ -148,8 +148,8 @@ static void example_mu_wait (testing t) {
|
|||
"five\n"
|
||||
"timeout 1s\n";
|
||||
|
||||
memset ((void *) &q, 0, sizeof (q));
|
||||
memset (&output, 0, sizeof (output));
|
||||
bzero ((void *) &q, sizeof (q));
|
||||
bzero (&output, sizeof (output));
|
||||
|
||||
closure_fork (closure_add_and_wait_mu (&add_and_wait_mu, &q, nsync_time_ms (500),
|
||||
NELEM (input), input));
|
||||
|
|
4
third_party/nsync/testing/mu_wait_test.c
vendored
4
third_party/nsync/testing/mu_wait_test.c
vendored
|
@ -15,10 +15,10 @@
|
|||
│ See the License for the specific language governing permissions and │
|
||||
│ limitations under the License. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/nsync/mu_wait.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "third_party/nsync/mu.h"
|
||||
#include "third_party/nsync/mu_wait.h"
|
||||
#include "third_party/nsync/note.h"
|
||||
#include "third_party/nsync/testing/closure.h"
|
||||
#include "third_party/nsync/testing/smprintf.h"
|
||||
|
@ -44,7 +44,7 @@ static mu_queue *mu_queue_new (int limit) {
|
|||
mu_queue *q;
|
||||
int size = offsetof (struct mu_queue_s, data) + sizeof (q->data[0]) * limit;
|
||||
q = (mu_queue *) malloc (size);
|
||||
memset ((void *) q, 0, size);
|
||||
bzero ((void *) q, size);
|
||||
q->limit = limit;
|
||||
return (q);
|
||||
}
|
||||
|
|
4
third_party/nsync/testing/once_test.c
vendored
4
third_party/nsync/testing/once_test.c
vendored
|
@ -15,11 +15,11 @@
|
|||
│ See the License for the specific language governing permissions and │
|
||||
│ limitations under the License. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/nsync/once.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/thread/thread.h"
|
||||
#include "third_party/nsync/counter.h"
|
||||
#include "third_party/nsync/mu.h"
|
||||
#include "third_party/nsync/once.h"
|
||||
#include "third_party/nsync/testing/closure.h"
|
||||
#include "third_party/nsync/testing/smprintf.h"
|
||||
#include "third_party/nsync/testing/testing.h"
|
||||
|
@ -99,7 +99,7 @@ static void test_once_run (testing t) {
|
|||
for (i = 0; i != 250; i++) {
|
||||
struct once_test_s *s =
|
||||
(struct once_test_s *) malloc (sizeof (*s));
|
||||
memset ((void *) s, 0, sizeof (*s));
|
||||
bzero ((void *) s, sizeof (*s));
|
||||
s->counter = 0;
|
||||
s->done = nsync_counter_new (N);
|
||||
s->t = t;
|
||||
|
|
2
third_party/nsync/testing/pingpong_test.c
vendored
2
third_party/nsync/testing/pingpong_test.c
vendored
|
@ -53,7 +53,7 @@ typedef struct ping_pong_s {
|
|||
} ping_pong;
|
||||
|
||||
static void ping_pong_init (ping_pong *pp, int limit) {
|
||||
memset ((void *) pp, 0, sizeof (*pp));
|
||||
bzero ((void *) pp, sizeof (*pp));
|
||||
pthread_mutex_init (&pp->mutex, NULL);
|
||||
pthread_rwlock_init (&pp->rwmutex, NULL);
|
||||
pthread_cond_init (&pp->cond[0], NULL);
|
||||
|
|
19
third_party/nsync/testing/testing.c
vendored
19
third_party/nsync/testing/testing.c
vendored
|
@ -15,6 +15,7 @@
|
|||
│ See the License for the specific language governing permissions and │
|
||||
│ limitations under the License. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/nsync/testing/testing.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/limits.h"
|
||||
|
@ -25,14 +26,12 @@
|
|||
#include "libc/str/str.h"
|
||||
#include "third_party/nsync/atomic.internal.h"
|
||||
#include "third_party/nsync/common.internal.h"
|
||||
#include "third_party/nsync/dll.h"
|
||||
#include "third_party/nsync/mu.h"
|
||||
#include "third_party/nsync/mu_wait.h"
|
||||
#include "third_party/nsync/races.internal.h"
|
||||
#include "third_party/nsync/testing/atm_log.h"
|
||||
#include "third_party/nsync/testing/closure.h"
|
||||
#include "third_party/nsync/testing/smprintf.h"
|
||||
#include "third_party/nsync/testing/testing.h"
|
||||
#include "third_party/nsync/testing/time_extra.h"
|
||||
// clang-format off
|
||||
|
||||
|
@ -55,7 +54,7 @@ struct testing_base_s {
|
|||
|
||||
nsync_mu testing_mu; /* protects fields below */
|
||||
int is_uniprocessor; /* whether the system is a uniprocessor */
|
||||
nsync_dll_list_ children; /* list of testing_s structs whose base is this testing_base_s */
|
||||
struct Dll *children; /* list of testing_s structs whose base is this testing_base_s */
|
||||
int child_count; /* count of testing_s structs whose base is this testing_base_s */
|
||||
int exit_status; /* final exit status */
|
||||
};
|
||||
|
@ -70,7 +69,7 @@ struct testing_s {
|
|||
nsync_time stop_time; /* when the timer was stopped; for benchmarks */
|
||||
void (*f) (testing); /* test function to run */
|
||||
const char *name; /* name of test */
|
||||
nsync_dll_element_ siblings; /* part of list of siblings */
|
||||
struct Dll siblings; /* part of list of siblings */
|
||||
};
|
||||
|
||||
/* Output the header for benchmarks. */
|
||||
|
@ -147,7 +146,7 @@ testing_base testing_new (int argc, char *argv[], int flags) {
|
|||
int argn;
|
||||
testing_base tb = (testing_base)malloc (sizeof (*tb));
|
||||
ShowCrashReports ();
|
||||
memset ((void *) tb, 0, sizeof (*tb));
|
||||
bzero ((void *) tb, sizeof (*tb));
|
||||
tb->flags = flags;
|
||||
tb->fp = stderr;
|
||||
tb->argc = argc;
|
||||
|
@ -224,7 +223,7 @@ static void finish_run (testing t) {
|
|||
if (tb->exit_status < t->test_status) {
|
||||
tb->exit_status = t->test_status;
|
||||
}
|
||||
tb->children = nsync_dll_remove_ (tb->children, &t->siblings);
|
||||
dll_remove (&tb->children, &t->siblings);
|
||||
tb->child_count--;
|
||||
nsync_mu_unlock (&tb->testing_mu);
|
||||
free (t);
|
||||
|
@ -358,8 +357,8 @@ void testing_run_ (testing_base tb, void (*f) (testing t), const char *name, int
|
|||
(tb->include_pat == NULL || match (tb->include_pat, name)) &&
|
||||
(tb->exclude_pat == NULL || !match (tb->exclude_pat, name))) {
|
||||
testing t = (testing) malloc (sizeof (*t));
|
||||
memset ((void *) t, 0, sizeof (*t));
|
||||
nsync_dll_init_ (&t->siblings, t);
|
||||
bzero ((void *) t, sizeof (*t));
|
||||
dll_init (&t->siblings);
|
||||
t->base = tb;
|
||||
t->f = f;
|
||||
t->name = name;
|
||||
|
@ -378,7 +377,7 @@ void testing_run_ (testing_base tb, void (*f) (testing t), const char *name, int
|
|||
nsync_mu_lock (&tb->testing_mu);
|
||||
nsync_mu_wait (&tb->testing_mu, &spare_thread, tb, NULL);
|
||||
tb->child_count++;
|
||||
tb->children = nsync_dll_make_last_in_list_ (tb->children, &t->siblings);
|
||||
dll_make_last (&tb->children, &t->siblings);
|
||||
nsync_mu_unlock (&tb->testing_mu);
|
||||
closure_fork (closure_testing (&run_test, t));
|
||||
} else {
|
||||
|
@ -394,7 +393,7 @@ void testing_run_ (testing_base tb, void (*f) (testing t), const char *name, int
|
|||
nsync_mu_lock (&tb->testing_mu);
|
||||
nsync_mu_wait (&tb->testing_mu, &spare_thread, tb, NULL);
|
||||
tb->child_count++;
|
||||
tb->children = nsync_dll_make_last_in_list_ (tb->children, &t->siblings);
|
||||
dll_make_last (&tb->children, &t->siblings);
|
||||
nsync_mu_unlock (&tb->testing_mu);
|
||||
closure_fork (closure_testing (&run_benchmark, t));
|
||||
}
|
||||
|
|
4
third_party/nsync/testing/wait_test.c
vendored
4
third_party/nsync/testing/wait_test.c
vendored
|
@ -60,8 +60,8 @@ static void test_wait_n (testing t) {
|
|||
nsync_time deadline;
|
||||
a_waitable aw;
|
||||
a_pwaitable apw;
|
||||
memset (&aw, 0, sizeof (aw));
|
||||
memset (&apw, 0, sizeof (apw));
|
||||
bzero (&aw, sizeof (aw));
|
||||
bzero (&apw, sizeof (apw));
|
||||
now = nsync_time_now ();
|
||||
deadline = nsync_time_add (now, nsync_time_ms (100));
|
||||
for (j = A_LEN (&aw); A_LEN (&aw) < j+ncounter;) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue