Remove unused empth_terminate()

Unused since 4.3.10.  Can be used safely only in very special
circumstances.

Removal allows simplifying pthread.c and ntthread.c some.  liblwp left
alone.
This commit is contained in:
Markus Armbruster 2009-03-01 10:49:48 +01:00
parent 3e4894c7f5
commit 5073b022fd
4 changed files with 8 additions and 66 deletions

View file

@ -112,6 +112,7 @@ int empth_init(void **ctx, int flags);
/* /*
* Create a new thread. * Create a new thread.
* ENTRY is the entry point. It will be called with argument UD. * ENTRY is the entry point. It will be called with argument UD.
* If it returns, the thread terminates as if it called empth_exit().
* Thread stack is at least SIZE bytes. * Thread stack is at least SIZE bytes.
* FLAGS should be the same as were passed to empth_init(), or zero. * FLAGS should be the same as were passed to empth_init(), or zero.
* NAME is the thread's name, it is used for logging and debugging. * NAME is the thread's name, it is used for logging and debugging.
@ -153,17 +154,6 @@ void empth_exit(void);
*/ */
void empth_yield(void); void empth_yield(void);
/*
* Terminate THREAD.
* THREAD will not be scheduled again. Instead, it will terminate as
* 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);
/* /*
* Put current thread to sleep until file descriptor FD is ready for I/O. * Put current thread to sleep until file descriptor FD is ready for I/O.
* If FLAGS & EMPTH_FD_READ, wake up if FD is ready for input. * If FLAGS & EMPTH_FD_READ, wake up if FD is ready for input.

View file

@ -98,12 +98,6 @@ empth_yield(void)
lwpYield(); lwpYield();
} }
void
empth_terminate(empth_t *a)
{
lwpTerminate(a);
}
int int
empth_select(int fd, int flags, struct timeval *timeout) empth_select(int fd, int flags, struct timeval *timeout)
{ {

View file

@ -81,9 +81,6 @@ struct loc_Thread {
/* The user data passed in at create time. */ /* The user data passed in at create time. */
void *pvUserData; void *pvUserData;
/* True if this thread has been killed. */
BOOL bKilled;
/* The entry function for the thread. */ /* The entry function for the thread. */
void (*pfnEntry) (void *); void (*pfnEntry) (void *);
@ -245,14 +242,6 @@ loc_RunThisThread(HANDLE hWaitObject)
empth_t *pThread = TlsGetValue(dwTLSIndex); empth_t *pThread = TlsGetValue(dwTLSIndex);
if (pThread->bKilled) {
if (!pThread->bMainThread) {
TlsSetValue(dwTLSIndex, NULL);
loc_FreeThreadInfo(pThread);
_endthread();
}
}
hWaitObjects[0] = hThreadMutex; hWaitObjects[0] = hThreadMutex;
hWaitObjects[1] = hWaitObject; hWaitObjects[1] = hWaitObject;
@ -538,20 +527,6 @@ empth_yield(void)
loc_RunThisThread(NULL); loc_RunThisThread(NULL);
} }
/************************
* empth_terminate
*
* Kill off the thread.
*/
void
empth_terminate(empth_t *pThread)
{
loc_debug("killing thread %s", pThread->szName);
pThread->bKilled = TRUE;
SetEvent(pThread->hThreadEvent);
}
/************************ /************************
* empth_select * empth_select
* *

View file

@ -50,18 +50,14 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h> #include <unistd.h>
#include "misc.h" #include "misc.h"
#include "empthread.h" #include "empthread.h"
#include "prototypes.h" #include "prototypes.h"
#define EMPTH_KILLED 1
#define EMPTH_INTR 2
struct empth_t { struct empth_t {
char *name; /* thread name */ char *name; /* thread name */
void *ud; /* user data */ void *ud; /* user data */
int state; /* my state */ int wakeup;
void (*ep)(void *); /* entry point */ void (*ep)(void *); /* entry point */
pthread_t id; /* thread id */ pthread_t id; /* thread id */
}; };
@ -170,7 +166,7 @@ empth_init(void **ctx_ptr, int flags)
ctx->ep = 0; ctx->ep = 0;
ctx->ud = 0; ctx->ud = 0;
ctx->id = pthread_self(); ctx->id = pthread_self();
ctx->state = 0; ctx->wakeup = 0;
pthread_setspecific(ctx_key, ctx); pthread_setspecific(ctx_key, ctx);
pthread_mutex_lock(&mtx_ctxsw); pthread_mutex_lock(&mtx_ctxsw);
logerror("pthreads initialized"); logerror("pthreads initialized");
@ -196,7 +192,7 @@ empth_create(void (*entry)(void *), int size, int flags,
} }
ctx->name = strdup(name); ctx->name = strdup(name);
ctx->ud = ud; ctx->ud = ud;
ctx->state = 0; ctx->wakeup = 0;
ctx->ep = entry; ctx->ep = entry;
eno = pthread_attr_init(&attr); eno = pthread_attr_init(&attr);
@ -233,11 +229,7 @@ empth_restorectx(void)
ctx_ptr = pthread_getspecific(ctx_key); ctx_ptr = pthread_getspecific(ctx_key);
*udata = ctx_ptr->ud; *udata = ctx_ptr->ud;
if (ctx_ptr->state == EMPTH_KILLED) { ctx_ptr->wakeup = 0;
empth_status("i am dead");
empth_exit();
}
ctx_ptr->state = 0;
empth_status("context restored"); empth_status("context restored");
} }
@ -281,14 +273,6 @@ empth_yield(void)
empth_restorectx(); empth_restorectx();
} }
void
empth_terminate(empth_t *a)
{
empth_status("killing thread %s", a->name);
a->state = EMPTH_KILLED;
pthread_kill(a->id, SIGALRM);
}
int int
empth_select(int fd, int flags, struct timeval *timeout) empth_select(int fd, int flags, struct timeval *timeout)
{ {
@ -341,7 +325,7 @@ empth_alarm(int sig)
{ {
/* /*
* Nothing to do --- we handle this signal just to let * Nothing to do --- we handle this signal just to let
* empth_wakeup() and empth_terminate() interrupt system calls. * empth_wakeup() interrupt system calls.
*/ */
} }
@ -349,8 +333,7 @@ void
empth_wakeup(empth_t *a) empth_wakeup(empth_t *a)
{ {
empth_status("waking up thread %s", a->name); empth_status("waking up thread %s", a->name);
if (a->state == 0) a->wakeup = 1;
a->state = EMPTH_INTR;
pthread_kill(a->id, SIGALRM); pthread_kill(a->id, SIGALRM);
} }
@ -367,7 +350,7 @@ empth_sleep(time_t until)
tv.tv_sec = until - time(NULL); tv.tv_sec = until - time(NULL);
tv.tv_usec = 0; tv.tv_usec = 0;
res = select(0, NULL, NULL, NULL, &tv); res = select(0, NULL, NULL, NULL, &tv);
} while (res < 0 && ctx->state == 0); } while (res < 0 && !ctx->wakeup);
empth_status("sleep done. Waiting for lock"); empth_status("sleep done. Waiting for lock");
pthread_mutex_lock(&mtx_ctxsw); pthread_mutex_lock(&mtx_ctxsw);
empth_restorectx(); empth_restorectx();