Now I'm kinda happy with the threads.

This commit is contained in:
Marcel Plch 2024-11-14 12:19:53 +01:00
parent e47a6d26cd
commit 9fe8afb68a
Signed by: dormouse
GPG key ID: 2CA77596BC4BDFFE
2 changed files with 11 additions and 2 deletions

View file

@ -33,6 +33,7 @@ typedef struct _cx_gl_ctx {
ModelRegistry *mr;
GLuint *VertexArrayIDs;
void (*free)(void *self);
uint8_t master_lock;
size_t VertexArray_count;
size_t VertexArray_size;
GLuint *programIDs;
@ -45,6 +46,7 @@ typedef struct _cx_nn_ctx {
float *input_buffer;
float *output_buffer;
void (*free)(void *self);
uint8_t master_lock;
} CX_NN_CTX;
typedef struct _cx_ctx {

View file

@ -230,7 +230,10 @@ cx_glrun(CX_GL_CTX *ctx) {
glfwGetCursorPos(ctx->window, &xpos, &ypos);
do {
// Skip render step if context is locked.
if (!ctx->master_lock) {
cx_glrender(ctx->window, ctx->programIDs[0], ctx->mr);
}
usleep(1000000/60);
// Check if the ESC key was pressed or the window was closed
} while(glfwGetKey(ctx->window, GLFW_KEY_ESCAPE) != GLFW_PRESS
@ -287,14 +290,18 @@ cx_run(CX_Context *ctx) {
// Establish a model registry
ctx->gl_ctx->mr = modelRegistry_new();
ctx->gl_ctx->master_lock = 1;
tg[0] = cx_threadGroup_new(&cx_glthread, ctx->gl_ctx);
tg[1] = cx_threadGroup_new(&cx_nnthread, ctx->nn_ctx);
pthread_join(tg[1]->group_manager->thread, NULL);
ctx->gl_ctx->master_lock = 0;
neural_getMesh(ctx->nn_ctx->nn, ctx->gl_ctx->mr);
tg[0] = cx_threadGroup_new(&cx_glthread, ctx->gl_ctx);
pthread_join(tg[0]->group_manager->thread, NULL);