diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2023-04-29 10:04:56 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2023-04-29 10:04:56 +0200 |
commit | 7855893959b44d12f9e333278e325e49f47c5a9f (patch) | |
tree | 3e24dab57e32780a1600c534a635f5a942e23cac /src | |
parent | make struct server opaque (diff) | |
download | cimple-7855893959b44d12f9e333278e325e49f47c5a9f.tar.gz cimple-7855893959b44d12f9e333278e325e49f47c5a9f.zip |
make struct worker opaque
Diffstat (limited to 'src')
-rw-r--r-- | src/worker.c | 24 | ||||
-rw-r--r-- | src/worker.h | 10 | ||||
-rw-r--r-- | src/worker_main.c | 6 |
3 files changed, 27 insertions, 13 deletions
diff --git a/src/worker.c b/src/worker.c index 7487e62..474be1c 100644 --- a/src/worker.c +++ b/src/worker.c @@ -20,13 +20,29 @@ #include <string.h> #include <unistd.h> -int worker_create(struct worker *worker, const struct settings *settings) +struct worker { + int fd; + + pthread_mutex_t task_mtx; + pthread_t task; + int task_active; +}; + +int worker_create(struct worker **_worker, const struct settings *settings) { + struct worker *worker; int ret = 0; + *_worker = malloc(sizeof(struct worker)); + if (!*_worker) { + log_errno("malloc"); + return -1; + } + worker = *_worker; + ret = libgit_init(); if (ret < 0) - return ret; + goto free; ret = net_connect(settings->host, settings->port); if (ret < 0) @@ -38,6 +54,9 @@ int worker_create(struct worker *worker, const struct settings *settings) git_shutdown: libgit_shutdown(); +free: + free(worker); + return ret; } @@ -47,6 +66,7 @@ void worker_destroy(struct worker *worker) log_errno_if(close(worker->fd), "close"); libgit_shutdown(); + free(worker); } static int msg_send_new_worker(const struct worker *worker) diff --git a/src/worker.h b/src/worker.h index 0bf3e80..246fd43 100644 --- a/src/worker.h +++ b/src/worker.h @@ -15,15 +15,9 @@ struct settings { char *port; }; -struct worker { - int fd; +struct worker; - pthread_mutex_t task_mtx; - pthread_t task; - int task_active; -}; - -int worker_create(struct worker *, const struct settings *); +int worker_create(struct worker **, const struct settings *); void worker_destroy(struct worker *); int worker_main(struct worker *, int argc, char *argv[]); diff --git a/src/worker_main.c b/src/worker_main.c index 7451861..7c78f93 100644 --- a/src/worker_main.c +++ b/src/worker_main.c @@ -72,7 +72,7 @@ static int parse_settings(struct settings *settings, int argc, char *argv[]) int main(int argc, char *argv[]) { struct settings settings; - struct worker worker; + struct worker *worker; int ret = 0; ret = parse_settings(&settings, argc, argv); @@ -83,12 +83,12 @@ int main(int argc, char *argv[]) if (ret < 0) return ret; - ret = worker_main(&worker, argc - optind, argv + optind); + ret = worker_main(worker, argc - optind, argv + optind); if (ret < 0) goto destroy_worker; destroy_worker: - worker_destroy(&worker); + worker_destroy(worker); return ret; } |