Commit graph

86 commits

Author SHA1 Message Date
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
48cec49fbf Fix empth_select() for funny flag arguments
EMPTH_POSIX and EMPTH_W32 implementations rejected values other than a
single flag.  Such values aren't used now, but it violates the
contract all the same.
2009-02-02 08:08:38 +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
Ron Koenderink
74b655f9fa Allow any length RW lock names for WIN32
Dynamically allocate the string space for RW
lock names for WIN32 (ntthread.c).  This
makes the WIN32 more consistent with the other
environments.
2008-09-13 16:39:45 -06:00
Ron Koenderink
838a1010c2 Allow any length thread names for WIN32
Dynamically allocate the string space for thread
name in WIN32 (ntthread.c) thread space.  This
makes the WIN32 more consistent with the other
environments.  It also addresses WIN32 issue of
the print width of 17 being used and only having
space for 16 characters in the fixed allocation.
2008-09-13 15:29:42 -06:00
Ron Koenderink
4d7d7bb77e Add missing error check for thread creation for WIN32
_beginthread() call in empth_create() has two error
return values 0L and 1L.  Add the missing check for 0L.
2008-09-12 07:22:28 -06:00
Ron Koenderink
af2a87e490 Ensure the empth_sleep() always yields for WIN32
The WIN32 version did not block when the sleep was
already reached by the time empth_sleep() did the
time remaining calculation.  The other versions
of empth_sleep() do always yield.
2008-09-12 07:22:28 -06: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
ed9da7cf06 Update known contributors comments 2008-08-03 08:04:08 -04:00
1d9aac2cf9 Add gcc attribute format where it's missing 2008-08-02 12:00:33 -04:00
Ron Koenderink
9a4f49f128 Add missing thread yield system call.
This change fixes a bug where the threads were not treated
fairly.  Before the fix, empth_yield would only yield to
threads already waiting hThreadMutex mutex.  It would not
yield to other threads ready to run from the release of other
mutexes.  An example of this is that the update task did
not start when force command was issued from script sequence.
2008-03-27 20:07:11 -06:00
db02dda32f Update copyright notice 2008-01-19 10:15:37 +01:00
Ron Koenderink
90a53439b2 (loc_Exit_Handler, empth_init) [_WIN32]: Correct the function declaration
for loc_Exit_Handler().  Remove unnecessary cast.
2007-11-27 03:29:35 +00:00
Ron Koenderink
c115ed1327 (random, srandom) [_WIN32]: Provide random and srandom
POSIX equivalents instead of using the WIN32 rand/srand functions.
The files were derived from GNU libc source.

(empth_threadMain) [_WIN32]: Remove the srandom() as the
POSIX equivalent are not thread specific as the WIN32 functions were.
2007-10-21 15:34:27 +00:00
Ron Koenderink
0627deae05 (empth_sleep) [_WIN32]: Remove a change to the random seeding
that accidently got committed in rev 1.65.  Was incorrect in rev 1.66.

(empth_sleep) [_WIN32]: Switch srand() to srandom() to be consistent
with the rest of the empire code.
2007-10-20 12:59:49 +00:00
Ron Koenderink
f449c3f8a4 (empth_sleep) [_WIN32]: Remove a change to the random seeding
that accidently got committed in rev 1.65.
2007-10-20 12:15:45 +00:00
Ron Koenderink
274c3d3a36 (empth_sleep) [_WIN32]: Ensure the thread does not waking up early.
It has been seen which caused an update to be missed.
2007-10-20 11:51:50 +00:00
Ron Koenderink
dbf7f554b1 (empth_sleep) [_WIN32]: Change if to while to ensure the time has
actually been reached.  There has been examples where the time
expired early by one second probably due a resolution error.  This
caused a scheduled update to be missed.  Broken in rev. 1.56.
2007-09-30 15:39:48 +00:00
Ron Koenderink
2e012c8fa3 (va_start) [_WIN32]: For va_start() requires stdarg.h. 2007-08-19 00:54:29 +00:00
Ron Koenderink
4bbc3f4286 Simple POSIX I/O emulation layer to work around Windows's defective
Unix I/O:
[_WIN32] (socklen_t, accept, posix_accept, bind. posix_bind, listen)
(posix_listen, setsockopt, posix_setsockopt, shutdown, posix_shutdown)
(socket, posix_socket, close, posix_close, creat, fstat, posix_fstat)
(lseek, posix_lseek, open, posix_open, read, posix_read, write)
(posix_write, fileno, posix_fileno, fcntl, O_NONBLOCK, F_RDLCK)
(F_WRLCK, F_GETFL, F_SETFL, F_SETLK, EWOULDBLOCK, ENOTSOCK)
(flock, fsync, posix_fsync):
New.
(ef_open, io_close, io_input, io_output, io_shutdown, io_noblocking)
(player_accept): Use them to simplify.
[_WIN32] (posix_fd2socket): New.
(empth_select): Use it.
(gen_power): Use it.
2007-08-14 03:33:28 +00:00
e09f50a7d3 (empth_wait_for_signal) [EMPTH_W32]: Fix to return SIGTERM. 2007-07-27 20:30:11 +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
Ron Koenderink
e19229ad98 (empth_create) [_WIN32]: Fix the error return code check for
the call to _beginthread() to check for 1L instead of -1.
2007-02-24 14:05:21 +00:00
Ron Koenderink
0978c0c4fc (accept.c, io.c, nthread.c, tcp_listen.c) [_WIN32,WIN32]:
Remove the define WIN32.
Not required for VC8.
2007-02-23 22:51:30 +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
71b46e770b (struct loc_Thread, empth_sem_wait, empth_sem_signal) [WIN32]:
Remove the semaphore mutex and replace with hThreadMutex instead
2007-01-18 14:28:23 +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
98250f2300 (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().
2007-01-18 01:05:19 +00:00
Ron Koenderink
0c52f203c0 (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.
2007-01-15 13:34:33 +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
Ron Koenderink
897c212bfa Add missing prototypes.h to get logerror(). 2006-07-11 22:06:03 +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
Ron Koenderink
0c53200e8e (empth_wait_for_signal) [_WIN32]: Add thread block for the main thread,
otherwise the main thread blocks all others.
2006-06-10 03:57:50 +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
0b1f561e97 Comments, whitespace. 2006-06-02 05:49:29 +00:00
f3e85c2f70 Coding style, comments, spelling... 2006-05-26 18:46:50 +00:00
4c4fdca42b Line breaks and other formatting issues. No functional changes. 2006-05-21 13:05:24 +00:00
e28851b8e9 Normalize unsigned int to just unsigned. 2006-04-30 12:26:07 +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