Abstract from update trigger mechanism:
(update_trigger): New. (force, zdon): Use it. (update_sem, update_force): Internal linkage. (update_trigger, update_force): Passing a pointer to static storage as thread argument is racy. Use dynamic allocation.
This commit is contained in:
parent
553662f305
commit
861112f827
4 changed files with 38 additions and 10 deletions
|
@ -38,7 +38,6 @@
|
|||
|
||||
extern int shutdown_pending;
|
||||
extern int update_pending;
|
||||
extern empth_sem_t *update_sem;
|
||||
extern empth_rwlock_t *update_lock;
|
||||
extern time_t update_time;
|
||||
extern int updating_mob;
|
||||
|
@ -52,7 +51,7 @@ void mobility_check(void *);
|
|||
void player_kill_idle(void *);
|
||||
void update_main(void);
|
||||
void update_init(void);
|
||||
int update_trigger(time_t);
|
||||
void shutdown_sequence(void *);
|
||||
void update_force(void *);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -34,13 +34,12 @@
|
|||
#include <config.h>
|
||||
|
||||
#include "commands.h"
|
||||
#include "empthread.h"
|
||||
#include "server.h"
|
||||
|
||||
int
|
||||
force(void)
|
||||
{
|
||||
static int seconds;
|
||||
int seconds;
|
||||
|
||||
if (update_pending) {
|
||||
pr("Update is pending\n");
|
||||
|
@ -59,7 +58,7 @@ force(void)
|
|||
return RET_FAIL;
|
||||
|
||||
pr("Scheduling update in %d second(s)\n", seconds);
|
||||
empth_create(PP_SCHED, update_force, (50 * 1024), 0, "forceUpdate",
|
||||
"Schedules an update", &seconds);
|
||||
if (update_trigger(seconds) < 0)
|
||||
return RET_FAIL;
|
||||
return RET_OK;
|
||||
}
|
||||
|
|
|
@ -52,7 +52,6 @@
|
|||
#include <config.h>
|
||||
|
||||
#include "commands.h"
|
||||
#include "empthread.h"
|
||||
#include "optlist.h"
|
||||
#include "server.h"
|
||||
|
||||
|
@ -142,7 +141,7 @@ zdon(void)
|
|||
|
||||
if (!checking && wantupd && demandupdatecheck()) {
|
||||
pr("Here goes...\n");
|
||||
empth_sem_signal(update_sem);
|
||||
update_trigger(0);
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
* Dave Pare, 1994
|
||||
* Steve McClure, 1996
|
||||
* Ron Koenderink, 2005
|
||||
* Markus Armbruster, 2007
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -53,6 +54,7 @@ int update_pending;
|
|||
time_t update_time;
|
||||
|
||||
static void update_sched(void *);
|
||||
static void update_force(void *);
|
||||
static void update_wait(void *unused);
|
||||
static int run_hook(char *cmd, char *name);
|
||||
|
||||
|
@ -126,14 +128,43 @@ update_sched(void *unused)
|
|||
/*NOTREACHED*/
|
||||
}
|
||||
|
||||
void
|
||||
/*
|
||||
* Trigger an update SECS_FROM_NOW seconds from now.
|
||||
* Return 0 on success, -1 on failure.
|
||||
*/
|
||||
int
|
||||
update_trigger(time_t secs_from_now)
|
||||
{
|
||||
static time_t *secp;
|
||||
|
||||
if (secs_from_now < 0)
|
||||
return -1;
|
||||
|
||||
if (secs_from_now == 0) {
|
||||
empth_sem_signal(update_sem);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* FIXME make triggers overwrite, not accumulate */
|
||||
secp = malloc(sizeof(time_t));
|
||||
if (!secp)
|
||||
return -1;
|
||||
*secp = secs_from_now;
|
||||
if (!empth_create(PP_SCHED, update_force, 50 * 1024, 0, "forceUpdate",
|
||||
"Schedules an update", secp))
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
update_force(void *seconds)
|
||||
{
|
||||
time_t now;
|
||||
|
||||
time(&now);
|
||||
empth_sleep(now + *(int *)seconds);
|
||||
empth_sleep(now + *(time_t *)seconds);
|
||||
empth_sem_signal(update_sem);
|
||||
free(seconds);
|
||||
empth_exit();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue