summaryrefslogtreecommitdiffstatsci
path: root/tests/multithreading/threaded_create_surf.c
blob: c8a587eab28014fe31169052325c66e8103f596c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#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;

    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;
}

int main(int argc, char *argv[]) {
    PERFORM_TEST(fixedSizeRects, argc, argv);
    return 0;
}