Commit graph

50 commits

Author SHA1 Message Date
eea9e76bf8 Don't log out player when update aborts a command with pthreads
pthread.c's empth_select() returned -1 when empth_wakeup() interrupted
select().  The failure then got propagated all the way up, and the
player got logged out.  Fix by returning 0 in that case.  While there,
retry on EINTR, to match LWP.  Also clarify comments.
2009-03-01 13:04:48 +01:00
5073b022fd Remove unused empth_terminate()
Unused since 4.3.10.  Can be used safely only in very special
circumstances.

Removal allows simplifying pthread.c and ntthread.c some.  liblwp left
alone.
2009-03-01 10:49:48 +01:00
ee20a9cd34 Update known contributors comments 2009-02-18 21:11:33 +01:00
35ef345ecb Update copyright notice 2009-02-08 09:33:18 +01:00
Ron Koenderink
08b9455682 Reimplement max_idle without a separate thread
Remove the KillIdle thread.  Add timeout to struct iop, initialized in
io_open().  Obey it in io_input() by passing it to empth_select().  If
empth_select() times out, report that back through io_input() to
recvclient() and player_login().  If player_login() receives a timeout
indication, print a message and terminate the session.  If
recvclient() receives a timeout indication, flash a message to the
player and initiate a shut down the player's session.

Create WIN32 sys/time.h to define struct timeval.  This creates some
conflicts with WIN32 windows.h definitions.  Including windows.h in
show.c and info.c creates conflicts, so remove that.  Modify service.c
to include sys/socket.h instead of windows.h to remove the conflict
with sys/time.h.
2009-02-01 17:06:33 +01:00
d702068457 Fix trailing whitespace 2008-09-17 21:31:40 -04:00
db4770426e Update known contributors comments 2008-09-17 18:54:15 -04:00
d46b0b727d Make empth_name() and empth_set_name() take a thread argument 2008-09-11 19:25:34 -04:00
Ron Koenderink
2ddeda99d0 New empth_name() and empth_set_name() 2008-09-11 14:46:31 -06:00
2e5915dd09 Remove bogus comment from empthread.h
Became bogus in commit d500a707.
2008-09-11 07:51:09 -04:00
db02dda32f Update copyright notice 2008-01-19 10:15:37 +01:00
1be2d7be4c Comment. 2007-07-27 19:10:39 +00:00
d500a7071c Remove the concept of thread priorities from empthread.h. Only LWP
supports priorities.  Update synchronization used to rely on them,
which naturally worked only with LWP (#1504036).  With that fixed, no
uses of priorities remained, but a minor bug did: players could starve
out threads with priorities below PP_PLAYER, i.e. delete_lostitems()
and player_kill_idle().  Closes #1458175:
(empth_create): Remove parameter prio.  Callers changed.  Also gets
rid of misleading comments in pthread.c and ntthread.c.
(PP_MAIN, PP_UPDATE, PP_SHUTDOWN, PP_SCHED, PP_TIMESTAMP, PP_PLAYER)
(PP_ACCEPT, PP_KILLIDLE): Remove.
(empth_init, empth_create) [EMPTH_LWP]: Pass priority 1.
2007-07-24 05:13:31 +00:00
c69cf0d1fd Semaphores are no longer used, remove:
(empth_sem_t, empth_sem_create, empth_sem_signal, empth_sem_wait):
Remove.
[EMPTH_LWP] (lwpSem, lwpCreateSem, lwpSignal, lwpWait): Remove.
[EMPTH_W32] (loc_sem): Remove.
2007-02-08 12:29:16 +00:00
cea39829af 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.
2007-02-08 11:26:43 +00:00
d0ab92b944 (lwpSetDesc): Unused, remove.
[EMPTH_LWP] (lwpProc): Remove member desc.
[EMPTH_LWP] (lwpCreate, lwpDestroy): Don't initialize / finalize it.

[EMPTH_POSIX] (empth_t): Remove member desc.
[EMPTH_POSIX] (empth_init, empth_create): Don't initialize it.

[EMPTH_W32] (loc_Thread): Remove member szDesc.
[EMPTH_W32] (empth_init, empth_create): Don't initialize it.

(empth_create, lwpCreate): Remove parameter desc.  Callers changed.
2007-01-28 16:40:27 +00:00
Ron Koenderink
68662df96a (struct loc_RWLock_t): Rename struct loc_RWLock_t to struct loc_RWLock
as the struct loc_RWLock_t is not a typedef.  No functional changes.
2007-01-18 01:22:32 +00:00
Ron Koenderink
c4cf0231ee (struct loc_Sem_t): Rename struct loc_Sem_t to struct loc_Sem
as the struct loc_Sem_t is not a typedef.  No functional changes.
2007-01-18 01:18:19 +00:00
Ron Koenderink
d6efd51b09 (struct loc_Thread_t): Rename struct loc_Thread_t to struct loc_Thread
as the struct loc_Thread_t is not a typedef.  No functional changes.
2007-01-18 01:12:43 +00:00
Ron Koenderink
71e0f98825 (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.

(empth_rwlock_t, empth_rwlock_create, empth_rwlock_destroy)
(empth_rwlock_wrlock, empth_rwlock_rdlock, empth_rwlock_unlock): New.

(empth_rwlock_t, empth_rwlock_create, empth_rwlock_destroy)
(empth_rwlock_wrlock, empth_rwlock_rdlock, empth_rwlock_unlock)
[EMPTH_W32]: WIN32 implementation.

(empth_rwlock_t, empth_rwlock_create, empth_rwlock_destroy)
(empth_rwlock_wrlock, empth_rwlock_rdlock, empth_rwlock_unlock)
(lwp_rwlock, lwp_rwlock_create, lwp_rwlock_destroy)
(lwp_rwlock_wrlock, lwp_rwlock_rdlock, lwp_rwlock_unlock)
[EMPTH_LWP]: LWP implementation.

(empth_rwlock_t, empth_rwlock_create, empth_rwlock_destroy)
(empth_rwlock_wrlock, empth_rwlock_rdlock, empth_rwlock_unlock)
[EMPTH_POSIX]: pthread implementation.
2007-01-15 12:45:35 +00:00
63bdc89835 Update copyright notice. 2007-01-09 19:09:31 +00:00
f4667a9457 Include pthread.h in the implementation instead of the header. 2006-12-26 16:52:11 +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
0a50a48141 Update known contributors comment. 2006-06-22 20:27:36 +00:00
1ca0b5cb2b Finally merge the journal patch:
(keep_journal): New econfig key.
(player_main): Log player login and logout.
(recvclient): Log player input.
(ef_open_srv, ef_close_srv): Log startup and shutdown.
(update_main): Log update.

Support the common SIGHUP log rotation idiom:
(empth_wait_for_shutdown, empth_wait_for_signal): Rename.
[EMPTH_LWP, EMPTH_POSIX] (empth_init, empth_wait_for_signal): Wait for
SIGHUP as well.
(main) [SIGHUP]: Reopen journal when empth_wait_for_signal() returns
SIGHUP.
2006-06-08 20:11:26 +00:00
7183516d91 (empth_init_signals): Don't catch SIGINT and SIGTERM.
(empth_wait_for_shutdown): New.
(main): Use it to wait for shutdown signal, then shut down.  Closes
#770492.
(empth_exit): Remove the weird special case for main thread.

Implement empth_wait_for_shutdown() for EMPTH_LWP:
[EMPTH_LWP] (lwpInitSigWait, lwpSigWait, lwpSigWakeup): New.
Declaration of lwpSigWait was accidentally committed in the previous
revision of lwp.h.
[EMPTH_LWP] (lwpInitSystem): New parameter waitset, pass it on to
lwpInitSigWait().
[EMPTH_LWP] (lwpReschedule): Call lwpSigWakeup().
[EMPTH_LWP] (empth_init): Declare signals needed by
empth_wait_for_shutdown().
(empth_wait_for_shutdown): Implement on top of lwpSigWait().

Implement empth_wait_for_shutdown() for EMPTH_POSIX:
[EMPTH_POSIX] (empth_init): Block signals, so that
empth_wait_for_shutdown() can use sigwait() safely.
(empth_wait_for_shutdown): Implement on top of sigwait().

Implement empth_wait_for_shutdown() for EMPTH_W32:
(empth_wait_for_shutdown): Implement on top of loc_BlockMainThread().
2006-06-07 21:01:16 +00:00
32e4fbd284 Move signal stuff into src/lib/empthread/, no functional change:
(empth_init_signals): New, factored out of start_server().  Call from
empth_init().
(panic): Move to posix.c, internal linkage.
(empth_obj): Add new posix.o

(empth_start, empth_alarm) [EMPTH_POSIX]: Clean up pointless messing
with signal handlers.
(empth_init, empth_wakeup) [EMPTH_POSIX]: Clean up a bit.
2006-06-05 08:51:02 +00:00
ba11aaaa36 (empth_create): LWP yields, and it's the reference implementation.
Document and fix the others.
2006-03-25 07:49:37 +00:00
f5a9284867 Update known contributors comment. 2006-02-24 21:35:27 +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
fa52e6944d Normalize inclusion guards: use NAME_H for name.h. Some headers
lacked them, others used reserved identifiers.
2005-12-29 10:16:01 +00:00
3b90d0cb81 (PP_MAIN, PP_UPDATE, PP_SHUTDOWN, PP_SCHED, PP_TIMESTAMP, PP_PLAYER)
(PP_ACCEPT, PP_KILLIDLE): Move from player.h to empthread.h and turn
into enumeration constants.
2005-12-28 21:21:15 +00:00
69150d10fc (EMPTH_LWP, EMPTH_POSIX, EMPTH_W32): Define in config.h instead of
compiler command line.  Don't bother to conditionalize code in .c
files that are only compiled when their thread package is used.

(_EMPTH_LWP, EMPTH_LWP, _EMPTH_POSIX, EMPTH_POSIX, _EMPTH_WIN32)
(EMPTH_W32): Identifiers beginning with an underscore and an uppercase
letter are reserved for any use.  Rename.
2005-12-28 14:27:15 +00:00
e6145fa515 (empth_start, empth_init) [_EMPTH_POSIX]: Do not handle SIGALRM. We
don't raise it, and the signal handler is fishy.
(empth_alarm): Unused, remove.
2005-10-26 16:30:00 +00:00
565faa8891 Cleanup, no functional change.
(empth_t, empth_sem_t): Define as incomplete types in empthread.h,
complete in pthread.c, to avoid exposing implementation details.

(EMPTH_KILLED): Move from empthread.h to pthread.c.
2005-07-23 17:40:49 +00:00
59c15ea9d4 [_DECTHREADS_] Drop support for DECthreads d4, a.k.a. DCE threads,
which are obsolete since at least 1997.

(empth_terminate, empth_wakeup) [__ppc__]: Ancient versions of OS X
lacked pthread_kill().  As a work-around, its use was disabled here
for all versions of OS X.  The work-around could lead to hangs.
Remove it and drop support for ancient versions of OS X.

(empth_create) [__linux__]: Linux has supported thread attribute
stacksize for ages.  Remove the special case.

(_MIT_POSIX_THREADS): Unused, remove.
2005-07-23 17:26:20 +00:00
d86c6e89ff Doc fix. 2005-07-01 19:51:48 +00:00
060df4ec8f Document Empire's thread abstraction. Minor cleanups:
(empth_init): Change first parameter to void **.
(empth_sleep): Change parameter to time_t.
2005-06-25 16:37:59 +00:00
345ad3dfe0 Update copyright notice. 2005-03-16 22:03:16 +00:00
Ron Koenderink
9227a314c5 (service_stoppped,stop_service,loc_Ctrl_C_Handler,
empth_request_shutdown,loc_BlockMainThread,empth_init,
service_ctrl_handler) [_WIN32]: Remove the Windows Build UI and
replace with Ctrl-c signal trap.  The shutdown event that was used for
STOPPING the service is now used for both foreground and background
(service) modes of operation. Also move the shutdown event from service
code to empth_t library.
2005-03-15 18:19:07 +00:00
afa65c8f27 Break inclusion cycles. To simplify the change, move a few
declarations to other, no less sensible places.
2005-02-12 19:26:59 +00:00
fac342ed49 Update copyright notice. 2004-09-07 15:07:16 +00:00
baabcc563e (empth_ctx_t): Unused, remove. 2004-08-28 12:49:13 +00:00
97843dfdf6 [_EMPTH_WIN32]: Previous rev. didn't even compile, fix. 2004-02-18 07:12:51 +00:00
e446bfd904 (empth_t, empth_sem_t) [_EMPTH_WIN32]: Use incomplete types, not void for
abstract data types.
2004-02-17 18:05:23 +00:00
237baffca9 Supply prototypes where possible. This uncovered type errors with
thread entrypoints:
(lwpSelect, shutdown_sequence): Parameters didn't match thread entry
point prototype.
(lwpEntryPoint): Arguments didn't match thread entry point prototype.

Change linkage of functions without prototype declaration to static
where possible.

Remove some superflous declarations, replace others by suitable
includes.
2004-02-17 17:59:30 +00:00
4fa84b5cb1 (emp_sig_t): Pre-ISO C compatibility cruft. Just use void. 2004-02-15 21:00:27 +00:00
9b7adfbecc Indented with src/scripts/indent-emp. 2003-09-02 20:48:48 +00:00
d8b7fdfae1 Import of Empire 4.2.12 2003-08-23 12:23:04 +00:00