Readability tweaks

This commit is contained in:
Marcel Plch 2024-11-10 00:48:13 +01:00
parent fee012f56c
commit 4b2db87c9e
Signed by: dormouse
GPG key ID: 2CA77596BC4BDFFE
4 changed files with 46 additions and 38 deletions

3
.gitignore vendored
View file

@ -1,5 +1,6 @@
build/ build/
*\.session training_data/
vim.sessions/
*\.tar* *\.tar*
*\.gpg *\.gpg

View file

View file

@ -1,5 +1,41 @@
#include <cx.h> #include <cx.h>
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 static void
cx_glBindBuffer(GLfloat *render_buffer, GLuint buffer_address, cx_glBindBuffer(GLfloat *render_buffer, GLuint buffer_address,
GLuint gl_index, GLint member_size, GLsizeiptr bufsize) { GLuint gl_index, GLint member_size, GLsizeiptr bufsize) {
@ -98,7 +134,7 @@ cx_glinit(GLFWwindow **window) {
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
// Open a window and create its OpenGL context // 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) { if (*window == NULL) {
fprintf(stderr, "Failed to open GLFW window.\n"); fprintf(stderr, "Failed to open GLFW window.\n");
glfwTerminate(); glfwTerminate();
@ -139,8 +175,14 @@ cx_nninit(Neural_Network **nn) {
return 0; return 0;
} }
static void
master_thread(void *ctx) {
}
int int
cx_init(CX_Context **cx_ctx) { cx_init(CX_Context **cx_ctx) {
printf("Initializing CX.");
*cx_ctx = calloc(1, sizeof(CX_Context)); *cx_ctx = calloc(1, sizeof(CX_Context));
(*cx_ctx)->VertexArrayIDs = calloc(1, sizeof(GLuint)); (*cx_ctx)->VertexArrayIDs = calloc(1, sizeof(GLuint));
(*cx_ctx)->VertexArray_count = 0; (*cx_ctx)->VertexArray_count = 0;
@ -148,6 +190,7 @@ cx_init(CX_Context **cx_ctx) {
(*cx_ctx)->programIDs = calloc(1, sizeof(GLuint)); (*cx_ctx)->programIDs = calloc(1, sizeof(GLuint));
(*cx_ctx)->ProgramID_count = 0; (*cx_ctx)->ProgramID_count = 0;
(*cx_ctx)->ProgramID_size = 1; (*cx_ctx)->ProgramID_size = 1;
(*cx_ctx)->threads = calloc(1, sizeof(CX_ThreadGroup));
if (cx_glinit(&(*cx_ctx)->window)) { if (cx_glinit(&(*cx_ctx)->window)) {
return -1; return -1;
@ -177,42 +220,6 @@ cx_nnrun(Neural_Network *nn) {
return 0; 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 int
cx_run(CX_Context *cx_ctx) { cx_run(CX_Context *cx_ctx) {
ModelRegistry *mr; ModelRegistry *mr;

View file