Changed sleep to wait everywhere where it was needed

This commit is contained in:
Erik Zandvliet 2016-05-18 17:06:03 +02:00
parent 3ad8317df7
commit 72de5e5b90
9 changed files with 18 additions and 18 deletions

View file

@ -63,7 +63,7 @@ void Util::Procs::exit_handler() {
break; break;
} }
if (!listcopy.empty()) { if (!listcopy.empty()) {
Util::sleep(20); Util::wait(20);
++waiting; ++waiting;
} }
} }
@ -91,7 +91,7 @@ void Util::Procs::exit_handler() {
break; break;
} }
if (!listcopy.empty()) { if (!listcopy.empty()) {
Util::sleep(20); Util::wait(20);
++waiting; ++waiting;
} }
} }
@ -119,7 +119,7 @@ void Util::Procs::exit_handler() {
break; break;
} }
if (!listcopy.empty()) { if (!listcopy.empty()) {
Util::sleep(20); Util::wait(20);
++waiting; ++waiting;
} }
} }

View file

@ -405,7 +405,7 @@ namespace IPC {
int i = 0; int i = 0;
do { do {
if (i != 0) { if (i != 0) {
Util::sleep(1000); Util::wait(1000);
} }
handle = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, name.c_str()); handle = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, name.c_str());
i++; i++;
@ -438,7 +438,7 @@ namespace IPC {
int i = 0; int i = 0;
while (i < 10 && handle == -1 && autoBackoff) { while (i < 10 && handle == -1 && autoBackoff) {
i++; i++;
Util::sleep(1000); Util::wait(1000);
handle = shm_open(name.c_str(), O_RDWR, ACCESSPERMS); handle = shm_open(name.c_str(), O_RDWR, ACCESSPERMS);
} }
} }
@ -558,7 +558,7 @@ namespace IPC {
int i = 0; int i = 0;
while (i < 10 && handle == -1 && autoBackoff) { while (i < 10 && handle == -1 && autoBackoff) {
i++; i++;
Util::sleep(1000); Util::wait(1000);
handle = open(std::string(Util::getTmpFolder() + name).c_str(), O_RDWR, (mode_t)0600); handle = open(std::string(Util::getTmpFolder() + name).c_str(), O_RDWR, (mode_t)0600);
} }
} }

View file

@ -313,7 +313,7 @@ bool Util::startInput(std::string streamname, std::string filename, bool forkFir
unsigned int waiting = 0; unsigned int waiting = 0;
while (!streamAlive(streamname) && ++waiting < 40){ while (!streamAlive(streamname) && ++waiting < 40){
Util::sleep(250); Util::wait(250);
} }
return streamAlive(streamname); return streamAlive(streamname);

View file

@ -238,7 +238,7 @@ namespace Mist {
} }
/*LTS-END*/ /*LTS-END*/
if (config->is_active){ if (config->is_active){
Util::sleep(1000); Util::wait(1000);
} }
} }
finish(); finish();

View file

@ -228,10 +228,10 @@ namespace Mist {
} }
updateMeta(); updateMeta();
if (myMeta.live && !isReadyForPlay()){ if (myMeta.live && !isReadyForPlay()){
unsigned int maxWaits = 15; unsigned long long waitUntil = Util::epoch() + 15;
while (!isReadyForPlay()){ while (!isReadyForPlay()){
Util::sleep(1000); Util::sleep(1000);
if (--maxWaits == 0){ if (Util::epoch() > waitUntil){
FAIL_MSG("Giving up waiting for playable tracks"); FAIL_MSG("Giving up waiting for playable tracks");
break; break;
} }
@ -1002,7 +1002,7 @@ namespace Mist {
DEBUG_MSG(DLVL_DEVEL, "Empty packet on track %u (%s) @ key %lu (next=%d) - could not reload, dropping track.", nxt.tid, myMeta.tracks[nxt.tid].type.c_str(), nxtKeyNum[nxt.tid]+1, nextPage); DEBUG_MSG(DLVL_DEVEL, "Empty packet on track %u (%s) @ key %lu (next=%d) - could not reload, dropping track.", nxt.tid, myMeta.tracks[nxt.tid].type.c_str(), nxtKeyNum[nxt.tid]+1, nextPage);
} }
//keep updating the metadata at 250ms intervals while waiting for more data //keep updating the metadata at 250ms intervals while waiting for more data
Util::sleep(250); Util::wait(250);
updateMeta(); updateMeta();
}else{ }else{
//if we're not live, we've simply reached the end of the page. Load the next key. //if we're not live, we've simply reached the end of the page. Load the next key.
@ -1043,7 +1043,7 @@ namespace Mist {
while(counter < 10 && myMeta.tracks[nxt.tid].getKey(nxtKeyNum[nxt.tid]).getTime() != thisPacket.getTime()){ while(counter < 10 && myMeta.tracks[nxt.tid].getKey(nxtKeyNum[nxt.tid]).getTime() != thisPacket.getTime()){
if (counter++){ if (counter++){
//Only sleep 500ms if this is not the first updatemeta try //Only sleep 500ms if this is not the first updatemeta try
Util::sleep(500); Util::wait(500);
} }
updateMeta(); updateMeta();
nxtKeyNum[nxt.tid] = getKeyForTime(nxt.tid, thisPacket.getTime()); nxtKeyNum[nxt.tid] = getKeyForTime(nxt.tid, thisPacket.getTime());
@ -1109,9 +1109,9 @@ namespace Mist {
if (nxt.offset < nProxy.curPage[nxt.tid].len){ if (nxt.offset < nProxy.curPage[nxt.tid].len){
unsigned long long nextTime = getDTSCTime(nProxy.curPage[nxt.tid].mapped, nxt.offset); unsigned long long nextTime = getDTSCTime(nProxy.curPage[nxt.tid].mapped, nxt.offset);
int ctr = 0; int ctr = 0;
//sleep at most half a second for new data. //sleep for at most 5 seconds for new data.
while (!nextTime && ++ctr < 5){ while (!nextTime && ++ctr < 5){
Util::sleep(1000); Util::wait(1000);
nextTime = getDTSCTime(nProxy.curPage[nxt.tid].mapped, nxt.offset); nextTime = getDTSCTime(nProxy.curPage[nxt.tid].mapped, nxt.offset);
} }
if (nextTime){ if (nextTime){

View file

@ -243,7 +243,7 @@ namespace Mist {
myConn.close(); myConn.close();
break; break;
} }
Util::sleep(500); Util::wait(500);
updateMeta(); updateMeta();
} }
mstime = myMeta.tracks[tid].getKey(myMeta.tracks[tid].fragments[fragNum - myMeta.tracks[tid].missedFrags].getNumber()).getTime(); mstime = myMeta.tracks[tid].getKey(myMeta.tracks[tid].fragments[fragNum - myMeta.tracks[tid].missedFrags].getNumber()).getTime();

View file

@ -453,7 +453,7 @@ namespace Mist {
myConn.close(); myConn.close();
break; break;
} }
Util::sleep(500); Util::wait(500);
updateMeta(); updateMeta();
} }
} while (myConn && seekable > 0); } while (myConn && seekable > 0);

View file

@ -134,7 +134,7 @@ namespace Mist {
myConn.close(); myConn.close();
break; break;
} }
Util::sleep(500); Util::wait(500);
updateMeta(); updateMeta();
} }
}while (myConn && seekable > 0); }while (myConn && seekable > 0);

View file

@ -218,7 +218,7 @@ void pushThread(void * nullPointer){
while (pConf->is_active){ while (pConf->is_active){
pushFirstElement(myThread); pushFirstElement(myThread);
if (!pushableSegments[myThread].size()){ if (!pushableSegments[myThread].size()){
Util::sleep(1000); Util::wait(1000);
} }
} }