]> git.pond.sub.org Git - empserver/blobdiff - src/lib/empthread/lwp.c
Update known contributors comments
[empserver] / src / lib / empthread / lwp.c
index 0663c5b937a0dd5a14519d65890c9a7a4612d7ab..5889c5f125d5c8503a08e43a30fa36f51e3daf24 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2005, 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
  *
  *  ---
  *
- *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- *  related information and legal notices. It is expected that any future
- *  projects/authors will amend these files as needed.
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
  *
  *  ---
  *
  *  lwp.c: Interface from Empire threads to LWP threads
- * 
+ *
  *  Known contributors to this file:
  *     Sasha Mikheev
+ *     Markus Armbruster, 2006-2009
  */
 
-#include <stdio.h>
-#include "prototypes.h"
-#include "empthread.h"
-
-#ifdef _EMPTH_LWP
+#include <config.h>
 
-/* The thread `created' by lwpInitSystem() */
-static empth_t *empth_main;
+#include <signal.h>
+#include <time.h>
+#include "empthread.h"
+#include "misc.h"
 
 /* Flags that were passed to empth_init() */
 static int empth_flags;
@@ -47,19 +46,26 @@ static int empth_flags;
 int
 empth_init(void **ctx, int flags)
 {
+    sigset_t set;
+
     empth_flags = flags;
-    empth_main = lwpInitSystem(PP_MAIN, (char **)ctx, flags);
+    empth_init_signals();
+    sigemptyset(&set);
+    sigaddset(&set, SIGHUP);
+    sigaddset(&set, SIGINT);
+    sigaddset(&set, SIGTERM);
+    lwpInitSystem(1, ctx, flags, &set);
     return 0;
 }
 
 
 empth_t *
-empth_create(int prio, void (*entry)(void *), int size, int flags,
-            char *name, char *desc, void *ud)
+empth_create(void (*entry)(void *), int size, int flags,
+            char *name, void *ud)
 {
     if (!flags)
        flags = empth_flags;
-    return lwpCreate(prio, entry, size, flags, name, desc, 0, 0, ud);
+    return lwpCreate(1, entry, size, flags, name, 0, NULL, ud);
 }
 
 empth_t *
@@ -68,19 +74,21 @@ empth_self(void)
     return LwpCurrent;
 }
 
+char *
+empth_name(empth_t *thread)
+{
+    return lwpName(thread);
+}
+
 void
-empth_exit(void)
+empth_set_name(empth_t *thread, char *name)
 {
-    time_t now;
+    lwpSetName(thread, name);
+}
 
-    /* We want to leave the main thread around forever, until it's time
-       for it to die for real (in a shutdown) */
-    if (LwpCurrent == empth_main) {
-       while (1) {
-           time(&now);
-           lwpSleepUntil(now + 60);
-       }
-    }
+void
+empth_exit(void)
+{
     lwpExit();
 }
 
@@ -90,47 +98,72 @@ empth_yield(void)
     lwpYield();
 }
 
-void
-empth_terminate(empth_t *a)
+int
+empth_select(int fd, int flags, struct timeval *timeout)
 {
-    lwpTerminate(a);
+    return lwpSleepFd(fd, flags, timeout);
 }
 
 void
-empth_select(int fd, int flags)
+empth_wakeup(empth_t *a)
 {
-    lwpSleepFd(fd, flags);
+    lwpWakeup(a);
 }
 
-void
-empth_wakeup(empth_t *a)
+int
+empth_sleep(time_t until)
 {
-    lwpWakeupFd(a);
+    return lwpSleepUntil(until);
 }
 
-void
-empth_sleep(time_t until)
+int
+empth_wait_for_signal(void)
 {
-    lwpSleepUntil(until);
+    sigset_t set;
+    int sig, err;
+    time_t now;
+
+    sigemptyset(&set);
+    sigaddset(&set, SIGHUP);
+    sigaddset(&set, SIGINT);
+    sigaddset(&set, SIGTERM);
+    for (;;) {
+       err = lwpSigWait(&set, &sig);
+       if (CANT_HAPPEN(err)) {
+           time(&now);
+           lwpSleepUntil(now + 60);
+           continue;
+       }
+       return sig;
+    }
 }
 
+empth_rwlock_t *
+empth_rwlock_create(char *name)
+{
+    return lwp_rwlock_create(name);
+}
 
-empth_sem_t *
-empth_sem_create(char *name, int cnt)
+void
+empth_rwlock_destroy(empth_rwlock_t *rwlock)
 {
-    return lwpCreateSem(name, cnt);
+    lwp_rwlock_destroy(rwlock);
 }
 
 void
-empth_sem_signal(empth_sem_t *sm)
+empth_rwlock_wrlock(empth_rwlock_t *rwlock)
 {
-    lwpSignal(sm);
+    lwp_rwlock_wrlock(rwlock);
 }
 
 void
-empth_sem_wait(empth_sem_t *sm)
+empth_rwlock_rdlock(empth_rwlock_t *rwlock)
 {
-    lwpWait(sm);
+    lwp_rwlock_rdlock(rwlock);
 }
 
-#endif
+void
+empth_rwlock_unlock(empth_rwlock_t *rwlock)
+{
+    lwp_rwlock_unlock(rwlock);
+}