18
19
#include <signal.h>
19
20
#include <ecl/ecl.h>
20
21
#include <ecl/internal.h>
22
#ifdef HAVE_SCHED_YIELD
23
27
* We have to put this explicit definition here because Boehm GC
24
28
* is designed to produce a DLL and we rather want a static
28
33
extern HANDLE WINAPI GC_CreateThread(
29
34
LPSECURITY_ATTRIBUTES lpThreadAttributes,
30
35
DWORD dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress,
31
36
LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId );
33
37
#ifndef WITH___THREAD
306
@(defun mp::make-lock (&key name)
321
@(defun mp::make-lock (&key name ((:recursive recursive) Ct))
307
322
cl_object output;
309
324
output = cl_alloc_object(t_lock);
310
325
output->lock.name = name;
311
326
output->lock.mutex = CreateMutex(NULL, FALSE, NULL);
327
output->lock.holder = Cnil;
328
output->lock.counter = 0;
329
output->lock.recursive = (recursive != Cnil);
312
330
si_set_finalizer(output, Ct);
335
mp_recursive_lock_p(cl_object lock)
337
if (type_of(lock) != t_lock)
338
FEwrong_type_argument(@'mp::lock', lock);
339
@(return (lock->lock.recursive? Ct : Cnil))
343
mp_lock_name(cl_object lock)
345
if (type_of(lock) != t_lock)
346
FEwrong_type_argument(@'mp::lock', lock);
347
@(return lock->lock.name)
351
mp_lock_holder(cl_object lock)
353
if (type_of(lock) != t_lock)
354
FEwrong_type_argument(@'mp::lock', lock);
355
@(return lock->lock.holder)
317
359
mp_giveup_lock(cl_object lock)
319
361
if (type_of(lock) != t_lock)
320
362
FEwrong_type_argument(@'mp::lock', lock);
321
if (ReleaseMutex(lock->lock.mutex) == 0)
363
if (lock->lock.holder != cl_env.own_process) {
364
FEerror("Attempt to give up a lock ~S that is not owned by ~S.", 2,
365
lock, cl_env.own_process);
367
if (--lock->lock.counter == 0) {
368
lock->lock.holder = Cnil;
370
if (ReleaseMutex(lock->lock.mutex) == 0)
322
371
FEwin32_error("Unable to release Win32 Mutex", 0);
329
378
if (type_of(lock) != t_lock)
330
379
FEwrong_type_argument(@'mp::lock', lock);
380
/* In Windows, all locks are recursive. We simulate the other case. */
381
if (!lock->lock.recursive && (lock->lock.holder == cl_env.own_process)) {
382
FEerror("A recursive attempt was made to hold lock ~S", 1, lock);
331
384
switch (WaitForSingleObject(lock->lock.mutex, (wait==Ct?INFINITE:0))) {
332
385
case WAIT_OBJECT_0:
386
lock->lock.holder = cl_env.own_process;
387
lock->lock.counter++;
335
390
case WAIT_TIMEOUT:
403
/*----------------------------------------------------------------------
404
* CONDITION VARIABLES
408
mp_make_condition_variable(void)
410
FEerror("Condition variables are not supported under Windows.", 0);
415
mp_condition_variable_wait(cl_object cv, cl_object lock)
417
if (type_of(cv) != t_condition_variable)
418
FEwrong_type_argument(@'mp::condition-variable', cv);
419
if (type_of(lock) != t_lock)
420
FEwrong_type_argument(@'mp::lock', lock);
421
FEerror("Condition variables are not supported under Windows.", 0);
426
mp_condition_variable_timedwait(cl_object cv, cl_object lock, cl_object seconds)
428
if (type_of(cv) != t_condition_variable)
429
FEwrong_type_argument(@'mp::condition-variable', cv);
430
if (type_of(lock) != t_lock)
431
FEwrong_type_argument(@'mp::lock', lock);
432
FEerror("Condition variables are not supported under Windows.", 0);
437
mp_condition_variable_signal(cl_object cv)
439
if (type_of(cv) != t_condition_variable)
440
FEwrong_type_argument(@'mp::condition-variable', cv);
441
FEerror("Condition variables are not supported under Windows.", 0);
446
mp_condition_variable_broadcast(cl_object cv)
448
if (type_of(cv) != t_condition_variable)
449
FEwrong_type_argument(@'mp::condition-variable', cv);
450
FEerror("Condition variables are not supported under Windows.", 0);
454
/*----------------------------------------------------------------------