]> git.pond.sub.org Git - empserver/commitdiff
Semaphores are no longer used, remove:
authorMarkus Armbruster <armbru@pond.sub.org>
Thu, 8 Feb 2007 12:29:16 +0000 (12:29 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Thu, 8 Feb 2007 12:29:16 +0000 (12:29 +0000)
(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.

include/empthread.h
include/lwp.h
src/lib/empthread/lwp.c
src/lib/empthread/ntthread.c
src/lib/empthread/pthread.c
src/lib/lwp/lwpint.h
src/lib/lwp/sem.c [deleted file]

index ea8ab88bc42ccf228ba773e006cf490115803614..0bb46bf93783e0df867dea6edc116fe205515e57 100644 (file)
@@ -71,9 +71,6 @@ enum {
 /* 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;
 
@@ -97,7 +94,6 @@ 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 */
@@ -111,7 +107,6 @@ typedef struct empth_rwlock_t empth_rwlock_t;
 #define EMPTH_STACKCHECK  0x2
 
 typedef struct loc_Thread empth_t;
-typedef struct loc_Sem empth_sem_t;
 typedef struct loc_RWLock empth_rwlock_t;
 
 void empth_request_shutdown(void);
@@ -199,33 +194,6 @@ int empth_sleep(time_t until);
  */
 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.
index 954ed689f8ed92e7eaba17c4d2bf95839a9489e8..c106dd913aee9dd6aca64adbbdf7afc56d6a75f2 100644 (file)
@@ -31,7 +31,6 @@
 #define LWP_PRINT      0x2
 
 struct lwpProc;
-struct lwpSem;
 struct lwp_rwlock;
 
 #define LWP_FD_READ    0x1
@@ -54,10 +53,6 @@ void *lwpGetUD(struct lwpProc * p);
 void lwpSetUD(struct lwpProc * p, char *ud);
 int lwpSetPriority(int prio);
 
-struct lwpSem *lwpCreateSem(char *name, int count);
-void lwpSignal(struct lwpSem *);
-void lwpWait(struct lwpSem *);
-
 struct lwp_rwlock *lwp_rwlock_create(char *);
 void lwp_rwlock_destroy(struct lwp_rwlock *);
 void lwp_rwlock_wrlock(struct lwp_rwlock *);
index bfafbbe45f56624fb3cf40a0f50aa1e0ceb969b6..c8d1d0a7efa8620aa36809940a5eba506875e40c 100644 (file)
@@ -132,24 +132,6 @@ empth_wait_for_signal(void)
     }
 }
 
-empth_sem_t *
-empth_sem_create(char *name, int cnt)
-{
-    return lwpCreateSem(name, cnt);
-}
-
-void
-empth_sem_signal(empth_sem_t *sm)
-{
-    lwpSignal(sm);
-}
-
-void
-empth_sem_wait(empth_sem_t *sm)
-{
-    lwpWait(sm);
-}
-
 empth_rwlock_t *
 empth_rwlock_create(char *name)
 {
index 0073cd283a2d4a2ee7c9965e26e3261135185a49..87a135f0080cc7b9d1f24a5a61f7ef857e13a86a 100644 (file)
@@ -90,21 +90,6 @@ struct loc_Thread {
 };
 
 
-/************************
- * loc_Sem
- */
-struct loc_Sem {
-
-    /* The semaphore name, passed in at create time. */
-    char szName[17];
-
-    /* An Event that the thread(s) will sleep on. */
-    HANDLE hEvent;
-
-    /* The count variable */
-    int count;
-};
-
 /************************
  * loc_RWLock
  *
@@ -640,66 +625,6 @@ empth_wait_for_signal(void)
     return 0;
 }
 
-/************************
- * empth_sem_create
- *
- * Create a signalling semaphore.
- */
-empth_sem_t *
-empth_sem_create(char *name, int cnt)
-{
-    empth_sem_t *pSem;
-
-    pSem = malloc(sizeof(*pSem));
-    if (!pSem) {
-       logerror("out of memory at %s:%d", __FILE__, __LINE__);
-       return NULL;
-    }
-
-    memset(pSem, 0, sizeof(pSem));
-    strncpy(pSem->szName, name, sizeof(pSem->szName) - 1);
-
-    pSem->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
-    pSem->count = cnt;
-
-    return pSem;
-}
-
-/************************
- * empth_sem_signal
- *
- * Hit/signal the specified semaphore.
- */
-void
-empth_sem_signal(empth_sem_t *pSem)
-{
-    loc_debug("signal on semaphore %s:%d", pSem->szName, pSem->count);
-
-    if (pSem->count++ < 0) {
-       SetEvent(pSem->hEvent);
-    }
-}
-
-/************************
- * empth_sem_wait
- *
- * Wait for the specified signal semaphore to be signaled.
- */
-void
-empth_sem_wait(empth_sem_t *pSem)
-{
-    empth_t *pThread = TlsGetValue(dwTLSIndex);
-
-    loc_debug("wait on semaphore %s:%d", pSem->szName, pSem->count);
-    if (--pSem->count < 0) {
-       /* Remove the thread from the running state. */
-       loc_BlockThisThread();
-       loc_debug("blocking");
-       loc_RunThisThread(pSem->hEvent);
-       loc_debug("waking up");
-    }
-}
-
 empth_rwlock_t *
 empth_rwlock_create(char *name)
 {
index 201f31085082efe470af95c42c3e02adc9d7c98c..9681b1abc906ed357e5d5d6059e19c5cd30c19f3 100644 (file)
@@ -68,14 +68,6 @@ struct empth_t {
     pthread_t id;              /* thread id */
 };
 
-struct empth_sem_t {
-    pthread_mutex_t mtx_update;        /* use it to update count */
-    int count;
-    char name[80];
-    pthread_mutex_t mtx_sem;
-    pthread_cond_t cnd_sem;
-};
-
 struct empth_rwlock_t {
     char *name;
     pthread_rwlock_t lock;
@@ -415,57 +407,6 @@ empth_wait_for_signal(void)
     }
 }
 
-empth_sem_t *
-empth_sem_create(char *name, int cnt)
-{
-    empth_sem_t *sm;
-
-    sm = malloc(sizeof(empth_sem_t));
-    if (!sm) {
-       logerror("out of memory at %s:%d", __FILE__, __LINE__);
-       return NULL;
-    }
-    strncpy(sm->name, name, sizeof(sm->name) - 1);
-    sm->count = cnt;
-    pthread_mutex_init(&sm->mtx_update, NULL);
-    pthread_mutex_init(&sm->mtx_sem, NULL);
-    pthread_cond_init(&sm->cnd_sem, NULL);
-    return sm;
-}
-
-void
-empth_sem_signal(empth_sem_t *sm)
-{
-    empth_status("signal on semaphore %s:%d", sm->name, sm->count);
-    pthread_mutex_lock(&sm->mtx_update);
-    if (sm->count++ < 0) {
-       pthread_mutex_unlock(&sm->mtx_update);
-       pthread_mutex_lock(&sm->mtx_sem);
-       pthread_cond_signal(&sm->cnd_sem);
-       pthread_mutex_unlock(&sm->mtx_sem);
-    } else
-       pthread_mutex_unlock(&sm->mtx_update);
-}
-
-void
-empth_sem_wait(empth_sem_t *sm)
-{
-    empth_status("wait on semaphore %s:%d", sm->name, sm->count);
-    pthread_mutex_lock(&sm->mtx_update);
-    if (--sm->count < 0) {
-       pthread_mutex_unlock(&sm->mtx_update);
-       empth_status("blocking");
-       pthread_mutex_unlock(&mtx_ctxsw);
-       pthread_mutex_lock(&sm->mtx_sem);
-       pthread_cond_wait(&sm->cnd_sem, &sm->mtx_sem);
-       empth_status("waking up");
-       pthread_mutex_unlock(&sm->mtx_sem);
-       pthread_mutex_lock(&mtx_ctxsw);
-       empth_restorectx();
-    } else
-       pthread_mutex_unlock(&sm->mtx_update);
-}
-
 empth_rwlock_t *
 empth_rwlock_create(char *name)
 {
index 12ce6ef7d1f3be1cc76ecf3d28899b4fd490d7f4..8795d0d2e10bfa6d7865388b71445c03f9986fbb 100644 (file)
@@ -74,13 +74,6 @@ struct lwpQueue {
     struct lwpProc *tail;
 };
 
-/* semaphore */
-struct lwpSem {
-    int count;
-    struct lwpQueue q;
-    char *name;
-};
-
 #define LWP_REDZONE    1024    /* make this a multiple of 1024 */
 
 /* XXX Note that this assumes sizeof(int) == 4 */
diff --git a/src/lib/lwp/sem.c b/src/lib/lwp/sem.c
deleted file mode 100644 (file)
index 4dd8b8d..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1994-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
- *  Copyright (C) 1991-3 Stephen Crane
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- *  ---
- *
- *  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.
- *
- *  ---
- *
- *  lwpSem.c: lwpSemaphore manipulation
- * 
- *  Known contributors to this file:
- *
- */
-
-#include <config.h>
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "lwp.h"
-#include "lwpint.h"
-
-/*
- * create a lwpSemaphore.
- */
-struct lwpSem *
-lwpCreateSem(char *name, int count)
-{
-    struct lwpSem *new;
-
-    if (!(new = malloc(sizeof(struct lwpSem))))
-       return 0;
-    new->name = strdup(name);
-    new->count = count;
-    new->q.head = new->q.tail = 0;
-    return new;
-}
-
-/*
- * signal a lwpSemaphore.  We only yield here if
- * the blocked process has a higher priority than ours'.
- */
-void
-lwpSignal(struct lwpSem *s)
-{
-    lwpStatus(LwpCurrent, "done with semaphore %s", s->name);
-    if (s->count++ < 0) {
-       struct lwpProc *p = lwpGetFirst(&s->q);
-       lwpStatus(LwpCurrent, "activating first waiter");
-       lwpReady(p);
-       if (LwpCurrent->pri < p->pri) {
-           lwpStatus(p, "priority is higher");
-           lwpYield();
-       }
-    }
-}
-
-/*
- * wait on a lwpSemaphore
- */
-void
-lwpWait(struct lwpSem *s)
-{
-    lwpStatus(LwpCurrent, "checking semaphore %s", s->name);
-    if (--s->count < 0) {
-       lwpStatus(LwpCurrent, "blocking");
-       lwpAddTail(&s->q, LwpCurrent);
-       lwpReschedule();
-    }
-}