From c69cf0d1fd583ad91462893c5c2e30b719f8e699 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 8 Feb 2007 12:29:16 +0000 Subject: [PATCH] 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. --- include/empthread.h | 32 ------------- include/lwp.h | 5 -- src/lib/empthread/lwp.c | 18 -------- src/lib/empthread/ntthread.c | 75 ------------------------------ src/lib/empthread/pthread.c | 59 ----------------------- src/lib/lwp/lwpint.h | 7 --- src/lib/lwp/sem.c | 90 ------------------------------------ 7 files changed, 286 deletions(-) delete mode 100644 src/lib/lwp/sem.c diff --git a/include/empthread.h b/include/empthread.h index ea8ab88bc..0bb46bf93 100644 --- a/include/empthread.h +++ b/include/empthread.h @@ -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. diff --git a/include/lwp.h b/include/lwp.h index 954ed689f..c106dd913 100644 --- a/include/lwp.h +++ b/include/lwp.h @@ -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 *); diff --git a/src/lib/empthread/lwp.c b/src/lib/empthread/lwp.c index bfafbbe45..c8d1d0a7e 100644 --- a/src/lib/empthread/lwp.c +++ b/src/lib/empthread/lwp.c @@ -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) { diff --git a/src/lib/empthread/ntthread.c b/src/lib/empthread/ntthread.c index 0073cd283..87a135f00 100644 --- a/src/lib/empthread/ntthread.c +++ b/src/lib/empthread/ntthread.c @@ -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) { diff --git a/src/lib/empthread/pthread.c b/src/lib/empthread/pthread.c index 201f31085..9681b1abc 100644 --- a/src/lib/empthread/pthread.c +++ b/src/lib/empthread/pthread.c @@ -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) { diff --git a/src/lib/lwp/lwpint.h b/src/lib/lwp/lwpint.h index 12ce6ef7d..8795d0d2e 100644 --- a/src/lib/lwp/lwpint.h +++ b/src/lib/lwp/lwpint.h @@ -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 index 4dd8b8d05..000000000 --- a/src/lib/lwp/sem.c +++ /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 - -#include -#include - -#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(); - } -} -- 2.43.0