00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <ortp/ortp.h>
00021 #include <ortp/sessionset.h>
00022 #include "scheduler.h"
00023
00024
00030 SessionSet * session_set_new()
00031 {
00032 SessionSet *set=(SessionSet *) ortp_malloc(sizeof(SessionSet));
00033 session_set_init(set);
00034 return set;
00035 }
00036
00037
00043 void session_set_destroy(SessionSet *set)
00044 {
00045 ortp_free(set);
00046 }
00047
00048 int session_set_and(SessionSet *sched_set, int maxs, SessionSet *user_set, SessionSet *result_set)
00049 {
00050 uint32_t *mask1,*mask2,*mask3;
00051 int i=0;
00052 int j,ret=0;
00053 mask1=(uint32_t*)(void*)&sched_set->rtpset;
00054 mask2=(uint32_t*)(void*)&user_set->rtpset;
00055 mask3=(uint32_t*)(void*)&result_set->rtpset;
00056 while(i<maxs+1){
00057 *mask3=(*mask1) & (*mask2);
00058
00059 *mask1=(*mask1) & (~(*mask3));
00060 if ((*mask3)!=0){
00061 for (j=0;j<32;j++){
00062 if ( ((*mask3)>>j) & 1){
00063 ret++;
00064 }
00065 }
00066 }
00067 i+=32;
00068 mask1++;
00069 mask2++;
00070 mask3++;
00071 }
00072
00073 return ret;
00074 }
00075
00098 int session_set_select(SessionSet *recvs, SessionSet *sends, SessionSet *errors)
00099 {
00100 int ret=0,bits;
00101 SessionSet temp;
00102 RtpScheduler *sched=ortp_get_scheduler();
00103
00104
00105 rtp_scheduler_lock(sched);
00106
00107 while(1){
00108
00109
00110 if (recvs!=NULL){
00111 session_set_init(&temp);
00112 bits=session_set_and(&sched->r_sessions,sched->all_max,recvs,&temp);
00113 if (bits>0){
00114 ret+=bits;
00115
00116 session_set_copy(recvs,&temp);
00117 }
00118 }
00119 if (sends!=NULL){
00120 session_set_init(&temp);
00121 bits=session_set_and(&sched->w_sessions,sched->all_max,sends,&temp);
00122 if (bits>0){
00123 ret+=bits;
00124
00125 session_set_copy(sends,&temp);
00126 }
00127 }
00128 if (errors!=NULL){
00129 session_set_init(&temp);
00130 bits=session_set_and(&sched->e_sessions,sched->all_max,errors,&temp);
00131 if (bits>0){
00132 ret+=bits;
00133
00134 session_set_copy(errors,&temp);
00135 }
00136 }
00137 if (ret>0){
00138
00139
00140 rtp_scheduler_unlock(sched);
00141 return ret;
00142 }
00143
00144
00145 ortp_cond_wait(&sched->unblock_select_cond,&sched->lock);
00146 }
00147
00148 return -1;
00149 }
00150