From cb116a189f04943562e7e464088ba421be7f4088 Mon Sep 17 00:00:00 2001 From: Mitya Selivanov Date: Sat, 8 Jun 2024 21:14:45 +0200 Subject: Remove LICENSE; Cleanup --- LICENSE | 26 ---------------- build.c | 8 ++--- source/kit/secure_random.c | 2 -- source/kit/secure_random.h | 1 + source/kit/test.h | 26 ---------------- source/tests/_exe.c | 1 + source/tests/atomic.test.c | 77 ++++++++++++++++++++++++---------------------- source/tests/mutex.test.c | 18 ++++++----- 8 files changed, 57 insertions(+), 102 deletions(-) delete mode 100644 LICENSE diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 987606a..0000000 --- a/LICENSE +++ /dev/null @@ -1,26 +0,0 @@ -Copyright (c) 2022-2024 Mitya Selivanov - -HTTP1 -Copyright (c) 2016 Christian C. Sachs - -C11 threads from Mesa -Copyright (c) 2022 Yonggang Luo -Copyright (c) 2012 yohhoy - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/build.c b/build.c index 225a207..ea04495 100755 --- a/build.c +++ b/build.c @@ -130,11 +130,11 @@ c8 *fmt(c8 const *format, ...) { return result; } -void make_fmt_v(c8 const *format, va_list args) { +void fmt_dup_v(c8 const *format, va_list args) { vsprintf(_strings[_string_index], format, args); } -c8 *make_fmt(c8 const *format, ...) { +c8 *fmt_dup(c8 const *format, ...) { va_list args; va_start(args, format); assert(_string_index < STRING_COUNT); @@ -413,9 +413,9 @@ i32 main(i32 argc, c8 **argv) { ""; if (extra_options[0] != '\0') - flags = make_fmt("%s %s", extra_options, flags); + flags = fmt_dup("%s %s", extra_options, flags); if (extra_link_options[0] != '\0') - link_flags = make_fmt("%s %s", extra_link_options, link_flags); + link_flags = fmt_dup("%s %s", extra_link_options, link_flags); // Prepare destination folder // diff --git a/source/kit/secure_random.c b/source/kit/secure_random.c index 2f53866..2565f6f 100644 --- a/source/kit/secure_random.c +++ b/source/kit/secure_random.c @@ -1,7 +1,5 @@ #include "secure_random.h" -#include "status.h" - #include #include #include diff --git a/source/kit/secure_random.h b/source/kit/secure_random.h index d09ea56..435fe88 100644 --- a/source/kit/secure_random.h +++ b/source/kit/secure_random.h @@ -2,6 +2,7 @@ #define KIT_SECURE_RANDOM_H #include "types.h" +#include "status.h" #ifdef __cplusplus extern "C" { diff --git a/source/kit/test.h b/source/kit/test.h index ca2b7c0..3563abc 100644 --- a/source/kit/test.h +++ b/source/kit/test.h @@ -42,32 +42,6 @@ // } // // ================================================================ -// -// The MIT License -// -// Copyright (c) 2022-2024 Mitya Selivanov -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, copy, -// modify, merge, publish, distribute, sublicense, and/or sell copies -// of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// ================================================================ #ifndef KIT_TEST_H #define KIT_TEST_H diff --git a/source/tests/_exe.c b/source/tests/_exe.c index 1c59ba2..01add48 100644 --- a/source/tests/_exe.c +++ b/source/tests/_exe.c @@ -21,6 +21,7 @@ #include "string_ref.test.c" #include "duration.test.c" #include "thread.test.c" +#include "atomic.test.c" #include "xml.test.c" #include "http1.test.c" #include "bench.test.c" diff --git a/source/tests/atomic.test.c b/source/tests/atomic.test.c index d5c172b..ca14959 100644 --- a/source/tests/atomic.test.c +++ b/source/tests/atomic.test.c @@ -5,13 +5,13 @@ #include "../kit/test.h" TEST("atomic store and load") { - ATOMIC(int) value; + int _Atomic value; atomic_store_explicit(&value, 20, memory_order_relaxed); REQUIRE(atomic_load_explicit(&value, memory_order_relaxed) == 20); } TEST("atomic exchange") { - ATOMIC(int) value; + int _Atomic value; atomic_store_explicit(&value, 20, memory_order_relaxed); REQUIRE(atomic_exchange_explicit(&value, 42, memory_order_relaxed) == 20); @@ -19,20 +19,23 @@ TEST("atomic exchange") { } TEST("atomic fetch add") { - ATOMIC(int) value; + int _Atomic value; atomic_store_explicit(&value, 20, memory_order_relaxed); REQUIRE(atomic_fetch_add_explicit(&value, 22, memory_order_relaxed) == 20); REQUIRE(atomic_load_explicit(&value, memory_order_relaxed) == 42); } -enum { THREAD_COUNT = 20, TICK_COUNT = 10000 }; +enum { + TEST_ATOMIC_THREAD_COUNT = 20, + TEST_ATOMIC_TICK_COUNT = 10000, +}; static int test_8_(void *p) { ptrdiff_t i; - ATOMIC(int8_t) *x = (ATOMIC(int8_t) *) p; + int8_t _Atomic *x = (int8_t _Atomic *) p; - for (i = 0; i < TICK_COUNT; i++) { + for (i = 0; i < TEST_ATOMIC_TICK_COUNT; i++) { atomic_fetch_add_explicit(x, 20, memory_order_relaxed); thrd_yield(); atomic_fetch_add_explicit(x, 22, memory_order_relaxed); @@ -45,11 +48,11 @@ static int test_8_(void *p) { } TEST("atomic types") { - ATOMIC(int8_t) b_1; - ATOMIC(int8_t) b_2; - ATOMIC(int16_t) i16; - ATOMIC(int32_t) i32; - ATOMIC(int64_t) i64; + int8_t _Atomic b_1; + int8_t _Atomic b_2; + int16_t _Atomic i16; + int32_t _Atomic i32; + int64_t _Atomic i64; atomic_store_explicit(&b_1, 42, memory_order_relaxed); atomic_store_explicit(&b_2, 43, memory_order_relaxed); @@ -86,18 +89,18 @@ TEST("atomic types") { TEST("atomic byte concurrency") { ptrdiff_t i; - ATOMIC(int8_t) foo; - ATOMIC(int8_t) bar; + int8_t _Atomic foo; + int8_t _Atomic bar; atomic_store_explicit(&foo, 42, memory_order_relaxed); atomic_store_explicit(&bar, 43, memory_order_relaxed); - thrd_t threads[THREAD_COUNT]; - for (i = 0; i < THREAD_COUNT; i++) + thrd_t threads[TEST_ATOMIC_THREAD_COUNT]; + for (i = 0; i < TEST_ATOMIC_THREAD_COUNT; i++) REQUIRE_EQ(thrd_create(threads + i, test_8_, (void *) ((i % 2) ? &foo : &bar)), thrd_success); - for (i = 0; i < THREAD_COUNT; i++) thrd_join(threads[i], NULL); + for (i = 0; i < TEST_ATOMIC_THREAD_COUNT; i++) thrd_join(threads[i], NULL); REQUIRE(atomic_load_explicit(&foo, memory_order_relaxed) == 42); REQUIRE(atomic_load_explicit(&bar, memory_order_relaxed) == 43); @@ -106,9 +109,9 @@ TEST("atomic byte concurrency") { static int test_16_(void *p) { ptrdiff_t i; - ATOMIC(int16_t) *x = (ATOMIC(int16_t) *) p; + int16_t _Atomic *x = (int16_t _Atomic *) p; - for (i = 0; i < TICK_COUNT; i++) { + for (i = 0; i < TEST_ATOMIC_TICK_COUNT; i++) { atomic_fetch_add_explicit(x, 2020, memory_order_relaxed); thrd_yield(); atomic_fetch_add_explicit(x, 2222, memory_order_relaxed); @@ -123,18 +126,18 @@ static int test_16_(void *p) { TEST("atomic int16 concurrency") { ptrdiff_t i; - ATOMIC(int16_t) foo; - ATOMIC(int16_t) bar; + int16_t _Atomic foo; + int16_t _Atomic bar; atomic_store_explicit(&foo, 42, memory_order_relaxed); atomic_store_explicit(&bar, 43, memory_order_relaxed); - thrd_t threads[THREAD_COUNT]; - for (i = 0; i < THREAD_COUNT; i++) + thrd_t threads[TEST_ATOMIC_THREAD_COUNT]; + for (i = 0; i < TEST_ATOMIC_THREAD_COUNT; i++) REQUIRE_EQ(thrd_create(threads + i, test_16_, (void *) ((i % 2) ? &foo : &bar)), thrd_success); - for (i = 0; i < THREAD_COUNT; i++) thrd_join(threads[i], NULL); + for (i = 0; i < TEST_ATOMIC_THREAD_COUNT; i++) thrd_join(threads[i], NULL); REQUIRE(atomic_load_explicit(&foo, memory_order_relaxed) == 42); REQUIRE(atomic_load_explicit(&bar, memory_order_relaxed) == 43); @@ -143,9 +146,9 @@ TEST("atomic int16 concurrency") { static int test_32_(void *p) { ptrdiff_t i; - ATOMIC(int32_t) *x = (ATOMIC(int32_t) *) p; + int32_t _Atomic *x = (int32_t _Atomic *) p; - for (i = 0; i < TICK_COUNT; i++) { + for (i = 0; i < TEST_ATOMIC_TICK_COUNT; i++) { atomic_fetch_add_explicit(x, 202020, memory_order_relaxed); thrd_yield(); atomic_fetch_add_explicit(x, 222222, memory_order_relaxed); @@ -160,18 +163,18 @@ static int test_32_(void *p) { TEST("atomic int32 concurrency") { ptrdiff_t i; - ATOMIC(int32_t) foo; - ATOMIC(int32_t) bar; + int32_t _Atomic foo; + int32_t _Atomic bar; atomic_store_explicit(&foo, 42, memory_order_relaxed); atomic_store_explicit(&bar, 43, memory_order_relaxed); - thrd_t threads[THREAD_COUNT]; - for (i = 0; i < THREAD_COUNT; i++) + thrd_t threads[TEST_ATOMIC_THREAD_COUNT]; + for (i = 0; i < TEST_ATOMIC_THREAD_COUNT; i++) REQUIRE_EQ(thrd_create(threads + i, test_32_, (void *) ((i % 2) ? &foo : &bar)), thrd_success); - for (i = 0; i < THREAD_COUNT; i++) thrd_join(threads[i], NULL); + for (i = 0; i < TEST_ATOMIC_THREAD_COUNT; i++) thrd_join(threads[i], NULL); REQUIRE(atomic_load_explicit(&foo, memory_order_relaxed) == 42); REQUIRE(atomic_load_explicit(&bar, memory_order_relaxed) == 43); @@ -180,9 +183,9 @@ TEST("atomic int32 concurrency") { static int test_64_(void *p) { ptrdiff_t i; - ATOMIC(int64_t) *x = (ATOMIC(int64_t) *) p; + int64_t _Atomic *x = (int64_t _Atomic *) p; - for (i = 0; i < TICK_COUNT; i++) { + for (i = 0; i < TEST_ATOMIC_TICK_COUNT; i++) { atomic_fetch_add_explicit(x, 20202020202020ll, memory_order_relaxed); thrd_yield(); @@ -200,18 +203,18 @@ static int test_64_(void *p) { TEST("atomic int64 concurrency") { ptrdiff_t i; - ATOMIC(int64_t) foo; - ATOMIC(int64_t) bar; + int64_t _Atomic foo; + int64_t _Atomic bar; atomic_store_explicit(&foo, 42, memory_order_relaxed); atomic_store_explicit(&bar, 43, memory_order_relaxed); - thrd_t threads[THREAD_COUNT]; - for (i = 0; i < THREAD_COUNT; i++) + thrd_t threads[TEST_ATOMIC_THREAD_COUNT]; + for (i = 0; i < TEST_ATOMIC_THREAD_COUNT; i++) REQUIRE_EQ(thrd_create(threads + i, test_64_, (void *) ((i % 2) ? &foo : &bar)), thrd_success); - for (i = 0; i < THREAD_COUNT; i++) thrd_join(threads[i], NULL); + for (i = 0; i < TEST_ATOMIC_THREAD_COUNT; i++) thrd_join(threads[i], NULL); REQUIRE(atomic_load_explicit(&foo, memory_order_relaxed) == 42); REQUIRE(atomic_load_explicit(&bar, memory_order_relaxed) == 43); diff --git a/source/tests/mutex.test.c b/source/tests/mutex.test.c index 61c1caa..9261fb1 100644 --- a/source/tests/mutex.test.c +++ b/source/tests/mutex.test.c @@ -3,7 +3,11 @@ #define KIT_TEST_FILE mutex #include "../kit/test.h" -enum { SLEEP = 400000000, TICK_COUNT = 200, THREAD_COUNT = 100 }; +enum { + TEST_MUTEX_SLEEP = 400000000, + TEST_MUTEX_TICK_COUNT = 200, + TEST_MUTEX_THREAD_COUNT = 100, +}; typedef struct { mtx_t lock; @@ -13,7 +17,7 @@ typedef struct { static int mtx_test_run(void *data) { int i; mtx_test_data_t *x = (mtx_test_data_t *) data; - for (i = 0; i < TICK_COUNT; i++) { + for (i = 0; i < TEST_MUTEX_TICK_COUNT; i++) { mtx_lock(&x->lock); x->value += i; @@ -33,13 +37,13 @@ TEST("mutex lock") { ptrdiff_t i; mtx_test_data_t data; - thrd_t pool[THREAD_COUNT]; + thrd_t pool[TEST_MUTEX_THREAD_COUNT]; data.value = 42; REQUIRE(mtx_init(&data.lock, mtx_plain) == thrd_success); - for (i = 0; i < THREAD_COUNT; i++) + for (i = 0; i < TEST_MUTEX_THREAD_COUNT; i++) thrd_create(pool + i, mtx_test_run, &data); - for (i = 0; i < THREAD_COUNT; i++) thrd_join(pool[i], NULL); + for (i = 0; i < TEST_MUTEX_THREAD_COUNT; i++) thrd_join(pool[i], NULL); mtx_destroy(&data.lock); REQUIRE(data.value == 42); @@ -49,7 +53,7 @@ static int test_lock(void *data) { mtx_t *m = (mtx_t *) data; mtx_lock(m); - struct timespec sec = { .tv_sec = 0, .tv_nsec = SLEEP }; + struct timespec sec = { .tv_sec = 0, .tv_nsec = TEST_MUTEX_SLEEP }; thrd_sleep(&sec, NULL); mtx_unlock(m); @@ -64,7 +68,7 @@ TEST("mutex try lock") { thrd_t t; REQUIRE(thrd_create(&t, test_lock, &m) == thrd_success); - struct timespec sec = { .tv_sec = 0, .tv_nsec = SLEEP / 2 }; + struct timespec sec = { .tv_sec = 0, .tv_nsec = TEST_MUTEX_SLEEP / 2 }; REQUIRE(thrd_sleep(&sec, NULL) == thrd_success); REQUIRE(mtx_trylock(&m) == thrd_busy); -- cgit v1.2.3