diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2022-02-18 15:49:55 +0100 |
|---|---|---|
| committer | j-p <jp_bruyere@hotmail.com> | 2022-02-18 21:09:23 +0100 |
| commit | e7f0aae994656c2b8893bbf673d3659ea7bd8f7f (patch) | |
| tree | 247d5863abf0b35b3bb73b7f3a2d7f0aeb54a0ac /tests | |
| parent | 595d435b5414ae3c52a4f54345dcda49ce3e4d39 (diff) | |
buggy font cache mutex guarding, multithreaded tests
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/multithreading/multithreaded.c | 6 | ||||
| -rw-r--r-- | tests/multithreading/multithreaded2.c | 17 | ||||
| -rw-r--r-- | tests/multithreading/threaded_create_surf.c | 50 |
3 files changed, 62 insertions, 11 deletions
diff --git a/tests/multithreading/multithreaded.c b/tests/multithreading/multithreaded.c index bd14e84..4981860 100644 --- a/tests/multithreading/multithreaded.c +++ b/tests/multithreading/multithreaded.c @@ -1,7 +1,11 @@ +/* + * multiple contexts in separate thread on temp surface for each thread + * guarded blit on final surface. + */ #include "test.h" #include "tinycthread.h" -#define THREAD_COUNT 16 +#define THREAD_COUNT 64 static int finishedThreadCount = 0; diff --git a/tests/multithreading/multithreaded2.c b/tests/multithreading/multithreaded2.c index 0485d13..7821581 100644 --- a/tests/multithreading/multithreaded2.c +++ b/tests/multithreading/multithreaded2.c @@ -1,3 +1,6 @@ +/* + * drawing from multiple contexts in separate threads on a single unguarded surface + */ #include "test.h" #include "tinycthread.h" @@ -17,23 +20,16 @@ void drawRandomRect (VkvgContext ctx, float s) { vkvg_rectangle(ctx, x, y, s, s); } -void _before_submit (void* data) { - mtx_lock((mtx_t*)data); -} -void _after_submit (void* data) { - mtx_unlock((mtx_t*)data); -} - 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); + vkvg_destroy (ctx); + mtx_lock (pmutex); finishedThreadCount++; - mtx_unlock(pmutex); + mtx_unlock (pmutex); return 0; } void fixedSizeRects(){ @@ -62,6 +58,7 @@ void fixedSizeRects(){ } int main(int argc, char *argv[]) { + vkvg_log_level = VKVG_LOG_ERR|VKVG_LOG_DEBUG;//|VKVG_LOG_INFO|VKVG_LOG_INFO_PATH|VKVG_LOG_DBG_ARRAYS|VKVG_LOG_FULL; PERFORM_TEST (fixedSizeRects, argc, argv); return 0; } diff --git a/tests/multithreading/threaded_create_surf.c b/tests/multithreading/threaded_create_surf.c new file mode 100644 index 0000000..9789565 --- /dev/null +++ b/tests/multithreading/threaded_create_surf.c @@ -0,0 +1,50 @@ +#include "test.h" +#include "tinycthread.h" + +#define THREAD_COUNT 16 + + +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); + } + + mtx_lock(pmutex); + finishedThreadCount++; + mtx_unlock(pmutex); + return 0; +} + +void fixedSizeRects(){ + mtx_t mutex; + pmutex = &mutex; + + vkvg_device_set_thread_aware (device, 1); + + 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); + + 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; + + vkvg_device_set_thread_aware (device, 0); +} + +int main(int argc, char *argv[]) { + PERFORM_TEST (fixedSizeRects, argc, argv); + return 0; +} |