(exit_nomem): New.
(update_init): New. (start_server): Call it. (start_server, update_sched): Move initialization stuff to it, with error checking added. (update_sched): Internal linkage.
This commit is contained in:
parent
6cbdd3e02a
commit
d38fcc6cf4
5 changed files with 40 additions and 11 deletions
|
@ -111,6 +111,8 @@ extern int debug;
|
|||
|
||||
extern int oops(char *, char *, int);
|
||||
|
||||
void exit_nomem(void) ATTRIBUTE((noreturn));
|
||||
|
||||
/* return codes from command routines */
|
||||
#define RET_OK 0 /* command completed sucessfully */
|
||||
#define RET_FAIL 1 /* command completed unsucessfully [?] */
|
||||
|
|
|
@ -51,7 +51,7 @@ void market_update(void *);
|
|||
void mobility_check(void *);
|
||||
void player_kill_idle(void *);
|
||||
void update_main(void *);
|
||||
void update_sched(void *);
|
||||
void update_init(void);
|
||||
void shutdown_sequence(void *);
|
||||
void update_force(void *);
|
||||
|
||||
|
|
|
@ -110,3 +110,16 @@ oops(char *msg, char *file, int line)
|
|||
if (debug) abort();
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Report out-of-memory condition and terminate the program.
|
||||
* Use this with restraint! Clean error recovery is preferable, but
|
||||
* not always feasible (e.g. halfway through the update) or worthwhile
|
||||
* (during server startup).
|
||||
*/
|
||||
void
|
||||
exit_nomem(void)
|
||||
{
|
||||
logerror("Memory exhausted");
|
||||
exit(1);
|
||||
}
|
||||
|
|
|
@ -325,8 +325,6 @@ start_server(int flags)
|
|||
"AcceptPlayers", "Accept network connections", 0);
|
||||
empth_create(PP_KILLIDLE, player_kill_idle, (50 * 1024), flags,
|
||||
"KillIdle", "Kills idle player connections", 0);
|
||||
empth_create(PP_SCHED, update_sched, (50 * 1024), flags, "UpdateSched",
|
||||
"Schedules updates to occur", 0);
|
||||
empth_create(PP_TIMESTAMP, delete_lostitems, (50 * 1024), flags,
|
||||
"DeleteItems", "Deletes old lost items", 0);
|
||||
if (opt_MOB_ACCESS) {
|
||||
|
@ -339,6 +337,8 @@ start_server(int flags)
|
|||
empth_create(PP_TIMESTAMP, market_update, (50 * 1024), flags,
|
||||
"MarketUpdate", "Updates the market", 0);
|
||||
}
|
||||
|
||||
update_init();
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -51,20 +51,34 @@ empth_sem_t *update_sem;
|
|||
empth_rwlock_t *update_lock;
|
||||
time_t update_time;
|
||||
|
||||
static void update_sched(void *);
|
||||
static void update_wait(void *unused);
|
||||
static int run_hook(char *cmd, char *name);
|
||||
|
||||
/*ARGSUSED*/
|
||||
void
|
||||
update_init(void)
|
||||
{
|
||||
update_sem = empth_sem_create("Update", 0);
|
||||
update_lock = empth_rwlock_create("Update");
|
||||
if (!update_sem || !update_lock)
|
||||
exit_nomem();
|
||||
|
||||
if (!empth_create(PP_SCHED, update_wait, 50 * 1024, 0,
|
||||
"Update", "Updates the world", NULL))
|
||||
exit_nomem();
|
||||
|
||||
if (!empth_create(PP_SCHED, update_sched, 50 * 1024, 0,
|
||||
"UpdateSched", "Schedules updates to occur", NULL))
|
||||
exit_nomem();
|
||||
}
|
||||
|
||||
/*ARGSUSED*/
|
||||
static void
|
||||
update_sched(void *unused)
|
||||
{
|
||||
int wind;
|
||||
time_t now, delta;
|
||||
|
||||
update_sem = empth_sem_create("Update", 0);
|
||||
update_lock = empth_rwlock_create("Update");
|
||||
empth_create(PP_SCHED, update_wait, (50 * 1024), 0, "UpdateWait",
|
||||
"Waits until players idle", 0);
|
||||
if (s_p_etu <= 0) {
|
||||
logerror("bad value for s_p_etu (%d)", s_p_etu);
|
||||
s_p_etu = 2 * 60;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue