diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2021-04-28 19:28:14 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2021-04-28 19:28:14 -0700 |
commit | 3812a302cefcccbeb9bc46ed5c55710eb4c0512e (patch) | |
tree | 0699a192560cd2e9d50a363a1929af7f794ed43c /src | |
parent | 64eed5bc02c0a4e09423aa67f118a2a7c8bc69b0 (diff) |
encode_cache: handle pthread_create() errors
switch to using rmdThread() and handle errors
previously pthread_create() errors were completely unnoticed
Diffstat (limited to 'src')
-rw-r--r-- | src/rmd.c | 6 | ||||
-rw-r--r-- | src/rmd_encode_cache.c | 17 | ||||
-rw-r--r-- | src/rmd_encode_cache.h | 2 | ||||
-rw-r--r-- | src/rmd_rescue.c | 5 |
4 files changed, 21 insertions, 9 deletions
@@ -158,8 +158,10 @@ int main(int argc, char **argv) //encode and then cleanup cache if (!pdata.args.encOnTheFly && !pdata.args.no_encode) { - if (!pdata.aborted) - rmdEncodeCache(&pdata); + if (!pdata.aborted) { + if (rmdEncodeCache(&pdata)) + return 1; + } fprintf(stderr, "Cleanning up cache...\n"); if (rmdPurgeCache(pdata.cache_data, !pdata.args.nosound)) diff --git a/src/rmd_encode_cache.c b/src/rmd_encode_cache.c index e2bf85d..2d778be 100644 --- a/src/rmd_encode_cache.c +++ b/src/rmd_encode_cache.c @@ -30,6 +30,7 @@ #include "rmd_flush_to_ogg.h" #include "rmd_init_encoder.h" #include "rmd_load_cache.h" +#include "rmd_threads.h" #include "rmd_types.h" #include <pthread.h> @@ -38,8 +39,7 @@ #include <stdlib.h> - -void rmdEncodeCache(ProgData *pdata) +int rmdEncodeCache(ProgData *pdata) { pthread_t flush_to_ogg_t, load_cache_t; @@ -61,13 +61,22 @@ void rmdEncodeCache(ProgData *pdata) pdata->sound_buffer = pdata->sound_buffer->next; } } - pthread_create(&flush_to_ogg_t, NULL, (void *)rmdFlushToOgg, (void *)pdata); + + if (rmdThread(&flush_to_ogg_t, rmdFlushToOgg, pdata)) { + fprintf(stderr, "Error creating rmdFlushToOgg thread!!!\n"); + return 1; + } //start loading image and audio - pthread_create(&load_cache_t, NULL, (void *)rmdLoadCache, (void *)pdata); + if (rmdThread(&load_cache_t, rmdLoadCache, pdata)) { + fprintf(stderr, "Error creating rmdLoadCache thread!!!\n"); + return 1; + } //join and finish pthread_join(load_cache_t, NULL); fprintf(stderr, "Encoding finished!\nWait a moment please...\n"); pthread_join(flush_to_ogg_t, NULL); + + return 0; } diff --git a/src/rmd_encode_cache.h b/src/rmd_encode_cache.h index 4c37f97..f1078c1 100644 --- a/src/rmd_encode_cache.h +++ b/src/rmd_encode_cache.h @@ -35,7 +35,7 @@ * ogg stream. * \param pdata ProgData struct containing all program data */ -void rmdEncodeCache(ProgData *pdata); +int rmdEncodeCache(ProgData *pdata); #endif diff --git a/src/rmd_rescue.c b/src/rmd_rescue.c index 73ae7d4..ac224dd 100644 --- a/src/rmd_rescue.c +++ b/src/rmd_rescue.c @@ -114,8 +114,9 @@ int rmdRescue(const char *path) rmdRegisterCallbacks(&pdata); fprintf(stderr, "Restoring %s!!!\n", path); - - rmdEncodeCache(&pdata); + + if (rmdEncodeCache(&pdata)) + return 1; fprintf(stderr, "Done!!!\n"); fprintf(stderr, "Goodbye!\n"); |