{
adaptCCtx* ctx = malloc(sizeof(adaptCCtx));
+ if (ctx == NULL) {
+ DISPLAY("Error: could not allocate space for context\n");
+ return NULL;
+ }
memset(ctx, 0, sizeof(adaptCCtx));
ctx->compressionLevel = 6; /* default */
pthread_mutex_init(&ctx->jobCompleted_mutex, NULL);
{
unsigned u;
for (u=0; u<ctx->numJobs; u++) {
+ DISPLAY("freeing compression job %u\n", u);
+ DISPLAY("%u\n", ctx->numJobs);
jobDescription job = ctx->jobs[u];
if (job.dst.start) free(job.dst.start);
if (job.src.start) free(job.src.start);
static int freeCCtx(adaptCCtx* ctx)
{
+ /* TODO: wait until jobs finish */
int const completedMutexError = pthread_mutex_destroy(&ctx->jobCompleted_mutex);
int const completedCondError = pthread_cond_destroy(&ctx->jobCompleted_cond);
int const readyMutexError = pthread_mutex_destroy(&ctx->jobReady_mutex);
{
DISPLAY("started output thread\n");
adaptCCtx* ctx = (adaptCCtx*)arg;
+ DISPLAY("casted ctx\n");
+
unsigned currJob = 0;
for ( ; ; ) {
jobDescription* job = &ctx->jobs[currJob];
BYTE* const src = malloc(FILE_CHUNK_SIZE);
FILE* const srcFile = fopen(srcFilename, "rb");
size_t fileSize = getFileSize(srcFilename);
- size_t const numJobsPrelim = (fileSize / FILE_CHUNK_SIZE) + 1;
+ size_t const numJobsPrelim = (fileSize >> 22) + 1; /* TODO: figure out why can't divide here */
size_t const numJobs = (numJobsPrelim * FILE_CHUNK_SIZE) == fileSize ? numJobsPrelim : numJobsPrelim + 1;
int ret = 0;
adaptCCtx* ctx = NULL;
ret = 1;
goto cleanup;
}
- if (!srcFilename || !dstFilename || !src) {
+ if (!srcFilename || !dstFilename || !src || !srcFile) {
DISPLAY("Error: initial variables could not be allocated\n");
ret = 1;
goto cleanup;
/* creating jobs */
for ( ; ; ) {
+ DISPLAY("in job creation loop\n");
size_t const readSize = fread(src, 1, FILE_CHUNK_SIZE, srcFile);
if (readSize != FILE_CHUNK_SIZE && !feof(srcFile)) {
DISPLAY("Error: problem occurred during read from src file\n");
ret = 1;
goto cleanup;
}
-
+ DISPLAY("reading was fine\n");
/* reading was fine, now create the compression job */
{
int const error = createCompressionJob(ctx, src, readSize);
goto cleanup;
}
}
+ if (feof(srcFile)) break;
}
-
- /* file compression completed */
- {
- int const fileCloseError = fclose(srcFile);
- int const cctxReleaseError = freeCCtx(ctx);
- if (fileCloseError | cctxReleaseError) {
- ret = 1;
- goto cleanup;
- }
- }
+ DISPLAY("cleanup\n");
cleanup:
+ /* file compression completed */
+ ret |= (srcFile != NULL) ? fclose(srcFile) : 0;
+ ret |= (ctx != NULL) ? freeCCtx(ctx) : 0;
if (src != NULL) free(src);
- if (ctx != NULL) freeCCtx(ctx);
return ret;
}