MCPcopy Index your code
hub / github.com/assaultcube/AC / poll_serverthreads

Function poll_serverthreads

source/src/server.cpp:165–309  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

163bool triggerpollrestart = false;
164
165void poll_serverthreads() // called once per mainloop-timeslice
166{
167 static vector<servermap *> servermapstodelete;
168 static int stage = 0, lastworkerthreadstart = 0, nextserverconfig = 0;
169 static bool debugmaprot = true, serverwasnotempty = false;
170
171 switch(stage) // cycle through some tasks once per minute (mostly file polling)
172 {
173 default: // start first thread
174 {
175 if(startnewservermapsepoch || readmapsthread_sem->getvalue()) fatal("thread management mishap"); // zero tolerance...
176
177 // wake readmapsthread
178 mlog(ACLOG_DEBUG,"waking readmapsthread");
179 startnewservermapsepoch = true;
180 servclock = (int) (time(NULL) / (time_t) 60);
181 readmapsthread_sem->post();
182 stage = 1;
183 lastworkerthreadstart = servmillis;
184 triggerpollrestart = false;
185 break;
186 }
187 case 1: // readmapsthread building/updating the list of maps in memory
188 {
189 servermap *fresh = (servermap *) servermapdropbox;
190 if(fresh)
191 {
192 if(fresh == servermapdropbox)
193 {
194 // got new servermap...
195 loopv(servermaps)
196 {
197 if(!strcmp(servermaps[i]->fname, fresh->fname)) // we don't check paths here - map filenames have to be unique
198 { // found map of same name
199 mlog(ACLOG_VERBOSE,"marked servermap %s%s for deletion", servermaps[i]->fpath, servermaps[i]->fname);
200 servermapstodelete.add(servermaps.remove(i)); // mark old version for deletion
201 }
202 }
203 if(fresh->isok)
204 {
205 servermaps.add(fresh);
206 mlog(servmillis>2345?ACLOG_INFO:ACLOG_VERBOSE,"added servermap %s%s", fresh->fpath, fresh->fname); // 1st time only in VERBOSE
207 maprot.initmap(fresh, NULL);
208 servermaps.sort(servermapsortname); // keep list sorted at all times
209 }
210 else delete fresh;
211 servermapdropbox = NULL;
212 }
213 readmapsthread_sem->post();
214 }
215 else if(!startnewservermapsepoch)
216 {
217 // readmapsthread is done
218 if(servmillis<2000)mlog(ACLOG_INFO,"added %d servermaps",servermaps.length());
219 while(!readmapsthread_sem->trywait())
220 ;
221 stage++;
222 }

Callers 1

serversliceFunction · 0.85

Calls 15

mlogFunction · 0.85
parsevitasFunction · 0.85
openfileFunction · 0.85
pathFunction · 0.85
numtimeFunction · 0.85
asctimestrFunction · 0.85
numclientsFunction · 0.85
pushvitasforsavingFunction · 0.85
poll_logbuffersFunction · 0.85
getvalueMethod · 0.80
postMethod · 0.80
initmapMethod · 0.80

Tested by

no test coverage detected