]> git.pond.sub.org Git - empserver/blobdiff - include/empthread.h
Update known contributors comments
[empserver] / include / empthread.h
index 239824e887891d421d94270d1760348a1db9ec48..1dbed07bddbfc8bde67cead5ae748f43bef02b3b 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  *  ---
  *
  *  empthread.h: Definitions for Empire threading
- * 
+ *
  *  Known contributors to this file:
  *     Sasha Mikheev
  *     Doug Hay, 1998
  *     Steve McClure, 1998
- *     Markus Armbruster, 2005-2007
+ *     Markus Armbruster, 2005-2009
+ *     Ron Koenderink, 2005-2009
  */
 
 /*
@@ -47,6 +48,7 @@
 #ifndef EMPTHREAD_H
 #define EMPTHREAD_H
 
+#include <sys/time.h>
 #include <time.h>
 
 #ifdef EMPTH_LWP
 
 /* Abstract data types */
 
-/* empth_t * represents a thread.  */
+/* A thread.  */
 typedef struct lwpProc empth_t;
 
-/* empth_rwlock_t * represents a read-write lock */
+/* A read-write lock, perferring writers */
 typedef struct lwp_rwlock empth_rwlock_t;
 
 /* Flags for empth_select(): whether to sleep on input or output */
@@ -110,6 +112,7 @@ int empth_init(void **ctx, int flags);
 /*
  * Create a new thread.
  * ENTRY is the entry point.  It will be called with argument UD.
+ * If it returns, the thread terminates as if it called empth_exit().
  * Thread stack is at least SIZE bytes.
  * FLAGS should be the same as were passed to empth_init(), or zero.
  * NAME is the thread's name, it is used for logging and debugging.
@@ -128,14 +131,14 @@ empth_t *empth_create(void (*entry)(void *),
 empth_t *empth_self(void);
 
 /*
- * Return the name of the current thread.
+ * Return the name THREAD.
  */
-char *empth_name(void);
+char *empth_name(empth_t *thread);
 
 /*
- * Sets the name of the current thread.
+ * Set the name of THREAD to NAME.
  */
-void empth_set_name(char *);
+void empth_set_name(empth_t *thread, char *name);
 
 /*
  * Terminate the current thread.
@@ -151,30 +154,22 @@ void empth_exit(void);
  */
 void empth_yield(void);
 
-/*
- * Terminate THREAD.
- * THREAD will not be scheduled again.  Instead, it will terminate as
- * if it executed empth_exit().  It is unspecified when exactly that
- * happens.
- * THREAD must not be the current thread.
- * Naive use of this function almost always leads to resource leaks.
- * Terminating a thread that may hold locks is not a good idea.
- */
-void empth_terminate(empth_t *thread);
-
 /*
  * Put current thread to sleep until file descriptor FD is ready for I/O.
  * If FLAGS & EMPTH_FD_READ, wake up if FD is ready for input.
  * If FLAGS & EMPTH_FD_WRITE, wake up if FD is ready for output.
  * At most one thread may sleep on the same file descriptor.
+ * TIMEOUT, if non-null, limits the sleep time.
+ * Return one when the FD is ready, zero on timeout or early wakeup by
+ * empth_wakeup(), -1 on error with errno set.
  * Note: Currently, Empire sleeps only on network I/O, i.e. FD is a
  * socket.  Implementations should not rely on that.
  */
-void empth_select(int fd, int flags);
+int empth_select(int fd, int flags, struct timeval *timeout);
 
 /*
  * Awaken THREAD if it is sleeping in empth_select() or empth_sleep().
- * Note: This must not awaken threads sleeping in other functions.
+ * This does not awaken threads sleeping in other functions.
  * Does not yield the processor.
  */
 void empth_wakeup(empth_t *thread);
@@ -194,7 +189,7 @@ int empth_wait_for_signal(void);
 /*
  * Create a read-write lock.
  * NAME is its name, it is used for debugging.
- * Return the reade-write lock, or NULL on error.
+ * Return the read-write lock, or NULL on error.
  */
 empth_rwlock_t *empth_rwlock_create(char *name);
 
@@ -214,9 +209,9 @@ void empth_rwlock_wrlock(empth_rwlock_t *rwlock);
 /*
  * Lock RWLOCK for reading.
  * A read-write lock can be locked for reading only when it is not
- * locked for writing.  If this is not the case, put the current
- * thread to sleep until it is.  Must not starve writers, and may
- * sleep to avoid that.
+ * locked for writing, and no other thread is attempting to lock it
+ * for writing.  If this is not the case, put the current thread to
+ * sleep until it is.
  */
 void empth_rwlock_rdlock(empth_rwlock_t *rwlock);