/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
#include <time.h>
-/* thread priorities */
-enum {
- PP_MAIN = 7,
- PP_UPDATE = 6,
- PP_SHUTDOWN = 5,
- PP_SCHED = 4,
- PP_TIMESTAMP = 2,
- PP_PLAYER = 3,
- PP_ACCEPT = 3,
- PP_KILLIDLE = 2
-};
-
#ifdef EMPTH_LWP
#include "lwp.h"
/* empth_t * represents a thread. */
typedef struct lwpProc empth_t;
-/* empth_sem_t * represents a semaphore */
-typedef struct lwpSem empth_sem_t;
-
/* empth_rwlock_t * represents a read-write lock */
typedef struct lwp_rwlock empth_rwlock_t;
#define EMPTH_STACKCHECK 0x2
typedef struct empth_t empth_t;
-typedef struct empth_sem_t empth_sem_t;
typedef struct empth_rwlock_t empth_rwlock_t;
#endif /* EMPTH_POSIX */
#define EMPTH_STACKCHECK 0x2
typedef struct loc_Thread empth_t;
-typedef struct loc_Sem_t empth_sem_t;
-typedef struct loc_RWLock_t empth_rwlock_t;
+typedef struct loc_RWLock empth_rwlock_t;
void empth_request_shutdown(void);
#endif /* EMPTH_W32 */
/*
* Create a new thread.
- * PRIO is the scheduling priority.
* ENTRY is the entry point. It will be called with argument UD.
* Thread stack is at least SIZE bytes.
* FLAGS should be the same as were passed to empth_init(), or zero.
- * NAME is the threads name, and DESC its description. These are used
- * for logging and debugging.
+ * NAME is the thread's name, it is used for logging and debugging.
* UD is the value to pass to ENTRY. It is also assigned to the
* context variable defined with empth_init() whenever the thread gets
* scheduled.
* Yield the processor.
* Return the thread, or NULL on error.
*/
-empth_t *empth_create(int prio, void (*entry)(void *),
- int size, int flags, char *name, char *desc, void *ud);
+empth_t *empth_create(void (*entry)(void *),
+ int size, int flags, char *name, void *ud);
/*
* Return the current thread.
* 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);
void empth_select(int fd, int flags);
/*
- * Awaken THREAD if it is sleeping in empth_select().
+ * Awaken THREAD if it is sleeping in empth_select() or empth_sleep().
* Note: This must not awaken threads sleeping in other functions.
+ * Does not yield the processor.
*/
void empth_wakeup(empth_t *thread);
/*
* Put current thread to sleep until the time is UNTIL.
- * May sleep somehwat longer, but never shorter.
+ * Return 0 if it slept until that time.
+ * Return -1 if woken up early, by empth_wakeup().
*/
-void empth_sleep(time_t until);
+int empth_sleep(time_t until);
/*
- * Wait for signal, return the signal number
+ * Wait for signal, return the signal number.
*/
int empth_wait_for_signal(void);
-/*
- * Create a semaphore.
- * NAME is its name, it is used for debugging.
- * COUNT is the initial count value of the semaphore, it must not be
- * negative.
- * Return the semaphore, or NULL on error.
- */
-empth_sem_t *empth_sem_create(char *name, int count);
-
-/*
- * Signal SEM.
- * Increase SEM's count. If threads are sleeping on it, wake up
- * exactly one of them. If that thread has a higher priority, yield
- * the processor.
- * This semaphore operation is often called `down' or `V' otherwhere.
- */
-void empth_sem_signal(empth_sem_t *sem);
-
-/*
- * Wait for SEM.
- * If SEM has a zero count, put current thread to sleep until
- * empth_sem_signal() awakens it. SEM will have non-zero value then.
- * Decrement SEM's count.
- * This semaphore operation is often called `up' or `P' otherwhere.
- */
-void empth_sem_wait(empth_sem_t *sem);
-
/*
* Create a read-write lock.
* NAME is its name, it is used for debugging.