Exemple #1
0
void wait_semaphore(semaphore_t *sem)
{
   int newval = (int32_t) decrement_atomic((volatile uint32_t*)&sem->value);
   if (newval < 0) {
      wait_task(&sem->taskwait);
   }
}
/**
 * Compresses video frame with tiles API
 *
 * @param[in]     s             compress state
 * @param[in]     frame         uncompressed frame
 * @param         buffer_index  0 or 1 - driver should have 2 output buffers, filling the selected one.
 *                Returned video frame should stay valid until requesting compress with the
 *                same index.
 * @param         parent        parent module (for the case when there is a need to reconfigure)
 * @return                      compressed video frame, may be NULL if compression failed
 */
static struct video_frame *compress_frame_tiles(struct compress_state_real *s, struct video_frame *frame,
        int buffer_index, struct module *parent)
{
    if(frame->tile_count != s->state_count) {
        s->state = realloc(s->state, frame->tile_count * sizeof(struct module *));
        for(unsigned int i = s->state_count; i < frame->tile_count; ++i) {
            char compress_options[1024];
            strncpy(compress_options, s->compress_options, sizeof(compress_options));
            compress_options[sizeof(compress_options) - 1] = '\0';
            s->state[i] = s->handle->init_func(parent, compress_options);
            if(!s->state[i]) {
                fprintf(stderr, "Compression initialization failed\n");
                return NULL;
            }
        }
        for(int i = 0; i < 2; ++i) {
            vf_free(s->out_frame[i]);
            s->out_frame[i] = vf_alloc(frame->tile_count);
        }
        s->state_count = frame->tile_count;
    }

    task_result_handle_t task_handle[frame->tile_count];

    struct compress_worker_data data_tile[frame->tile_count];
    for(unsigned int i = 0; i < frame->tile_count; ++i) {
        struct compress_worker_data *data = &data_tile[i];
        data->state = s->state[i];
        data->tile = &frame->tiles[i];
        data->desc = video_desc_from_frame(frame);
        data->desc.tile_count = 1;
        data->buffer_index = buffer_index;;
        data->callback = s->handle->compress_tile_func;

        task_handle[i] = task_run_async(compress_tile_callback, data);
    }

    for(unsigned int i = 0; i < frame->tile_count; ++i) {
        struct compress_worker_data *data = wait_task(task_handle[i]);

        if(i == 0) { // update metadata from first tile
            data->desc.tile_count = frame->tile_count;
            vf_write_desc(s->out_frame[buffer_index], data->desc);
        }

        if(data->ret) {
            memcpy(&s->out_frame[buffer_index]->tiles[i], data->ret, sizeof(struct tile));
        } else {
            return NULL;
        }
    }

    return s->out_frame[buffer_index];
}
int64_t task_manager::get_parameter(communication::Task_Param const &parameter, size_t cur_tasks_size)
{
    if (!parameter.has_dependenttaskid())
    {
        return parameter.value();
    }

    // если параметр - зависимая переменная
    // если параметр - неправильный id какой-то задачи
    if (parameter.dependenttaskid() < 0 || parameter.dependenttaskid() > cur_tasks_size - 1)
    {
        return -1;
    }

    wait_task(parameter.dependenttaskid());
    return tasks[parameter.dependenttaskid()].get_result();
}
communication::SubscribeResponse task_manager::subscribe(int32_t task_id)
{
    communication::SubscribeResponse subs_resp;

    if (task_id < 0 || task_id >= tasks.size())
    {
        subs_resp.set_status(communication::Status::ERROR);
        return subs_resp;
    }
    
    wait_task(task_id);

    // возвращаем результат, когда задача уже выполнилась
    subs_resp.set_status(communication::Status::OK);
    subs_resp.set_value(tasks[task_id].get_result());

    return subs_resp;
}
Exemple #5
0
void run_service_cordel(int list_methods_len,chor_method_data list_methods[],char mailbox[]){
    m_task_t received_task = NULL;
    MSG_error_t res = MSG_OK;
    msg_comm_t msg_recv = NULL;
    static int id_sender = 0;
    char sender_name[50];
    sprintf(sender_name,"%s_%d",mailbox,id_sender++);
    int waiting_count = 0;
    while(1){
	msg_recv = MSG_task_irecv(&(received_task),mailbox);
	res = MSG_comm_wait(msg_recv,-1);
	if(res == MSG_OK){
	    char task_name[100];
	    strcpy(task_name,MSG_task_get_name(received_task));
	    task_data *received_task_data = (task_data *) received_task->data;
	    XBT_INFO("received task %lf",received_task_data->id);
	   // double endtime = MSG_get_clock();
	   // write_log(received_task_data->starttime,endtime,"waiting time");
	   //received_task_data->starttime = endtime;
	   int index_method = find_method(list_methods_len,list_methods,task_name);
	    chor_method_data method_data = list_methods[index_method];
	    int i;
	    for(i = 0;i<method_data.instructions_len;i++){
		method_instruction instruction = method_data.instructions[i];
		if(instruction.type == INVOKE){
		    service_invoke(instruction.role,instruction.method_name,instruction.input_size,sender_name);
		    waiting_count++;
		}else if(instruction.type == INVOKE_A){
		    service_invoke_cordel(instruction.role,instruction.method_name,instruction.input_size,received_task_data);
		}else if(instruction.type == EXEC){
		    run_chor_task(task_name,method_data);
		    }
		else if(instruction.type == WAIT){
		    wait_task(sender_name,waiting_count);
		    waiting_count = 0;
		    }
		else if(instruction.type == RETURN){
		    return_task(task_name,received_task,method_data.output_size);
		}
	    }
	}
	received_task = NULL;
    }
}