Ron Koenderink [Sun, 11 Mar 2007 21:29:37 +0000 (21:29 +0000)]
(S_IRUSR, S_IWUSR, S_IEUSR, S_IRWXU,
S_IRGRP, S_IWGRP, S_IEGRP, S_IRWXG,
S_IROTH, S_IWOTH, S_IEOTH, S_IRWXO) [_WIN32]:
Add #ifndef for standard defines as the the MinGW environment has the
user defines already created. Correct EXEC permision to use S_IEXEC.
Set the group and other permssions to 0 as they do not exist in WIN32.
Ron Koenderink [Sat, 10 Mar 2007 16:29:51 +0000 (16:29 +0000)]
(add, disa, ef_open, logerror, main): Switch permissions to
standard defines instead of magic numbers to improve portability.
Also define WIN32 equivalents to the standard defines.
Rewrite how updates are triggered (closes #1504036):
(update_init, update_sched, update_run, update_wait): Don't create a
separate UpdateSched thread, run update_sched() in the Update thread.
Run the update by calling update_run() instead of by signalling its
thread. update_run() replaces update_wait(); it just runs the update
and returns instead of waiting for the signal to update in a loop.
Move initialization of the Update thread's *player to its new thread
entry point.
(update_sem, update_init): Remove update_sem.
(update_thread): New.
(update_init): Initialize it.
(update_forced): New.
(update_trigger, update_force): Wake up update_thread with
update_force set.
(update_sched): Reset it before sleep, test it after sleep so that
schedule checking is only done for scheduled updates, not forced
updates.
(update_sched, update_init): Move sanity test of s_p_etu to
update_init().
Make empth_wakeup() and empth_terminate() wake up empth_sleep(), and
empth_sleep() return whether that happened:
[EMPTH_LWP] (lwpWakeupSleep): New, factored out of lwpSelect().
[EMPTH_LWP] (lwpSelect): Use it.
[EMPTH_LWP] (lwpWakeup): New. Call lwpWakeupFd() if sleeping in
lwpSleepFd(), lwpWakeupSleep() if sleeping in lwpSleepUntil().
[EMPTH_LWP] (lwpTerminate, empth_wakeup): Use it rather than
lwpWakeupFd().
[EMPTH_LWP] (lwpWakeupFd): Internal linkage.
[EMPTH_LWP] (lwpSleepUntil): Reset member runtime, so that lwpWakeup()
can test it reliably. Return how sleep woke up.
[EMPTH_LWP] (empth_sleep): Return value of lwpSleepUntil().
[EMPTH_POSIX] (EMPTH_INTR): New.
[EMPTH_POSIX] (empth_wakeup): Set state to it.
[EMPTH_POSIX] (empth_restorectx): Clear state.
[EMPTH_POSIX] (empth_sleep): Don't re-seleep when state is not clear,
i.e. thread was woken up prematurely. Return how sleep woke up.
[EMPTH_W32] (empth_sleep): Implement by waiting on hThreadEvent with a
timeout rather than a straight Sleep(). Return how sleep woke up.
Simplify. Should also be more efficient.
(LwpSigCheck): New.
(lwpCatchAwaitedSig): Set it.
(lwpSigWait): Clear it.
(lwpSigWakeup): Test it.
(lwpSigWakeup): Unblock LwpSigWaiter without testing LwpSigCatched.
(lwpSigWait): Test LwpSigCatched after wakeup.
(LwpSigAwaited, LwpSigPtr): Remove.
(lwpCreate): Initialize members runtime and fd. Initializing fd is
necessary to make lwpWakeupFd() work reliably. Initializing runtime
isn't strictly necessary, as it is used only while the thread is on
LwpDelayq, and putting it there sets runtime.
Ron Koenderink [Sat, 27 Jan 2007 02:04:27 +0000 (02:04 +0000)]
(unit_view): New, create by expanding shp_view() to work for
land_unit as well.
(do_unit_move): Add view option for land units using unit_view().
Combine ship and land viewing using the unit_view().
(shp_view): Remove, not used any more, replaced by unit_view().
Ron Koenderink [Wed, 24 Jan 2007 23:24:37 +0000 (23:24 +0000)]
(unit_path): New, create by combining shp_path() and lnd_path().
(do_unit_move): Replace shp_path() and lnd_path() with unit_path().
(shp_path, lnd_path): Remove shp_path() and lnd_path(),
not used any more.
Ron Koenderink [Tue, 23 Jan 2007 01:41:37 +0000 (01:41 +0000)]
(unit_list): New, create by combining shp_list() and lnd_list().
(do_unit_move): Replace call to shp_list() and lnd_list() with unit_list().
(shp_list, lnd_list): Remove, not needed, replaced by unit_list().
(ef_open_srv, start_server): Journal must not be written before
empth_init(), because writing calls empth_self(). Move call of
journal_startup().
(ef_close_srv, finish_server, panic): Move call of journal_shutdown()
for symmetry.
Fix server not to create a journal on SIGHUP when !keep_journal:
(journal_reopen): New.
(main): Use it. Fixes failure to obey !keep_journal.
(journal_open): Internal linkage, changed semantics and return value.
Callers changed.
(journal_close): One caller left, inline and remove.
(shutdwn): Take exclusive update lock for shutdown. This makes the
shutdown block until all aborted commands terminated and gave up their
lock. Remove the cheesy one second wait for commands to finish. This
also locks out further commands to execute during shutdown. However,
it also makes it impossible to kill hung player threads here. Rely on
player_kill_idle() for that. That doesn't quite work right now,
because it leaves a stale shared lock behind, which blocks shutdown.
Ron Koenderink [Sun, 21 Jan 2007 11:39:52 +0000 (11:39 +0000)]
(do_unit_move): Change unit type to be determined at the
beginning of function instead using the leader. The leader
becomes unknown when stopping or unit list becomes
empty. This broke printing the path for ships. Broken
in rev 1.43.
Abstract from shutdown initiation mechanism:
(shutdown_initiate): New.
(shut): Use it. Shutdown in zero minutes no longer cancels the
shutdown, it just works. Use negative argument to cancel. Logging is
less detailed.
(shutdown_sequence): Internal linkage.
(pr_wall): All callers prefix text it with the same header. Move it
into the function.
(sendmessage): Don't split messages into lines of no more than 60
characters. Update info flash and wall. They were wrong, anyway:
they claimed long messages were truncated.
(coll): Fix freeing of repaid loan. The incorrectly freed loan
continued to exist. Fortunately, both shark and collect refused to
touch it. fina() and repa() oopsed in loan_owed(), and recovered by
assuming (incorrectly!) a plausible debt. Before trdsub.c rev. 1.7,
fina() catched and logged the bug, and ignored the loan, and repa()
computed a ridiculous debt.
Ron Koenderink [Thu, 18 Jan 2007 01:05:19 +0000 (01:05 +0000)]
(empth_wait_for_signal) [WIN32]: Simplify empth_wait_for_signal()
by combined the waiting for hShutdownEvent and hThreadMutex
using the optional parmeter added to loc_RunThisThread().
(ac_encounter): Called writemap() only for active sorties, and not
when update_pending. This makes no sense. The map is updated in
memory and not calling writemap() only delays the write back to disk.
Remove the conditional.
Fuse market update and market check thread:
(check_all_markets): No longer a thread entry point. Remove the
parameter. Remove *player setup. Don't terminate the thread when
done.
(market_update): Call check_all_markets() instead of running it in its
own thread. Set up *player for it.
(market_init): Create the fused update thread instead of the update
wait thread.
Fuse update wait thread and update thread:
(update_main): No longer a thread entry point. Remove the parameter.
Remove *player setup. Don't terminate the thread when done.
(update_pending): Move to src/server/update.c.
(update_wait): Call update_main() instead of running it in its own
thread. Set up *player for it.
(update_init): Create the fused update thread instead of the update
wait thread.
Synchronize commands and update properly with a lock (towards
resolving #1458175 and #1504036):
(update_lock): New.
(update_shed): Initialize it.
(update_wait, dispatch): Take exclusive update_lock around the update,
shared update_lock around commands. This makes the update block until
all aborted commands terminated and gave up their lock. Remove the
cheesy and unsafe two second wait for commands to finish. It also
makes player threads block before executing commands while the update
is pending, removing the need to fail commands then. So don't.
Ron Koenderink [Mon, 15 Jan 2007 13:34:33 +0000 (13:34 +0000)]
(struct loc_Thread_t, struct loc_Sem_t, hThreadStartEvent)
(loc_RunThisThread, empth_init, empth_create, empth_wait_for_signal)
[EMPTH_W32]: Remove some incorrect references to semaphones
in the comments. No functional changes.
Ron Koenderink [Mon, 15 Jan 2007 12:45:35 +0000 (12:45 +0000)]
(loc_RunThread, empth_init, empth_threadMain, empth_yield)
(empth_select, empth_sleep, empth_wait_for_signal)
(empth_sem_wait) [EMPTH_W32]: Add the ability to wait additional
event in loc_RunThread() when acquiring the hThread mutex.
(produce_sect): Use bp_put_items() after calls that may update vec[].
This is more robust than using bp_put_item() for those elements of
vec[] that the call may change. The old code missed some changes:
upd_buildeff() changing population when tearing down a big city,
enlist(), and produce(). The first two should have been harmless, the
last one made budget mispredict repairs when required materials were
produced in the same update.
(do_feed, produce_sect): Move bp_put_item() calls from do_feed() to
produce_sect(), for consistency with the other update functions that
update sct_item[]. Parameter bp is now unused, remove.
(bp): Rename member val to bp_item, member avail to bp_avail. Users
changed. Switch from int to short, to match struct sctstr members
sct_item and sct_avail.
Symbolic indexes for struct bp member bp_item[]:
(BP_NONE, BP_CIVIL, BP_MILIT, BP_SHELL, BP_GUN, BP_LCM, BP_HCM)
(BP_MAX): New.
(bug_key): Use them. Values are now array indexes, not indexes + 1.
(bp_get_item, bp_put_item, bp_set_from_sect): Update for changed
bud_key[].
(get_wp, bp_ref): Replace function returning pointer into a struct bp
by function returning to struct bp. Leave member access to callers.
Callers changed.
Replace the revolting build pointer data structure by a proper data
type. Make it abstract because that's possible. Change data layout
so that the slots belonging to a sector are together in memory, it's
nicer to the cache.
(bp): The new type. Users changed.
(get_wp): Update accordingly.
(alloc_bp): New.
(update_main, calc_all): Use it. Before, calc_all() allocated 1/7
more than necessary.