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.
This commit is contained in:
parent
c1eb1bd5d2
commit
c69cf0d1fd
7 changed files with 0 additions and 286 deletions
|
@ -71,9 +71,6 @@ enum {
|
||||||
/* empth_t * represents a thread. */
|
/* empth_t * represents a thread. */
|
||||||
typedef struct lwpProc empth_t;
|
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 */
|
/* empth_rwlock_t * represents a read-write lock */
|
||||||
typedef struct lwp_rwlock empth_rwlock_t;
|
typedef struct lwp_rwlock empth_rwlock_t;
|
||||||
|
|
||||||
|
@ -97,7 +94,6 @@ typedef struct lwp_rwlock empth_rwlock_t;
|
||||||
#define EMPTH_STACKCHECK 0x2
|
#define EMPTH_STACKCHECK 0x2
|
||||||
|
|
||||||
typedef struct empth_t empth_t;
|
typedef struct empth_t empth_t;
|
||||||
typedef struct empth_sem_t empth_sem_t;
|
|
||||||
typedef struct empth_rwlock_t empth_rwlock_t;
|
typedef struct empth_rwlock_t empth_rwlock_t;
|
||||||
|
|
||||||
#endif /* EMPTH_POSIX */
|
#endif /* EMPTH_POSIX */
|
||||||
|
@ -111,7 +107,6 @@ typedef struct empth_rwlock_t empth_rwlock_t;
|
||||||
#define EMPTH_STACKCHECK 0x2
|
#define EMPTH_STACKCHECK 0x2
|
||||||
|
|
||||||
typedef struct loc_Thread empth_t;
|
typedef struct loc_Thread empth_t;
|
||||||
typedef struct loc_Sem empth_sem_t;
|
|
||||||
typedef struct loc_RWLock empth_rwlock_t;
|
typedef struct loc_RWLock empth_rwlock_t;
|
||||||
|
|
||||||
void empth_request_shutdown(void);
|
void empth_request_shutdown(void);
|
||||||
|
@ -199,33 +194,6 @@ int empth_sleep(time_t until);
|
||||||
*/
|
*/
|
||||||
int empth_wait_for_signal(void);
|
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.
|
* Create a read-write lock.
|
||||||
* NAME is its name, it is used for debugging.
|
* NAME is its name, it is used for debugging.
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
#define LWP_PRINT 0x2
|
#define LWP_PRINT 0x2
|
||||||
|
|
||||||
struct lwpProc;
|
struct lwpProc;
|
||||||
struct lwpSem;
|
|
||||||
struct lwp_rwlock;
|
struct lwp_rwlock;
|
||||||
|
|
||||||
#define LWP_FD_READ 0x1
|
#define LWP_FD_READ 0x1
|
||||||
|
@ -54,10 +53,6 @@ void *lwpGetUD(struct lwpProc * p);
|
||||||
void lwpSetUD(struct lwpProc * p, char *ud);
|
void lwpSetUD(struct lwpProc * p, char *ud);
|
||||||
int lwpSetPriority(int prio);
|
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 *);
|
struct lwp_rwlock *lwp_rwlock_create(char *);
|
||||||
void lwp_rwlock_destroy(struct lwp_rwlock *);
|
void lwp_rwlock_destroy(struct lwp_rwlock *);
|
||||||
void lwp_rwlock_wrlock(struct lwp_rwlock *);
|
void lwp_rwlock_wrlock(struct lwp_rwlock *);
|
||||||
|
|
|
@ -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_t *
|
||||||
empth_rwlock_create(char *name)
|
empth_rwlock_create(char *name)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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
|
* loc_RWLock
|
||||||
*
|
*
|
||||||
|
@ -640,66 +625,6 @@ empth_wait_for_signal(void)
|
||||||
return 0;
|
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_t *
|
||||||
empth_rwlock_create(char *name)
|
empth_rwlock_create(char *name)
|
||||||
{
|
{
|
||||||
|
|
|
@ -68,14 +68,6 @@ struct empth_t {
|
||||||
pthread_t id; /* thread id */
|
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 {
|
struct empth_rwlock_t {
|
||||||
char *name;
|
char *name;
|
||||||
pthread_rwlock_t lock;
|
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_t *
|
||||||
empth_rwlock_create(char *name)
|
empth_rwlock_create(char *name)
|
||||||
{
|
{
|
||||||
|
|
|
@ -74,13 +74,6 @@ struct lwpQueue {
|
||||||
struct lwpProc *tail;
|
struct lwpProc *tail;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* semaphore */
|
|
||||||
struct lwpSem {
|
|
||||||
int count;
|
|
||||||
struct lwpQueue q;
|
|
||||||
char *name;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define LWP_REDZONE 1024 /* make this a multiple of 1024 */
|
#define LWP_REDZONE 1024 /* make this a multiple of 1024 */
|
||||||
|
|
||||||
/* XXX Note that this assumes sizeof(int) == 4 */
|
/* XXX Note that this assumes sizeof(int) == 4 */
|
||||||
|
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue