This commit is contained in:
parent
be70ef346e
commit
cdf102089a
2 changed files with 28 additions and 2 deletions
|
@ -19,13 +19,37 @@ ClockCb::ClockCb(size_t size, size_t index){
|
|||
}
|
||||
|
||||
bool ClockCb::adjust(TimeStamp ts){
|
||||
bool result = false;
|
||||
bool result = true;
|
||||
short emit_idx = ts.getIndex();
|
||||
// lock jusqu'a la fin de la fonction
|
||||
Glib::Mutex::Lock lock(_mutex);
|
||||
// si les conditions sont remplies, alors on peut modifier l'horloge
|
||||
|
||||
printf("ClockCb::adjust -- stamp index : %d\n", ts.getIndex() );
|
||||
printf("ClockCb::adjust -- local index : %d\n", _cur_index );
|
||||
printf("ClockCb::adjust -- (emitter) stamp index : %d\n", ts.getIndex() );
|
||||
|
||||
if (ts[emit_idx] == _ticks[emit_idx] + 1){
|
||||
printf("ClockCb::adjust -- index TS_m[j] == TS_i[j] + 1 (FIFO property)\n");
|
||||
|
||||
// Condition "le site i a recu au moins tout ce que l'emetteur à recu"
|
||||
for (int idx = 0; idx < _ticks.size(); idx++){
|
||||
if (idx != emit_idx){
|
||||
if (ts[idx] > _ticks[idx]) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Condition FIFO non respectée
|
||||
result = false;
|
||||
}
|
||||
|
||||
if (result){
|
||||
// si les deux conditions sont respectées, on met à jour l'horloge...
|
||||
_ticks[emit_idx] = _ticks[emit_idx] + 1;
|
||||
printf("ClockCb::adjust -- time update _ticks[%d] = %d\n", emit_idx, _ticks[emit_idx]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,8 @@ void LowReceiver::manage_cbcast(Message * mesg) {
|
|||
|
||||
} else {
|
||||
printf("LowReceiver::manage_cbcast - Received a message from a friend\n");
|
||||
|
||||
_clock.adjust(mesg->getStamp());
|
||||
// FIXME: si l'horloge est ajustable
|
||||
// (donc les contraintes TS_m[j] = TS_m[j]+1 && ... ),
|
||||
// alors on délivre directement
|
||||
|
|
Loading…
Add table
Reference in a new issue