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.
(get_materials): Redesign.
(shiprepair, planerepair, landrepair): Use it. Behavioral change:
ship repairs outside harbors and plane repairs by a carrier can use
fewer materials. Before, such repairs consumed each required
commodity as far as available. Now, they consume the same fraction of
the real cost of each commodity, i.e. commodity use is limited by the
most scarce commodity. Neither old nor new behavior make much sense,
but the new code is simpler.
Ron Koenderink [Wed, 3 Jan 2007 12:54:41 +0000 (12:54 +0000)]
(decl): Prevent the deity from changing relations for a player to
self. Closes #1384998. Allow the deity to set the relations of a
player towards the deity.
New option AUTO_POWER; closes #1009993:
(opt_AUTO_POWER, update_power): New.
(update_main): Implement AUTO_POWER.
(powe): Disable power new when AUTO_POWER is on.
(powe): New power update.
(gen_power): Compute power into buffer passed by caller, make write to
power file optional.
Ron Koenderink [Tue, 26 Dec 2006 19:17:22 +0000 (19:17 +0000)]
(do_mob_land): Disable automatic land unit fortification with excess
mobility when MOB_ACCESS is on. It leads to excessively deep
recursion and thus miserable performance as the number of land units
grows.
Ron Koenderink [Wed, 29 Nov 2006 12:16:43 +0000 (12:16 +0000)]
(ef_open) [_WIN32]: Fix to get a read lock instead of a write lock for
EFF_RDONLY and to get a write lock instead of a total file lock for
file opened for writing.
Ron Koenderink [Tue, 10 Oct 2006 20:23:19 +0000 (20:23 +0000)]
(switch_leader): Generalize the code, no functional changes.
(navi): Change switch_flagship() to call switch_leader() instead.
(switch_flagship): Remove, not needed, replaced with switch_leader().
(take_casualties): Code for distributing casualties among units did
not make sense, and in its confusion destroyed land land units when it
shouldn't. Minimally invasive fix; code is still ugly and
incomprehensible.