summaryrefslogtreecommitdiffstatsci
path: root/tests/multithreading/multithreaded2.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/multithreading/multithreaded2.c')
-rw-r--r--tests/multithreading/multithreaded2.c79
1 files changed, 39 insertions, 40 deletions
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;
}