/****************************************************************************** * Function: jpeg_queue_init * Description: Initialize the queue. * It checks the pointer to the entry array and allocate * jpeg_q_t structure, and initialize queue head, tail * and counts all to zero. * Also initialize thread condition variable and mutex. * Input parameters: * p_queue - The pointer to queue object. * Return values: * JPEGERR_SUCCESS * JPEGERR_EMALLOC * JPEGERR_ENULLPTR * (See jpegerr.h for description of error values.) * Notes: none *****************************************************************************/ int jpeg_queue_init(jpeg_queue_t *p_queue) { jpeg_q_t *p_q; // Queue validation if (!p_queue) { JPEG_DBG_ERROR("jpeg_queue_init: failed with empty queue pointer\n"); return JPEGERR_ENULLPTR; } // Allocate the jpeg_q_t structure p_q = (jpeg_q_t *)JPEG_MALLOC(sizeof(jpeg_q_t)); *p_queue= (jpeg_queue_t)p_q; if (!p_q) { JPEG_DBG_ERROR("jpeg_queue_init: failed with allocation queue\n"); return JPEGERR_EMALLOC; } // Zero out all fields // Initialize queue head, tail and counts all to zero STD_MEMSET(p_q, 0, sizeof(jpeg_q_t)); // Initialize thread condition variable and mutex (void)os_mutex_init(&(p_q->mutex)); (void)os_cond_init(&(p_q->get_cond)); (void)os_cond_init(&(p_q->abort_cond)); return JPEGERR_SUCCESS; }
/*********************************************************** * Name: os_init * * Arguments: void * * Description: Routine to init the local OS stack - called from vchi_init * * Returns: int32_t - success == 0 * ***********************************************************/ int32_t os_init( void ) { int success; vcos_init(); os_cond_init(); os_assert(!vcos_os_inited++); /* should only be called once now */ success = os_semaphore_create(&os_mutex_global, OS_SEMAPHORE_TYPE_SUSPEND); os_assert(success == 0); return success; }
int main(int argc, char *argv[]) { START(argc, argv, "obj_direct"); if (argc != 3) UT_FATAL("usage: %s [directory] [# of pools]", argv[0]); unsigned npools = ATOU(argv[2]); const char *dir = argv[1]; int r; os_mutex_init(&lock1); os_mutex_init(&lock2); os_cond_init(&sync_cond1); os_cond_init(&sync_cond2); cond1 = cond2 = 0; PMEMobjpool **pops = MALLOC(npools * sizeof(PMEMobjpool *)); UT_ASSERTne(pops, NULL); size_t length = strlen(dir) + MAX_PATH_LEN; char *path = MALLOC(length); for (unsigned i = 0; i < npools; ++i) { int ret = snprintf(path, length, "%s"OS_DIR_SEP_STR"testfile%d", dir, i); if (ret < 0 || ret >= length) UT_FATAL("!snprintf"); pops[i] = pmemobj_create(path, LAYOUT_NAME, PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR); if (pops[i] == NULL) UT_FATAL("!pmemobj_create"); } PMEMoid *oids = MALLOC(npools * sizeof(PMEMoid)); UT_ASSERTne(oids, NULL); PMEMoid *tmpoids = MALLOC(npools * sizeof(PMEMoid)); UT_ASSERTne(tmpoids, NULL); oids[0] = OID_NULL; UT_ASSERTeq(obj_direct(oids[0]), NULL); for (unsigned i = 0; i < npools; ++i) { oids[i] = (PMEMoid) {pops[i]->uuid_lo, 0}; UT_ASSERTeq(obj_direct(oids[i]), NULL); uint64_t off = pops[i]->heap_offset; oids[i] = (PMEMoid) {pops[i]->uuid_lo, off}; UT_ASSERTeq((char *)obj_direct(oids[i]) - off, (char *)pops[i]); r = pmemobj_alloc(pops[i], &tmpoids[i], 100, 1, NULL, NULL); UT_ASSERTeq(r, 0); } r = pmemobj_alloc(pops[0], &thread_oid, 100, 2, NULL, NULL); UT_ASSERTeq(r, 0); UT_ASSERTne(obj_direct(thread_oid), NULL); os_thread_t t; PTHREAD_CREATE(&t, NULL, test_worker, NULL); /* wait for the worker thread to perform the first check */ os_mutex_lock(&lock1); while (!cond1) os_cond_wait(&sync_cond1, &lock1); os_mutex_unlock(&lock1); for (unsigned i = 0; i < npools; ++i) { UT_ASSERTne(obj_direct(tmpoids[i]), NULL); pmemobj_free(&tmpoids[i]); UT_ASSERTeq(obj_direct(tmpoids[i]), NULL); pmemobj_close(pops[i]); UT_ASSERTeq(obj_direct(oids[i]), NULL); } /* signal the worker that we're free and closed */ os_mutex_lock(&lock2); cond2 = 1; os_cond_signal(&sync_cond2); os_mutex_unlock(&lock2); PTHREAD_JOIN(&t, NULL); os_cond_destroy(&sync_cond1); os_cond_destroy(&sync_cond2); os_mutex_destroy(&lock1); os_mutex_destroy(&lock2); FREE(pops); FREE(tmpoids); FREE(oids); DONE(NULL); }
int jpeg_encode (uint8_t * Y, uint8_t * UV, yuv_args_t * _yuv_args) { int rc, i; encoder_args_t encoder_args; memset (&encoder_args, 0, sizeof (encoder_args)); LOG_D ("=============================================================\n"); LOG_D ("Encoder start\n"); LOG_D ("=============================================================\n"); encoder_args.main.y_buf = Y; encoder_args.main.uv_buf = UV; encoder_args.main.quality = _yuv_args->quality; // encoder_args.thumbnail.quality = 50; encoder_args.main.width = _yuv_args->width; // encoder_args.thumbnail.width = 0; encoder_args.main.height = _yuv_args->height; // encoder_args.thumbnail.height = 0; encoder_args.rotation = 0; // encoder_args.encode_thumbnail = true; encoder_args.main.format = YCBCRLP_H2V2; // encoder_args.thumbnail.format = YCBCRLP_H2V2; encoder_args.preference = _yuv_args->preference; encoder_args.back_to_back_count = 1; #if 0 encoder_args.main_scale_cfg.enable = false; encoder_args.main_scale_cfg.input_width = 0; encoder_args.main_scale_cfg.input_height = 0; encoder_args.main_scale_cfg.output_width = 0; encoder_args.main_scale_cfg.output_height = 0; encoder_args.main_scale_cfg.h_offset = 0; encoder_args.main_scale_cfg.v_offset = 0; encoder_args.tn_scale_cfg.enable = false; encoder_args.tn_scale_cfg.input_width = 0; encoder_args.tn_scale_cfg.input_height = 0; encoder_args.tn_scale_cfg.output_width = 0; encoder_args.tn_scale_cfg.output_height = 0; encoder_args.tn_scale_cfg.h_offset = 0; encoder_args.tn_scale_cfg.v_offset = 0; encoder_args.target_filesize = 0; #endif encoder_args.abort_time = 0; encoder_args.use_pmem = false; // Double check all the required arguments are set #if 0 if (!encoder_args.main.file_name || !encoder_args.output_file || !encoder_args.main.width || !encoder_args.main.height || encoder_args.main.format == 8) { LOG_D ("Missing required arguments.\n"); return 1; } if (encoder_args.encode_thumbnail && (!encoder_args.thumbnail.file_name || !encoder_args.thumbnail.width || !encoder_args.thumbnail.height || encoder_args.thumbnail.format == 8)) { LOG_D ("Missing thumbnail arguments.\n"); return 1; } #endif // Create thread control blocks thread_ctrl_blks = (thread_ctrl_blk_t *) malloc (concurrent_cnt * sizeof (thread_ctrl_blk_t)); if (!thread_ctrl_blks) { LOG_D ("hw_engine_encode failed: insufficient memory in creating thread control blocks\n"); return 1; } memset (thread_ctrl_blks, 0, concurrent_cnt * sizeof (thread_ctrl_blk_t)); // Initialize the blocks and kick off the threads for (i = 0; i < concurrent_cnt; i++) { thread_ctrl_blks[i].tid = i; thread_ctrl_blks[i].p_args = &encoder_args; os_mutex_init (&thread_ctrl_blks[i].output_handler_args.mutex); os_cond_init (&thread_ctrl_blks[i].output_handler_args.cond); if (os_thread_create(&thread_ctrl_blks[i].thread, hw_engine_encode,&thread_ctrl_blks[i])) { LOG_D ("hw_engine_encode: os_create failed\n"); return 1; } } rc = 0; // Join the threads for (i = 0; i < concurrent_cnt; i++) { OS_THREAD_FUNC_RET_T ret; os_thread_join (&thread_ctrl_blks[i].thread, &ret); if (ret) { LOG_D ("hw_engine_encode: thread %d failed\n", i); rc = (int) OS_THREAD_FUNC_RET_FAILED; } } free (thread_ctrl_blks); if (!rc) LOG_D ("hw_engine_encode finished successfully\n"); LOG_D ("exit value: %d\n", rc); return rc; }