00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "config.h"
00019
00020 #include <assert_pp.h>
00021
00022 #include <iostream>
00023
00024 #include "RealTimeSchedule.hh"
00025
00026 #if !defined(min)
00027 #define min(x, y) ((x) < (y) ? (x) : (y))
00028 #define max(x, y) ((x) > (y) ? (x) : (y))
00029 #endif
00030
00031 RealTimeSchedule::RealTimeSchedule(CORBA::ULong start,
00032 CORBA::ULong period,
00033 CORBA::ULong deadline) :
00034 rts_Start(start), rts_Period(period), rts_Deadline(deadline)
00035 {
00036 require(deadline <= period);
00037 }
00038
00039 RealTimeSchedule::~RealTimeSchedule()
00040 {
00041 }
00042
00043 CORBA::ULong RealTimeSchedule::intersect(CORBA::ULong start, CORBA::ULong stop)
00044 {
00045 int starting_period_index, ending_period_index;
00046 CORBA::ULong retval = 0;
00047
00048 require(start <= stop);
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 starting_period_index = ((int)start - (int)this->rts_Start) /
00059 (int)this->rts_Period;
00060
00061 if( stop < this->rts_Start )
00062 {
00063
00064 ending_period_index = -1;
00065 }
00066 else
00067 {
00068
00069
00070
00071
00072 ending_period_index = (stop - this->rts_Start - 1) / this->rts_Period;
00073 }
00074
00075 if( starting_period_index < 0 )
00076 {
00077
00078
00079
00080
00081
00082 starting_period_index = -1;
00083 }
00084 else
00085 {
00086 unsigned long long start_us, end_us;
00087
00088
00089
00090
00091
00092 start_us = this->rts_Start +
00093 (this->rts_Period * starting_period_index);
00094
00095 end_us = this->rts_Start +
00096 (this->rts_Period * starting_period_index) +
00097 this->rts_Deadline;
00098
00099 retval += (CORBA::ULong)(min(stop, end_us) - max(start, start_us));
00100 }
00101
00102 if( (starting_period_index + 1) <= (ending_period_index - 1) )
00103 {
00104
00105 retval += (ending_period_index - starting_period_index - 1) *
00106 this->rts_Deadline;
00107 }
00108
00109 if( ending_period_index < 0 )
00110 {
00111
00112 }
00113 else if( starting_period_index != ending_period_index )
00114 {
00115 unsigned long long start_us;
00116
00117
00118 start_us = this->rts_Start + (this->rts_Period * ending_period_index);
00119 retval += (CORBA::ULong)(min(stop, start_us + this->rts_Deadline) -
00120 start_us);
00121 }
00122 return( retval );
00123 }