gpointer rtp_scheduler_schedule(gpointer psched) { RtpScheduler *sched=(RtpScheduler*) psched; RtpTimer *timer=sched->timer; RtpSession *current; int err; /* try to get the real time priority by getting root*/ #ifndef _WIN32 #ifdef HAVE_SETEUID err=seteuid(0); #else err=setuid(0); #endif if (err<0) g_message("Could not get root euid: %s",strerror(errno)); #endif g_message("scheduler: trying to reach real time kernel scheduling..."); /* take this lock to prevent the thread to start until g_thread_create() returns because we need sched->thread to be initialized */ g_mutex_lock(sched->lock); g_cond_signal(sched->unblock_select_cond); /* unblock the starting thread */ g_mutex_unlock(sched->lock); g_thread_set_priority(sched->thread,G_THREAD_PRIORITY_HIGH); timer->timer_init(); while(sched->thread_running) { /* do the processing here: */ g_mutex_lock(sched->lock); current=sched->list; /* processing all scheduled rtp sessions */ while (current!=NULL) { ortp_debug("scheduler: processing session=%p.\n",current); rtp_session_process(current,sched->time_,sched); current=current->next; } /* wake up all the threads that are sleeping in _select() */ g_cond_broadcast(sched->unblock_select_cond); g_mutex_unlock(sched->lock); /* now while the scheduler is going to sleep, the other threads can compute their result mask and see if they have to leave, or to wait for next tick*/ //g_message("scheduler: sleeping."); timer->timer_do(); sched->time_+=sched->timer_inc; } /* when leaving the thread, stop the timer */ timer->timer_uninit(); return NULL; }
void * rtp_scheduler_schedule(void * psched) { RtpScheduler *sched=(RtpScheduler*) psched; RtpTimer *timer=sched->timer; RtpSession *current; /* take this lock to prevent the thread to start until g_thread_create() returns because we need sched->thread to be initialized */ ortp_mutex_lock(&sched->lock); ortp_cond_signal(&sched->unblock_select_cond); /* unblock the starting thread */ ortp_mutex_unlock(&sched->lock); timer->timer_init(); while(sched->thread_running) { /* do the processing here: */ ortp_mutex_lock(&sched->lock); current=sched->list; /* processing all scheduled rtp sessions */ while (current!=NULL) { ortp_debug("scheduler: processing session=0x%x.\n",current); rtp_session_process(current,sched->time_,sched); current=current->next; } /* wake up all the threads that are sleeping in _select() */ ortp_cond_broadcast(&sched->unblock_select_cond); ortp_mutex_unlock(&sched->lock); /* now while the scheduler is going to sleep, the other threads can compute their result mask and see if they have to leave, or to wait for next tick*/ //ortp_message("scheduler: sleeping."); timer->timer_do(); sched->time_+=sched->timer_inc; } /* when leaving the thread, stop the timer */ timer->timer_uninit(); return NULL; }