Commit graph

37 commits

Author SHA1 Message Date
2503e41bd2 Rename play_lock back to update_lock
It was renamed to play_lock because it synchronized not just updates
but also shutdown.  Since the previous commit, it again only
synchronizes updates.  Rename it back.

Also move its initialization next to shutdown_lock's.
2012-04-26 20:08:57 +02:00
49ae6a7b9d Fix synchronization between shutdown and player threads
shutdwn() sets the EOF indicator, aborts the running command, if any,
forbids sleeping on I/O and wakes up the player thread, for all player
threads in state PS_PLAYING.  It takes play_lock to prevent new
commands from running.  It then waits up to 3s for player threads to
terminate, by polling player_next(), to let output buffers drain.

Issues:

1. Polling is lame.

2. New player threads can still enter state PS_PLAYING.  They'll block
   as soon as they try to run a command.  Somehwat unclean.

3. We can exit before all player threads left state PS_PLAYING, losing
   a treasury update, play time update, and log entries.  Could happen
   when player threads blocked on output until commit 90b3abc5 fixed
   that; its commit message describes the bug's impact in more detail.
   Since then, the bug shouldn't bite in practice, because player
   threads should leave state PS_PLAYING quickly.

Fix by introducing shutdown_lock: player threads in state PS_PLAYING
hold it shared, shutdwn() takes it exclusive, instead of play_lock.
Takes care of the issues as follows:

3. shutdwn() waits until all player threads left state PS_PLAYING, no
   matter how long it takes them.

2. New player threads block before entering state PS_PLAYING.

1. shutdwn() still polls up to 3s for player threads to terminate.
   Still lame.  Left for another day.
2012-04-26 20:05:28 +02:00
7e2008e7f4 License upgrade to GPL version 3 or later
Why upgrade?  I'm not a lawyer, but here's my take on the differences
to version 2:

* Software patents: better protection against abuse of patents to
  prevent users from exercising the rights under the GPL.  I doubt
  we'll get hit with a patent suit, but it's a good move just on
  general principles.

* License compatibility: compatible with more free licenses, i.e. can
  "steal" more free software for use in Empire.  I don't expect to steal
  much, but it's nice to have the option.

* Definition of "source code": modernization of some details for today's
  networked world, to make it easier to distribute the software.  Not
  really relevant to us now, as we normally distribute full source code.

* Tivoization: this is about putting GPL-licensed software in hardware,
  then make the hardware refuse to run modified software.  "Neat" trick
  to effectively deny its users their rights under the GPL.  Abuse was
  "pioneered" by TiVo (popular digital video recorders).  GPLv3 forbids
  it.  Unlikely to become a problem for us.

* Internationalization: more careful wording, to harden the license
  outside the US.  The lawyers tell us it better be done that way.

* License violations: friendlier way to deal with license violations.
  This has come out of past experience enforcing the GPL.

* Additional permissions: Probably not relevant to us.

Also include myself in the list of principal authors.
2011-04-12 21:20:58 +02:00
73e25ff21e Update copyright notice 2010-01-19 08:40:17 +01:00
c528fcbe3e Update known contributors comments 2009-12-13 17:34:28 +01:00
0a4d77e919 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.
2009-11-30 19:43:18 +01:00
8cbcfefda1 Clean up useless declarations
Commit fbf9f15b removed SO, SE, but left their declarations behind.
Ditto commit 3aea20e1 for bigcity_dchr, and commit 08b94556 for
player_kill_idle.

Commit afa65c8f accidentally added a declaration for xedit().
2009-03-28 13:04:48 +01:00
35ef345ecb Update copyright notice 2009-02-08 09:33:18 +01:00
d702068457 Fix trailing whitespace 2008-09-17 21:31:40 -04:00
7441e2499f Expire lost items at the update instead of continuously
Replace thread DeleteItems running delete_lostitems() by simple
function delete_old_lostitems(), and call it from update_main().
2008-09-12 18:05:58 -04:00
ed9da7cf06 Update known contributors comments 2008-08-03 08:04:08 -04:00
f63401329d New post_crash_dump_hook
Run it from crash_dump().  Useful to move core files out of the way,
alert deities by e-mail, and so forth.
2008-04-25 22:12:22 +02:00
db02dda32f Update copyright notice 2008-01-19 10:15:37 +01:00
f915f91b47 Update known contributors comment. 2007-07-27 20:16:19 +00:00
a9afd1efef (update_lock, play_lock, update_pending, play_wrlock_wanted): Move to
main.c and rename to better reflect their purpose.  Fix misleading
comments.
2007-07-20 19:09:34 +00:00
Ron Koenderink
228a545ff3 (UPDATE_TIME_LEN): New.
(update_time): Define with size to make MSVC happy.
2007-07-19 21:58:05 +00:00
7dd8b8a305 New xdump updates:
(EF_UPDATES, update_ca): New.
(empfile): Add it.
(update_time): Move to src/lib/global/updtime.c.
2007-07-18 06:16:33 +00:00
e9cfbdc241 (update_running): New.
(update_run): Set it.

Replace incorrect uses of update_pending by update_running, fixing
buggy behavior while the update was trying to gain control:
(sct_do_upd_mob, shp_do_upd_mob, lnd_do_upd_mob, pln_do_upd_mob):
MOB_ACCESS mobility update was skipped.
(telegram_is_new): Fix recognition of new telegrams by timestamp.
(wu): Bulletins got misfiled as production reports.
(shp_nav): Sail path got ignored.
(setrel): Declaration of war failed silently with SLOW_WAR enabled.
Messages got suppressed.
(PR, mpr): Messages got misdirected to bulletins.
2007-07-17 06:13:14 +00:00
4bd19812af Use the new Empire clock for implementing MOB_ACCESS:
(lndstr, plnstr, sctstr, shpstr): Change timestamp members lnd_access,
pln_access, sct_access, shp_access from real time (time_t) to ETUs
within a turn (short).
(land_ca, plane_ca, sect_ca, ship_ca): Update accordingly.
(build_ship, build_land, build_bridge, build_plane, build_tower)
(explore, check_trade, bsanct, takeover, takeover_ship)
(takeover_land): Use game_tick_to_now() instead of time() to update
the timestamp.  Change check_trade(), takeover_ship(), takeover_land()
to do that only when MOB_ACCESS is enabled, for consistency.
(lupgr, supgr, pupgr, takeover_ship): Don't touch the timestamp where
mobility isn't touched either.
(sct_do_upd_mob, shp_do_upd_mob, lnd_do_upd_mob, pln_do_upd_mob): Use
game_tick_to_now() instead of increase_mob() to compute ETUs since
the timestamp and update the timestamp.  Closes #1012699.
(increase_mob): Remove.
(mob_sect, mob_ship, mob_land, mob_plane): sct_do_upd_mob() & friends
no longer do the right thing at the update.  Use game_reset_tick() and
pass its result directly to do_mob_sect() & friends.  This is only
correct when argument is etu_per_update, which it always is.  Remove
parameter.  Callers changed.
(do_mob_sect, do_mob_ship, do_mob_land, do_mob_plane): Oops on
negative argument.

(mob_acc_globals, timestampfil, mobupdate, updating_mob)
(update_all_mob, timestamp_fixing, update_timestamps, mobility_check):
The mobupdate command was important to let deities manually
synchronize mobility updating with updates.  That's no longer needed.
The code behind it is somewhat hairy and ugly, and updating it to work
with the Empire clock is just not worth it.  Remove.  Users changed.
(player_coms): Update accordingly.
(upda): Remove display of mobility updating state.

(mobility_init): No need to fix up mobility on startup, as the Empire
clock runs normally even when the server is down.  Remove.  Caller
changed.
2007-07-15 09:43:57 +00:00
71320ed67f New update scheduler:
(schedulefil): New.
(set_dirs, set_paths): Rename.  Initialize schedulfil.
(read_schedule): New.  Can read several updates, which will be used in
later changesets.
(update_time): Change to array.  Will be used in later changesets.
(update_schedule_anchor): New.
(update_init): Initialize it.
(update_get_schedule): New.
(update_init): Call it to initialize update_time[].
(update_sched): Rewrite.
(update_forced, update_wanted): Replace.
(update_reschedule): New.
(main): Call it on SIGHUP to reload the schedule.
(update_trigger, update_force, force, player_coms): Drop force's
capability to schedule updates in the future, because it's not worth
the trouble to implement again.  Deities can simply edit the schedule
file to schedule updates.  Remove update_force() and
update_trigger()'s parameter.
(upda): Update for new scheduler.  Take care to keep output the same
as far as possible, even though it's ugly, to avoid breaking clients.
(update_policy, adj_update, update_times, hourslop, blitz_time):
econfig keys removed.
(update_demand, UPD_DEMAND_NONE, UPD_DEMAND_SCHED, UPD_DEMAND_ASYNC)
(update_demandpolicy, UDP_NORMAL, UDP_TIMES, UDP_NORMAL, UDP_BLITZ)
(UDP_MAX, UDP_DEFAULT, UDDEM_TMCHECK, UDDEM_COMSET, UDDEM_DISABLE)
(UDDEM_MAX, UDDEM_DEFAULT): econfig key and values replaced.  Users
changed.  wantupd.h is now empty, remove.
(demand_check): External linkage.
(update_policy_check): Now pointless, remove.
(is_daytime_near, min_to_next_daytime, regular_update_time)
(scheduled_update_time, next_scheduled_time, updatetime)
(next_update_time, next_update_check_time): Unused, Remove.

(demand_check, demandupdatecheck): Move call of demand_update_time()
from demand_check(), which controls all demand updates, to
demandupdatecheck(), which controls only unscheduled ones.  Fixes
update command not to lie about the next scheduled demand update.

(demandupdatecheck): Check updates_disabled() so that zdone no longer
claims to trigger an update when it can't.
2007-07-11 22:27:29 +00:00
84cfd670ce 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.
2007-01-20 20:40:52 +00:00
861112f827 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.
2007-01-19 06:46:10 +00:00
f41e44fb74 (market_init): New.
(start_server): Call it.  Move initialization stuff to it, with error
checking added.
(market_update): Internal linkage.
2007-01-16 20:22:06 +00:00
02584d8a50 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.
2007-01-16 20:06:27 +00:00
d38fcc6cf4 (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.
2007-01-16 19:26:31 +00:00
6cbdd3e02a 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.
2007-01-15 19:57:26 +00:00
63bdc89835 Update copyright notice. 2007-01-09 19:09:31 +00:00
8e8c6fb891 (shutdown_init): Has no effect, remove. 2006-12-31 17:05:57 +00:00
e42053d928 Break inclusion cycle: prototypes.h and commands.h included each
other.  Ensure headers in include/ can be included in any order
(except for econfig-spec.h, which is special).  New header types.h to
help avoid inclusion cycles.  Sort include directives.  Remove some
superflous includes.
2006-07-10 06:37:23 +00:00
4515b84c59 COPYING duplicates information from README. Remove. Move GPL from
LICENSE to COPYING, because that's where it usually is.  Update all
the references to these files.
2006-01-21 19:48:41 +00:00
3e400c018c Update copyright notice. 2006-01-05 13:36:57 +00:00
Ron Koenderink
ef0dbf6790 (force): Change to create update thread instead of calling
empth_sleep() as the empth_sleep() can not be aborted for an update.
(update_force): New.
2005-08-20 19:16:56 +00:00
345ad3dfe0 Update copyright notice. 2005-03-16 22:03:16 +00:00
fac342ed49 Update copyright notice. 2004-09-07 15:07:16 +00:00
aafc693026 Remove junk at end of #endif. 2004-02-24 18:26:34 +00:00
c1be5d8657 Don't declare things in more than one place. Move some declarations
between headers.  Code is now fully prototyped and compiles cleanly
with gcc -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs
-Wredundant-decls.  Closes #723788.
2004-02-20 20:45:18 +00:00
22a356b1e1 New server.h for server startup, control and shutdown, i.e. stuff in
src/server.  Use it.
2004-02-19 19:02:30 +00:00