added print statements for debugging, fixed long memset by changing to calloc
This commit is contained in:
parent
0887e98d4b
commit
dd96efa9ef
2
contrib/adaptive-compression/run.sh
Executable file
2
contrib/adaptive-compression/run.sh
Executable file
@ -0,0 +1,2 @@
|
|||||||
|
make clean v2
|
||||||
|
./v2 tests/test2048.pdf tmp.zst
|
BIN
contrib/adaptive-compression/v2
Executable file
BIN
contrib/adaptive-compression/v2
Executable file
Binary file not shown.
@ -45,6 +45,7 @@ typedef struct {
|
|||||||
|
|
||||||
static adaptCCtx* createCCtx(unsigned numJobs, const char* const outFilename)
|
static adaptCCtx* createCCtx(unsigned numJobs, const char* const outFilename)
|
||||||
{
|
{
|
||||||
|
|
||||||
adaptCCtx* ctx = malloc(sizeof(adaptCCtx));
|
adaptCCtx* ctx = malloc(sizeof(adaptCCtx));
|
||||||
memset(ctx, 0, sizeof(adaptCCtx));
|
memset(ctx, 0, sizeof(adaptCCtx));
|
||||||
ctx->compressionLevel = 6; /* default */
|
ctx->compressionLevel = 6; /* default */
|
||||||
@ -53,7 +54,7 @@ static adaptCCtx* createCCtx(unsigned numJobs, const char* const outFilename)
|
|||||||
pthread_mutex_init(&ctx->jobReady_mutex, NULL);
|
pthread_mutex_init(&ctx->jobReady_mutex, NULL);
|
||||||
pthread_cond_init(&ctx->jobReady_cond, NULL);
|
pthread_cond_init(&ctx->jobReady_cond, NULL);
|
||||||
ctx->numJobs = numJobs;
|
ctx->numJobs = numJobs;
|
||||||
ctx->jobs = malloc(numJobs*sizeof(jobDescription));
|
ctx->jobs = calloc(1, numJobs*sizeof(jobDescription));
|
||||||
ctx->nextJobID = 0;
|
ctx->nextJobID = 0;
|
||||||
ctx->threadError = 0;
|
ctx->threadError = 0;
|
||||||
if (!ctx->jobs) {
|
if (!ctx->jobs) {
|
||||||
@ -95,6 +96,7 @@ static int freeCCtx(adaptCCtx* ctx)
|
|||||||
|
|
||||||
static void* compressionThread(void* arg)
|
static void* compressionThread(void* arg)
|
||||||
{
|
{
|
||||||
|
DISPLAY("started compression thread\n");
|
||||||
adaptCCtx* ctx = (adaptCCtx*)arg;
|
adaptCCtx* ctx = (adaptCCtx*)arg;
|
||||||
unsigned currJob = 0;
|
unsigned currJob = 0;
|
||||||
for ( ; ; ) {
|
for ( ; ; ) {
|
||||||
@ -126,6 +128,7 @@ static void* compressionThread(void* arg)
|
|||||||
|
|
||||||
static void* outputThread(void* arg)
|
static void* outputThread(void* arg)
|
||||||
{
|
{
|
||||||
|
DISPLAY("started output thread\n");
|
||||||
adaptCCtx* ctx = (adaptCCtx*)arg;
|
adaptCCtx* ctx = (adaptCCtx*)arg;
|
||||||
unsigned currJob = 0;
|
unsigned currJob = 0;
|
||||||
for ( ; ; ) {
|
for ( ; ; ) {
|
||||||
@ -202,6 +205,10 @@ static int createCompressionJob(adaptCCtx* ctx, BYTE* data, size_t srcSize)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
memcpy(job.src.start, data, srcSize);
|
memcpy(job.src.start, data, srcSize);
|
||||||
|
pthread_mutex_lock(job.jobReady_mutex);
|
||||||
|
job.jobReady = 1;
|
||||||
|
pthread_cond_signal(job.jobReady_cond);
|
||||||
|
pthread_mutex_unlock(job.jobReady_mutex);
|
||||||
ctx->nextJobID++;
|
ctx->nextJobID++;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -209,6 +216,10 @@ static int createCompressionJob(adaptCCtx* ctx, BYTE* data, size_t srcSize)
|
|||||||
/* return 0 if successful, else return error */
|
/* return 0 if successful, else return error */
|
||||||
int main(int argCount, const char* argv[])
|
int main(int argCount, const char* argv[])
|
||||||
{
|
{
|
||||||
|
if (argCount < 2) {
|
||||||
|
DISPLAY("Error: not enough arguments\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
const char* const srcFilename = argv[1];
|
const char* const srcFilename = argv[1];
|
||||||
const char* const dstFilename = argv[2];
|
const char* const dstFilename = argv[2];
|
||||||
BYTE* const src = malloc(FILE_CHUNK_SIZE);
|
BYTE* const src = malloc(FILE_CHUNK_SIZE);
|
||||||
@ -228,7 +239,7 @@ int main(int argCount, const char* argv[])
|
|||||||
if (!srcFilename || !dstFilename || !src) {
|
if (!srcFilename || !dstFilename || !src) {
|
||||||
DISPLAY("Error: initial variables could not be allocated\n");
|
DISPLAY("Error: initial variables could not be allocated\n");
|
||||||
ret = 1;
|
ret = 1;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* creating context */
|
/* creating context */
|
||||||
|
Loading…
Reference in New Issue
Block a user