Now I'm kinda happy with the threads.
This commit is contained in:
parent
e47a6d26cd
commit
9fe8afb68a
2 changed files with 11 additions and 2 deletions
|
@ -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 {
|
||||
|
|
11
src/cx.c
11
src/cx.c
|
@ -230,7 +230,10 @@ cx_glrun(CX_GL_CTX *ctx) {
|
|||
glfwGetCursorPos(ctx->window, &xpos, &ypos);
|
||||
|
||||
do {
|
||||
cx_glrender(ctx->window, ctx->programIDs[0], ctx->mr);
|
||||
// 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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue