Simplify checks whether player thread may sleep
A player thread may sleep on input or output, except: (1) While it is executing a C_MOD command, it may only sleep on input. (2) While it is being aborted by the update or shutdown, it may not sleep at all. To find out whether a player thread may sleep on input, code has to check condition (2). It needs do to that in recvclient(). To find out whether it may sleep on output, it has to check both conditions. It needs to do that in pr_player() and upr_player(). The code tracked condition (1) in global variable play_lock_wanted. It checked condition (2) by examining struct player member command. Replace all that by new struct player member may_sleep. Initialize it in player_new(), update it in dispatch(), shutdwn() and update_run(). This makes the tests in recvclient(), pr_player() and upr_player() obvious. play_wrlock_wanted() is now unused, remove it.
This commit is contained in:
parent
bd6d9d53a0
commit
0a4d77e919
8 changed files with 17 additions and 20 deletions
|
@ -51,6 +51,10 @@
|
|||
#define CAP bit(6)
|
||||
#define MONEY bit(7)
|
||||
|
||||
enum player_sleep {
|
||||
PLAYER_SLEEP_NEVER, PLAYER_SLEEP_ON_INPUT, PLAYER_SLEEP_FREELY
|
||||
};
|
||||
|
||||
struct player {
|
||||
struct emp_qelem queue;
|
||||
empth_t *proc;
|
||||
|
@ -76,6 +80,7 @@ struct player {
|
|||
int simulation; /* e.g. budget command */
|
||||
double dolcost;
|
||||
time_t curup; /* when last input was received */
|
||||
enum player_sleep may_sleep; /* when may thread sleep? */
|
||||
int aborted; /* interrupt cookie or EOF received? */
|
||||
int eof; /* EOF (cookie or real) received? */
|
||||
int recvfail; /* #recvclient() failures */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue