Readability tweaks
This commit is contained in:
parent
fee012f56c
commit
4b2db87c9e
4 changed files with 46 additions and 38 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,5 +1,6 @@
|
|||
build/
|
||||
*\.session
|
||||
training_data/
|
||||
vim.sessions/
|
||||
|
||||
*\.tar*
|
||||
*\.gpg
|
||||
|
|
81
src/cx.c
81
src/cx.c
|
@ -1,5 +1,41 @@
|
|||
#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
|
||||
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;
|
||||
|
|
0
src/void
0
src/void
Loading…
Reference in a new issue