From 4b2db87c9e57cc5cfc4f1abf2c51b02ffd283cdc Mon Sep 17 00:00:00 2001 From: Marcel Plch Date: Sun, 10 Nov 2024 00:48:13 +0100 Subject: [PATCH] Readability tweaks --- .gitignore | 3 +- include/void | 0 src/cx.c | 81 ++++++++++++++++++++++++++++------------------------ src/void | 0 4 files changed, 46 insertions(+), 38 deletions(-) delete mode 100644 include/void delete mode 100644 src/void diff --git a/.gitignore b/.gitignore index 25a9a7b..d597bc1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ build/ -*\.session +training_data/ +vim.sessions/ *\.tar* *\.gpg diff --git a/include/void b/include/void deleted file mode 100644 index e69de29..0000000 diff --git a/src/cx.c b/src/cx.c index 289898f..c8e07dd 100644 --- a/src/cx.c +++ b/src/cx.c @@ -1,5 +1,41 @@ #include +static CX_Thread * +cx_thread_new(void *(*target)(void *), + void *ctx) { + CX_Thread *self; + int err; + + self = malloc(sizeof(CX_Thread)); + if (!self) { + goto err; + } + err = pthread_create(&self->thread, NULL, target, ctx); + if (err) { + goto err; + } + self->ctx = ctx; + +err: + free(self); + return NULL; +} + +static CX_ThreadGroup * +cx_threadGroup_new(void *(*target)(void *), + void *ctx) { + CX_ThreadGroup *self; + + self = malloc(sizeof(CX_ThreadGroup)); + + self->group_manager = cx_thread_new(target, ctx); + self->workers = malloc(8 * sizeof(CX_Thread *)); + self->worker_count = 0; + self->worker_size = 8; + + return self; +} + static void cx_glBindBuffer(GLfloat *render_buffer, GLuint buffer_address, GLuint gl_index, GLint member_size, GLsizeiptr bufsize) { @@ -98,7 +134,7 @@ cx_glinit(GLFWwindow **window) { glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Open a window and create its OpenGL context - *window = glfwCreateWindow(1280, 720, "CONTROL-X", NULL, NULL); + *window = glfwCreateWindow(1280, 720, "C-X", NULL, NULL); if (*window == NULL) { fprintf(stderr, "Failed to open GLFW window.\n"); glfwTerminate(); @@ -139,8 +175,14 @@ cx_nninit(Neural_Network **nn) { return 0; } +static void +master_thread(void *ctx) { +} + int cx_init(CX_Context **cx_ctx) { + printf("Initializing CX."); + *cx_ctx = calloc(1, sizeof(CX_Context)); (*cx_ctx)->VertexArrayIDs = calloc(1, sizeof(GLuint)); (*cx_ctx)->VertexArray_count = 0; @@ -148,6 +190,7 @@ cx_init(CX_Context **cx_ctx) { (*cx_ctx)->programIDs = calloc(1, sizeof(GLuint)); (*cx_ctx)->ProgramID_count = 0; (*cx_ctx)->ProgramID_size = 1; + (*cx_ctx)->threads = calloc(1, sizeof(CX_ThreadGroup)); if (cx_glinit(&(*cx_ctx)->window)) { return -1; @@ -177,42 +220,6 @@ cx_nnrun(Neural_Network *nn) { return 0; } -static CX_Thread * -cx_thread_new(void *(*target)(void *), - void *ctx) { - CX_Thread *self; - int err; - - self = malloc(sizeof(CX_Thread)); - if (!self) { - goto err; - } - err = pthread_create(&self->thread, NULL, target, ctx); - if (err) { - goto err; - } - self->ctx = ctx; - -err: - free(self); - return NULL; -} - -static CX_ThreadGroup * -cx_threadGroup_new(void *(*target)(void *), - void *ctx) { - CX_ThreadGroup *self; - - self = malloc(sizeof(CX_ThreadGroup)); - - self->group_manager = cx_thread_new(target, ctx); - self->workers = malloc(8 * sizeof(CX_Thread *)); - self->worker_count = 0; - self->worker_size = 8; - - return self; -} - int cx_run(CX_Context *cx_ctx) { ModelRegistry *mr; diff --git a/src/void b/src/void deleted file mode 100644 index e69de29..0000000