1998-01-15
1998-01-15 05:59:43 by Fredrik Hübinette (Hubbe) <hubbe@hubbe.net>
-
dc7cc90d1c9de64fbc7953a8a6ffce7c0740f712
(58 lines)
(+53/-5)
[
Show
| Annotate
]
Branch: 7.9
threads now works on NT
Rev: src/Makefile.in:1.51
Rev: src/builtin_functions.c:1.60
Rev: src/error.c:1.9
Rev: src/error.h:1.8
Rev: src/las.c:1.41
Rev: src/main.c:1.33
Rev: src/object.c:1.32
Rev: src/threads.c:1.52
Rev: src/threads.h:1.27
1:
#include "global.h"
- RCSID("$Id: threads.c,v 1.51 1998/01/13 22:56:51 hubbe Exp $");
+ RCSID("$Id: threads.c,v 1.52 1998/01/15 05:59:43 hubbe Exp $");
int num_threads = 1;
int threads_disabled = 0;
15:
#include "program.h"
#include "gc.h"
+ #ifdef __NT__
+
+ #ifdef DEBUG
+ static int IsValidHandle(HANDLE h)
+ {
+ __try {
+ HANDLE ret;
+ if(DuplicateHandle(GetCurrentProcess(),
+ h,
+ GetCurrentProcess(),
+ &ret,
+ NULL,
+ 0,
+ DUPLICATE_SAME_ACCESS))
+ {
+ CloseHandle(ret);
+ }
+ }
+
+ __except (1) {
+ return 0;
+ }
+
+ return 1;
+ }
+
+ void CheckValidHandle(HANDLE h)
+ {
+ if(!IsValidHandle((HANDLE)h))
+ fatal("Invalid handle!\n");
+ }
+
+ #endif
+
+ #endif
+
#ifdef SIMULATE_COND_WITH_EVENT
int co_wait(COND_T *c, MUTEX_T *m)
{
struct cond_t_queue me;
event_init(&me.event);
-
+ me.next=0;
mt_lock(& c->lock);
- me.next=c->tail;
+ if(c->tail)
+ {
+ c->tail->next=&me;
c->tail=&me;
- if(!c->head) c->head=&me;
+ }else{
+ c->head=c->tail=&me;
+ }
mt_unlock(& c->lock);
mt_unlock(m);
34: Inside #if defined(SIMULATE_COND_WITH_EVENT)
event_destroy(& me.event);
/* Cancellation point?? */
+ #ifdef DEBUG
+ if(me.next)
+ fatal("Wait on event return prematurely!!\n");
+ #endif
+
return 0;
}
41: Inside #if defined(SIMULATE_COND_WITH_EVENT)
{
struct cond_t_queue *t;
mt_lock(& c->lock);
- if(t=c->head)
+ if((t=c->head))
{
c->head=t->next;
t->next=0;
64: Inside #if defined(SIMULATE_COND_WITH_EVENT)
while((t=n))
{
n=t->next;
+ t->next=0;
event_signal(& t->event);
}