summaryrefslogtreecommitdiffstatsci
path: root/tests/multithreading
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2024-10-27 20:03:31 +0000
committerj-p <jp_bruyere@hotmail.com>2025-03-24 19:12:00 +0100
commit15ecf40ff47bfbdedddd3161b7d6d9d1418e64bb (patch)
tree49001433bd5b102118593642bf1a749494e7ea54 /tests/multithreading
parent7b2f17b8d8f3763d974c52bfbe9a429779aa6f7b (diff)
clang format
Diffstat (limited to 'tests/multithreading')
-rw-r--r--tests/multithreading/multithreaded.c91
-rw-r--r--tests/multithreading/multithreaded2.c79
-rw-r--r--tests/multithreading/threaded_create_surf.c61
-rw-r--r--tests/multithreading/threaded_text.c106
4 files changed, 166 insertions, 171 deletions
diff --git a/tests/multithreading/multithreaded.c b/tests/multithreading/multithreaded.c
index 05ee038..280261d 100644
--- a/tests/multithreading/multithreaded.c
+++ b/tests/multithreading/multithreaded.c
@@ -7,70 +7,69 @@
#define THREAD_COUNT 32
+static int finishedThreadCount = 0;
+static mtx_t *pmutex;
-static int finishedThreadCount = 0;
-static mtx_t* pmutex;
+void drawRandomRect(VkvgContext ctx, float s) {
+ float w = (float)test_width;
+ float h = (float)test_height;
+ randomize_color(ctx);
-void drawRandomRect (VkvgContext ctx, float s) {
- float w = (float)test_width;
- float h = (float)test_height;
- randomize_color(ctx);
+ float x = truncf(w * rndf());
+ float y = truncf(h * rndf());
- float x = truncf(w*rndf());
- float y = truncf(h*rndf());
-
- vkvg_rectangle(ctx, x, y, s, s);
+ vkvg_rectangle(ctx, x, y, s, s);
}
-int drawRectsThread () {
+int drawRectsThread() {
- VkvgSurface s = vkvg_surface_create(device, test_width, test_height);
- VkvgContext ctx = vkvg_create(s);
- for (uint32_t i=0; i<test_size; i++) {
- drawRandomRect(ctx, 14.0f);
- vkvg_fill (ctx);
- }
- vkvg_destroy(ctx);
+ VkvgSurface s = vkvg_surface_create(device, test_width, test_height);
+ VkvgContext ctx = vkvg_create(s);
+ for (uint32_t i = 0; i < test_size; i++) {
+ drawRandomRect(ctx, 14.0f);
+ vkvg_fill(ctx);
+ }
+ vkvg_destroy(ctx);
- mtx_lock(pmutex);
+ mtx_lock(pmutex);
- ctx = vkvg_create(surf);
- vkvg_set_source_surface (ctx, s, 0, 0);
- vkvg_paint(ctx);
- vkvg_destroy(ctx);
+ ctx = vkvg_create(surf);
+ vkvg_set_source_surface(ctx, s, 0, 0);
+ vkvg_paint(ctx);
+ vkvg_destroy(ctx);
- finishedThreadCount++;
- mtx_unlock(pmutex);
+ finishedThreadCount++;
+ mtx_unlock(pmutex);
- vkvg_surface_destroy (s);
- return 0;
+ vkvg_surface_destroy(s);
+ return 0;
}
-void fixedSizeRects(){
- mtx_t mutex;
- pmutex = &mutex;
+void fixedSizeRects() {
+ mtx_t mutex;
+ pmutex = &mutex;
- vkvg_device_set_thread_aware (device, 1);
+ vkvg_device_set_thread_aware(device, 1);
- thrd_t threads[THREAD_COUNT];
+ thrd_t threads[THREAD_COUNT];
- finishedThreadCount = 0;
- mtx_init (pmutex, mtx_plain);
- for (uint32_t i=0; i<THREAD_COUNT; i++)
- thrd_create (&threads[i], drawRectsThread, NULL);
+ finishedThreadCount = 0;
+ mtx_init(pmutex, mtx_plain);
+ for (uint32_t i = 0; i < THREAD_COUNT; i++)
+ thrd_create(&threads[i], drawRectsThread, NULL);
- const struct timespec ts = {1,0};
- while (finishedThreadCount < THREAD_COUNT)
- thrd_sleep(&ts, NULL);
+ const struct timespec ts = {1, 0};
+ while (finishedThreadCount < THREAD_COUNT)
+ thrd_sleep(&ts, NULL);
- mtx_lock(pmutex);
- mtx_unlock(pmutex);
- mtx_destroy (pmutex);
- pmutex = NULL;
+ mtx_lock(pmutex);
+ mtx_unlock(pmutex);
+ mtx_destroy(pmutex);
+ pmutex = NULL;
- vkvg_device_set_thread_aware (device, 0);
+ vkvg_device_set_thread_aware(device, 0);
}
int main(int argc, char *argv[]) {
- PERFORM_TEST (fixedSizeRects, argc, argv);
- return 0;
+ PERFORM_TEST(fixedSizeRects, argc, argv);
+ return 0;
}
diff --git a/tests/multithreading/multithreaded2.c b/tests/multithreading/multithreaded2.c
index a29e006..7eff7a0 100644
--- a/tests/multithreading/multithreaded2.c
+++ b/tests/multithreading/multithreaded2.c
@@ -6,58 +6,57 @@
#define THREAD_COUNT 32
+static int finishedThreadCount = 0;
+static mtx_t *pmutex;
-static int finishedThreadCount = 0;
-static mtx_t* pmutex;
+void drawRandomRect(VkvgContext ctx, float s) {
+ float w = (float)test_width;
+ float h = (float)test_height;
+ randomize_color(ctx);
-void drawRandomRect (VkvgContext ctx, float s) {
- float w = (float)test_width;
- float h = (float)test_height;
- randomize_color(ctx);
+ float x = truncf(w * rndf());
+ float y = truncf(h * rndf());
- float x = truncf(w*rndf());
- float y = truncf(h*rndf());
-
- vkvg_rectangle(ctx, x, y, s, s);
+ vkvg_rectangle(ctx, x, y, s, s);
}
-int drawRectsThread () {
- VkvgContext ctx = vkvg_create(surf);
- for (uint32_t i=0; i<test_size; i++) {
- drawRandomRect(ctx, 14.0f);
- vkvg_fill (ctx);
- }
- vkvg_destroy (ctx);
- mtx_lock (pmutex);
- finishedThreadCount++;
- mtx_unlock (pmutex);
- return 0;
+int drawRectsThread() {
+ VkvgContext ctx = vkvg_create(surf);
+ for (uint32_t i = 0; i < test_size; i++) {
+ drawRandomRect(ctx, 14.0f);
+ vkvg_fill(ctx);
+ }
+ vkvg_destroy(ctx);
+ mtx_lock(pmutex);
+ finishedThreadCount++;
+ mtx_unlock(pmutex);
+ return 0;
}
-void fixedSizeRects(){
- mtx_t mutex;
- pmutex = &mutex;
+void fixedSizeRects() {
+ mtx_t mutex;
+ pmutex = &mutex;
- vkvg_device_set_thread_aware (device, 1);
+ vkvg_device_set_thread_aware(device, 1);
- thrd_t threads[THREAD_COUNT];
+ thrd_t threads[THREAD_COUNT];
- finishedThreadCount = 0;
- mtx_init (pmutex, mtx_plain);
- for (uint32_t i=0; i<THREAD_COUNT; i++)
- thrd_create (&threads[i], drawRectsThread, NULL);
+ finishedThreadCount = 0;
+ mtx_init(pmutex, mtx_plain);
+ for (uint32_t i = 0; i < THREAD_COUNT; i++)
+ thrd_create(&threads[i], drawRectsThread, NULL);
- const struct timespec ts = {1,0};
- while (finishedThreadCount < THREAD_COUNT)
- thrd_sleep(&ts, NULL);
+ const struct timespec ts = {1, 0};
+ while (finishedThreadCount < THREAD_COUNT)
+ thrd_sleep(&ts, NULL);
- mtx_lock(pmutex);
- mtx_unlock(pmutex);
- mtx_destroy (pmutex);
- pmutex = NULL;
+ mtx_lock(pmutex);
+ mtx_unlock(pmutex);
+ mtx_destroy(pmutex);
+ pmutex = NULL;
- vkvg_device_set_thread_aware (device, 0);
+ vkvg_device_set_thread_aware(device, 0);
}
int main(int argc, char *argv[]) {
- PERFORM_TEST (fixedSizeRects, argc, argv);
- return 0;
+ PERFORM_TEST(fixedSizeRects, argc, argv);
+ return 0;
}
diff --git a/tests/multithreading/threaded_create_surf.c b/tests/multithreading/threaded_create_surf.c
index 9789565..f7e8d80 100644
--- a/tests/multithreading/threaded_create_surf.c
+++ b/tests/multithreading/threaded_create_surf.c
@@ -3,48 +3,47 @@
#define THREAD_COUNT 16
+static int finishedThreadCount = 0;
+static mtx_t *pmutex;
-static int finishedThreadCount = 0;
-static mtx_t* pmutex;
+int create_surfs() {
+ for (uint32_t i = 0; i < test_size; i++) {
+ VkvgSurface s = vkvg_surface_create(device, test_width, test_height);
+ vkvg_surface_destroy(s);
+ }
-int create_surfs () {
- for (uint32_t i=0; i<test_size; i++) {
- VkvgSurface s = vkvg_surface_create(device, test_width, test_height);
- vkvg_surface_destroy (s);
- }
-
- mtx_lock(pmutex);
- finishedThreadCount++;
- mtx_unlock(pmutex);
- return 0;
+ mtx_lock(pmutex);
+ finishedThreadCount++;
+ mtx_unlock(pmutex);
+ return 0;
}
-void fixedSizeRects(){
- mtx_t mutex;
- pmutex = &mutex;
+void fixedSizeRects() {
+ mtx_t mutex;
+ pmutex = &mutex;
- vkvg_device_set_thread_aware (device, 1);
+ vkvg_device_set_thread_aware(device, 1);
- thrd_t threads[THREAD_COUNT];
+ thrd_t threads[THREAD_COUNT];
- finishedThreadCount = 0;
- mtx_init (pmutex, mtx_plain);
- for (uint32_t i=0; i<THREAD_COUNT; i++)
- thrd_create (&threads[i], create_surfs, NULL);
+ finishedThreadCount = 0;
+ mtx_init(pmutex, mtx_plain);
+ for (uint32_t i = 0; i < THREAD_COUNT; i++)
+ thrd_create(&threads[i], create_surfs, NULL);
- const struct timespec ts = {1,0};
- while (finishedThreadCount < THREAD_COUNT)
- thrd_sleep(&ts, NULL);
+ const struct timespec ts = {1, 0};
+ while (finishedThreadCount < THREAD_COUNT)
+ thrd_sleep(&ts, NULL);
- mtx_lock(pmutex);
- mtx_unlock(pmutex);
- mtx_destroy (pmutex);
- pmutex = NULL;
+ mtx_lock(pmutex);
+ mtx_unlock(pmutex);
+ mtx_destroy(pmutex);
+ pmutex = NULL;
- vkvg_device_set_thread_aware (device, 0);
+ vkvg_device_set_thread_aware(device, 0);
}
int main(int argc, char *argv[]) {
- PERFORM_TEST (fixedSizeRects, argc, argv);
- return 0;
+ PERFORM_TEST(fixedSizeRects, argc, argv);
+ return 0;
}
diff --git a/tests/multithreading/threaded_text.c b/tests/multithreading/threaded_text.c
index bacf597..8ae18a9 100644
--- a/tests/multithreading/threaded_text.c
+++ b/tests/multithreading/threaded_text.c
@@ -7,77 +7,75 @@
#define THREAD_COUNT 16
-static int finishedThreadCount = 0;
-static mtx_t* pmutex;
+static int finishedThreadCount = 0;
+static mtx_t *pmutex;
-void drawRandomRect (VkvgContext ctx, float s) {
- float w = (float)test_width;
- float h = (float)test_height;
- randomize_color(ctx);
+void drawRandomRect(VkvgContext ctx, float s) {
+ float w = (float)test_width;
+ float h = (float)test_height;
+ randomize_color(ctx);
- float x = truncf(w*rndf());
- float y = truncf(h*rndf());
+ float x = truncf(w * rndf());
+ float y = truncf(h * rndf());
- vkvg_rectangle(ctx, x, y, s, s);
+ vkvg_rectangle(ctx, x, y, s, s);
}
-int _single_font_and_size () {
- VkvgSurface s = vkvg_surface_create(device, test_width, test_height);
- VkvgContext ctx = vkvg_create(s);
- vkvg_clear(ctx);
- for (uint32_t i=0; i<test_size/THREAD_COUNT; i++) {
- randomize_color(ctx);
- float x = rndf() * test_width;
- float y = rndf() * test_height;
- vkvg_select_font_face(ctx,"mono");
- vkvg_set_font_size(ctx, 20);
- vkvg_move_to(ctx,x,y);
- vkvg_show_text(ctx,"This is a test string!");
- }
- vkvg_destroy(ctx);
+int _single_font_and_size() {
+ VkvgSurface s = vkvg_surface_create(device, test_width, test_height);
+ VkvgContext ctx = vkvg_create(s);
+ vkvg_clear(ctx);
+ for (uint32_t i = 0; i < test_size / THREAD_COUNT; i++) {
+ randomize_color(ctx);
+ float x = rndf() * test_width;
+ float y = rndf() * test_height;
+ vkvg_select_font_face(ctx, "mono");
+ vkvg_set_font_size(ctx, 20);
+ vkvg_move_to(ctx, x, y);
+ vkvg_show_text(ctx, "This is a test string!");
+ }
+ vkvg_destroy(ctx);
- mtx_lock(pmutex);
+ mtx_lock(pmutex);
- ctx = vkvg_create(surf);
- vkvg_set_source_surface (ctx, s, 0, 0);
- vkvg_paint(ctx);
- vkvg_destroy(ctx);
+ ctx = vkvg_create(surf);
+ vkvg_set_source_surface(ctx, s, 0, 0);
+ vkvg_paint(ctx);
+ vkvg_destroy(ctx);
- finishedThreadCount++;
- mtx_unlock(pmutex);
+ finishedThreadCount++;
+ mtx_unlock(pmutex);
- vkvg_surface_destroy (s);
- return 0;
+ vkvg_surface_destroy(s);
+ return 0;
}
-void threaded_text(int(*testfunc)(void*)){
- mtx_t mutex;
- pmutex = &mutex;
+void threaded_text(int (*testfunc)(void *)) {
+ mtx_t mutex;
+ pmutex = &mutex;
- vkvg_device_set_thread_aware (device, 1);
+ vkvg_device_set_thread_aware(device, 1);
- thrd_t threads[THREAD_COUNT];
+ thrd_t threads[THREAD_COUNT];
- finishedThreadCount = 0;
- mtx_init (pmutex, mtx_plain);
- for (uint32_t i=0; i<THREAD_COUNT; i++)
- thrd_create (&threads[i], testfunc, NULL);
+ finishedThreadCount = 0;
+ mtx_init(pmutex, mtx_plain);
+ for (uint32_t i = 0; i < THREAD_COUNT; i++)
+ thrd_create(&threads[i], testfunc, NULL);
- const struct timespec ts = {1,0};
- while (finishedThreadCount < THREAD_COUNT)
- thrd_sleep(&ts, NULL);
+ const struct timespec ts = {1, 0};
+ while (finishedThreadCount < THREAD_COUNT)
+ thrd_sleep(&ts, NULL);
- mtx_lock(pmutex);
- mtx_unlock(pmutex);
- mtx_destroy (pmutex);
- pmutex = NULL;
+ mtx_lock(pmutex);
+ mtx_unlock(pmutex);
+ mtx_destroy(pmutex);
+ pmutex = NULL;
- vkvg_device_set_thread_aware (device, 0);
-}
-void single_font_and_size() {
- threaded_text (_single_font_and_size);
+ vkvg_device_set_thread_aware(device, 0);
}
+void single_font_and_size() { threaded_text(_single_font_and_size); }
int main(int argc, char *argv[]) {
- PERFORM_TEST (single_font_and_size, argc, argv);
- return 0;
+ PERFORM_TEST(single_font_and_size, argc, argv);
+ return 0;
}