Keep capabilities and protocol config around after close, retry opening pages for ~50ms, no longer warn in save situations of SHM re-use

This commit is contained in:
Thulinma 2023-07-11 14:17:22 +02:00
parent e8388b2a89
commit b7d5964512
4 changed files with 58 additions and 11 deletions

View file

@ -919,7 +919,12 @@ bool Util::checkException(const JSON::Value &ex, const std::string &useragent){
}
Util::DTSCShmReader::DTSCShmReader(const std::string &pageName){
size_t attempts = 0;
do {
rPage.init(pageName, 0, false, false);
++attempts;
if (!rPage && attempts < 5){Util::sleep(10);}
} while (!rPage && attempts < 5);
if (rPage){rAcc = Util::RelAccX(rPage.mapped);}
}

View file

@ -21,6 +21,8 @@ namespace Controller{
JSON::Value Storage; ///< Global storage of data.
tthread::mutex configMutex;
tthread::mutex logMutex;
std::set<std::string> shmList;
tthread::mutex shmListMutex;
uint64_t logCounter = 0;
uint64_t lastConfigChange = 0;
uint64_t lastConfigWrite = 0;
@ -217,6 +219,7 @@ namespace Controller{
if (shmAccs){shmAccs->master = true;}
if (rlxStrm){rlxStrm->setExit();}
if (shmStrm){shmStrm->master = true;}
wipeShmPages();
}else{
if (shmLogs){shmLogs->master = false;}
if (shmAccs){shmAccs->master = false;}
@ -442,6 +445,7 @@ namespace Controller{
mistCapaOut.close();
}
mistCapaOut.init(SHM_CAPA, temp.size() + 100, true, false);
addShmPage(SHM_CAPA);
if (!mistCapaOut.mapped){
FAIL_MSG("Could not open capabilities config for writing! Is shared memory enabled on your "
"system?");
@ -454,6 +458,7 @@ namespace Controller{
A.setRCount(1);
A.setEndPos(1);
A.setReady();
mistCapaOut.master = false;
}
void writeProtocols(){
@ -473,6 +478,7 @@ namespace Controller{
if (proxy_written != tmpProxy){
proxy_written = tmpProxy;
static IPC::sharedPage mistProxOut(SHM_PROXY, proxy_written.size() + 100, true, false);
addShmPage(SHM_PROXY);
mistProxOut.close();
mistProxOut.init(SHM_PROXY, proxy_written.size() + 100, false, false);
if (mistProxOut){
@ -511,6 +517,7 @@ namespace Controller{
mistProtoOut.close();
}
mistProtoOut.init(SHM_PROTO, temp.size() + 100, true, false);
addShmPage(SHM_PROTO);
if (!mistProtoOut.mapped){
FAIL_MSG(
"Could not open protocol config for writing! Is shared memory enabled on your system?");
@ -526,6 +533,7 @@ namespace Controller{
A.setEndPos(1);
A.setReady();
}
mistProtoOut.master = false;
}
void writeStream(const std::string &sName, const JSON::Value &sConf){
@ -640,6 +648,7 @@ namespace Controller{
globAccX.setString("udpApi", udpApiBindAddr);
globAccX.setInt("systemBoot", systemBoot);
globCfg.master = false; // leave the page after closing
addShmPage(SHM_GLOBAL_CONF);
}
}
@ -752,4 +761,23 @@ namespace Controller{
}
/*LTS-END*/
}
void addShmPage(const std::string & page){
tthread::lock_guard<tthread::mutex> guard(shmListMutex);
shmList.insert(page);
}
void wipeShmPages(){
tthread::lock_guard<tthread::mutex> guard(shmListMutex);
if (!shmList.size()){return;}
std::set<std::string>::iterator it;
for (it = shmList.begin(); it != shmList.end(); ++it){
IPC::sharedPage page(*it, 0, false, false);
if (page){page.master = true;}
}
shmList.clear();
}
}// namespace Controller

View file

@ -50,4 +50,7 @@ namespace Controller{
void writeCapabilities();
void writeProtocols();
void addShmPage(const std::string & page);
void wipeShmPages();
}// namespace Controller

View file

@ -423,7 +423,8 @@ namespace Mist{
//Set stream status to STRMSTAT_INIT, then close the page in non-master mode to keep it around
char pageName[NAME_BUFFER_SIZE];
snprintf(pageName, NAME_BUFFER_SIZE, SHM_STREAM_STATE, streamName.c_str());
streamStatus.init(pageName, 2, true, false);
streamStatus.init(pageName, 2, false, false);
if (!streamStatus){streamStatus.init(pageName, 2, true, false);}
if (streamStatus){streamStatus.mapped[0] = STRMSTAT_INIT;}
streamStatus.master = false;
streamStatus.close();
@ -470,7 +471,8 @@ namespace Mist{
// Re-init streamStatus, previously closed
char pageName[NAME_BUFFER_SIZE];
snprintf(pageName, NAME_BUFFER_SIZE, SHM_STREAM_STATE, streamName.c_str());
streamStatus.init(pageName, 2, true, false);
streamStatus.init(pageName, 2, false, false);
if (!streamStatus){streamStatus.init(pageName, 2, true, false);}
streamStatus.master = false;
if (streamStatus){streamStatus.mapped[0] = STRMSTAT_INIT;}
}
@ -480,9 +482,12 @@ namespace Mist{
playerLock.unlink();
char pageName[NAME_BUFFER_SIZE];
snprintf(pageName, NAME_BUFFER_SIZE, SHM_STREAM_STATE, streamName.c_str());
streamStatus.init(pageName, 2, true, false);
streamStatus.init(pageName, 2, false, false);
if (streamStatus){
streamStatus.master = true;
streamStatus.close();
}
}
playerLock.unlink();
pullLock.unlink();
return ret;
@ -501,7 +506,8 @@ namespace Mist{
// Re-init streamStatus, previously closed
char pageName[NAME_BUFFER_SIZE];
snprintf(pageName, NAME_BUFFER_SIZE, SHM_STREAM_STATE, streamName.c_str());
streamStatus.init(pageName, 2, true, false);
streamStatus.init(pageName, 2, false, false);
if (!streamStatus){streamStatus.init(pageName, 2, true, false);}
streamStatus.master = false;
if (streamStatus){streamStatus.mapped[0] = STRMSTAT_INIT;}
}
@ -539,7 +545,7 @@ namespace Mist{
if (playerLock){
char pageName[NAME_BUFFER_SIZE];
snprintf(pageName, NAME_BUFFER_SIZE, SHM_STREAM_STATE, streamName.c_str());
streamStatus.init(pageName, 2, true, false);
streamStatus.init(pageName, 2, false, false);
if (streamStatus){streamStatus.mapped[0] = STRMSTAT_INVALID;}
}
#if DEBUG >= DLVL_DEVEL
@ -566,12 +572,17 @@ namespace Mist{
char pageName[NAME_BUFFER_SIZE];
snprintf(pageName, NAME_BUFFER_SIZE, SHM_STREAM_IPID, streamName.c_str());
pidPage.init(pageName, 8, false, false);
if (pidPage){
pidPage.master = true;
pidPage.close();
}
//Clear stream state
snprintf(pageName, NAME_BUFFER_SIZE, SHM_STREAM_STATE, streamName.c_str());
streamStatus.init(pageName, 2, true, false);
streamStatus.init(pageName, 2, false, false);
if (streamStatus){
streamStatus.master = true;
streamStatus.close();
}
//Delete lock
playerLock.unlink();
}