//printf("thread_func %X enter wait\n", (int)v); fflush(stdout);
sem_wait(&c->work_sem);
//printf("thread_func %X after wait (func=%X)\n", (int)v, (int)c->func); fflush(stdout);
if(c->func)
c->ret=c->func(c->avctx,c->arg);
else
returnNULL;
//printf("thread_func %X signal complete\n", (int)v); fflush(stdout);
sem_post(&c->done_sem);
//av_log(w->avctx, AV_LOG_DEBUG, "thread_func %X enter wait\n", (int)v);
sem_wait(&w->work_sem);
//av_log(w->avctx, AV_LOG_DEBUG, "thread_func %X after wait\n", (int)v);
if(c->job_count==0)
break;
for(i=0;i<c->job_count;i++){
intindex=(i+w->start_index)%c->job_count;
JobContext*j=&c->job[index];
//av_log(w->avctx, AV_LOG_DEBUG, "thread_func %X first check of %d\n", (int)v, index);
if(j->assigned)continue;//unsynced check, if != 0 it is already given to another worker, it never becomes available before the next execute() call so this should be safe
//av_log(w->avctx, AV_LOG_DEBUG, "thread_func %X second check of %d\n", (int)v, index);