(update_lock, play_lock, update_pending, play_wrlock_wanted): Move to
main.c and rename to better reflect their purpose. Fix misleading comments.
This commit is contained in:
parent
d4150cc2ee
commit
a9afd1efef
5 changed files with 31 additions and 29 deletions
|
@ -36,11 +36,12 @@
|
||||||
|
|
||||||
#include "empthread.h"
|
#include "empthread.h"
|
||||||
|
|
||||||
extern int shutdown_pending;
|
|
||||||
extern int update_pending;
|
|
||||||
extern int update_running;
|
|
||||||
extern empth_rwlock_t *update_lock;
|
|
||||||
#define UPDATE_TIME_LEN 16
|
#define UPDATE_TIME_LEN 16
|
||||||
|
|
||||||
|
extern int shutdown_pending;
|
||||||
|
extern empth_rwlock_t *play_lock;
|
||||||
|
extern int play_wrlock_wanted;
|
||||||
|
extern int update_running;
|
||||||
extern time_t update_time[UPDATE_TIME_LEN];
|
extern time_t update_time[UPDATE_TIME_LEN];
|
||||||
|
|
||||||
void market_init(void);
|
void market_init(void);
|
||||||
|
|
|
@ -324,9 +324,9 @@ io_output_all(struct iop *iop)
|
||||||
* Mustn't block a player thread while update is pending, or else
|
* Mustn't block a player thread while update is pending, or else
|
||||||
* a malicous player could delay the update indefinitely
|
* a malicous player could delay the update indefinitely
|
||||||
*/
|
*/
|
||||||
while (((n = io_output(iop, IO_NOWAIT)) > 0) && !update_pending) {
|
while ((n = io_output(iop, IO_NOWAIT)) > 0 && !play_wrlock_wanted)
|
||||||
empth_select(iop->fd, EMPTH_FD_WRITE);
|
empth_select(iop->fd, EMPTH_FD_WRITE);
|
||||||
}
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,7 @@ dispatch(char *buf, char *redir)
|
||||||
pr("Command not implemented\n");
|
pr("Command not implemented\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
empth_rwlock_rdlock(update_lock);
|
empth_rwlock_rdlock(play_lock);
|
||||||
if (redir) {
|
if (redir) {
|
||||||
prredir(redir);
|
prredir(redir);
|
||||||
uprnf(buf);
|
uprnf(buf);
|
||||||
|
@ -110,7 +110,7 @@ dispatch(char *buf, char *redir)
|
||||||
logerror("%s: returned bad value", command->c_form);
|
logerror("%s: returned bad value", command->c_form);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
empth_rwlock_unlock(update_lock);
|
empth_rwlock_unlock(play_lock);
|
||||||
player->command = 0;
|
player->command = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,19 @@ static void loc_NTInit(void);
|
||||||
static void loc_NTTerm(void);
|
static void loc_NTTerm(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Lock to synchronize player threads with update and shutdown.
|
||||||
|
* Update and shutdown takes it exclusive, commands take it shared.
|
||||||
|
*/
|
||||||
|
empth_rwlock_t *play_lock;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Is a thread attempting to take an exclusive play_lock?
|
||||||
|
* Threads holding a shared play_lock must not sleep while this is
|
||||||
|
* true.
|
||||||
|
*/
|
||||||
|
int play_wrlock_wanted;
|
||||||
|
|
||||||
static char pidfname[] = "server.pid";
|
static char pidfname[] = "server.pid";
|
||||||
|
|
||||||
/* Run as daemon? If yes, detach from controlling terminal etc. */
|
/* Run as daemon? If yes, detach from controlling terminal etc. */
|
||||||
|
@ -373,7 +386,7 @@ shutdwn(int sig)
|
||||||
}
|
}
|
||||||
empth_wakeup(p->proc);
|
empth_wakeup(p->proc);
|
||||||
}
|
}
|
||||||
empth_rwlock_wrlock(update_lock);
|
empth_rwlock_wrlock(play_lock);
|
||||||
/* rely on player_kill_idle() for killing hung player threads */
|
/* rely on player_kill_idle() for killing hung player threads */
|
||||||
if (sig)
|
if (sig)
|
||||||
logerror("Server shutting down on signal %d", sig);
|
logerror("Server shutting down on signal %d", sig);
|
||||||
|
|
|
@ -48,18 +48,6 @@
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
|
|
||||||
/*
|
|
||||||
* Lock to synchronize player threads with the update.
|
|
||||||
* Update takes it exclusive, commands take it shared.
|
|
||||||
*/
|
|
||||||
empth_rwlock_t *update_lock;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Update is pending, player threads must give up update_lock ASAP.
|
|
||||||
* This means they must not block while update_pending.
|
|
||||||
*/
|
|
||||||
int update_pending;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Update is running.
|
* Update is running.
|
||||||
* Can be used to suppress messages, or direct them to bulletins.
|
* Can be used to suppress messages, or direct them to bulletins.
|
||||||
|
@ -86,8 +74,8 @@ update_init(void)
|
||||||
if (update_get_schedule() < 0)
|
if (update_get_schedule() < 0)
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
update_lock = empth_rwlock_create("Update");
|
play_lock = empth_rwlock_create("Update");
|
||||||
if (!update_lock)
|
if (!play_lock)
|
||||||
exit_nomem();
|
exit_nomem();
|
||||||
|
|
||||||
dp = player_new(-1);
|
dp = player_new(-1);
|
||||||
|
@ -205,7 +193,7 @@ update_run(void)
|
||||||
{
|
{
|
||||||
struct player *p;
|
struct player *p;
|
||||||
|
|
||||||
update_pending = 1;
|
play_wrlock_wanted = 1;
|
||||||
for (p = player_next(0); p != 0; p = player_next(p)) {
|
for (p = player_next(0); p != 0; p = player_next(p)) {
|
||||||
if (p->state != PS_PLAYING)
|
if (p->state != PS_PLAYING)
|
||||||
continue;
|
continue;
|
||||||
|
@ -215,18 +203,18 @@ update_run(void)
|
||||||
empth_wakeup(p->proc);
|
empth_wakeup(p->proc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
empth_rwlock_wrlock(update_lock);
|
empth_rwlock_wrlock(play_lock);
|
||||||
if (*pre_update_hook) {
|
if (*pre_update_hook) {
|
||||||
if (run_hook(pre_update_hook, "pre-update")) {
|
if (run_hook(pre_update_hook, "pre-update")) {
|
||||||
update_pending = 0;
|
play_wrlock_wanted = 0;
|
||||||
empth_rwlock_unlock(update_lock);
|
empth_rwlock_unlock(play_lock);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
update_running = 1;
|
update_running = 1;
|
||||||
update_main();
|
update_main();
|
||||||
update_pending = update_running = 0;
|
play_wrlock_wanted = update_running = 0;
|
||||||
empth_rwlock_unlock(update_lock);
|
empth_rwlock_unlock(play_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue