~ubuntu-branches/debian/sid/ocaml/sid

« back to all changes in this revision

Viewing changes to otherlibs/systhreads/win32.c

  • Committer: Bazaar Package Importer
  • Author(s): Stefano Zacchiroli
  • Date: 2009-02-22 08:49:13 UTC
  • mfrom: (12.1.1 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090222084913-3i0uw2bhd0lgw0ok
* Uploading to unstable
* debian/control: bump dh-ocaml to (>= 0.4) to avoid buggy ocamlinit.mk

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
/*                                                                     */
12
12
/***********************************************************************/
13
13
 
14
 
/* $Id: win32.c,v 1.44 2006/04/16 23:28:21 doligez Exp $ */
 
14
/* $Id: win32.c,v 1.45 2007/10/31 09:12:29 xleroy Exp $ */
15
15
 
16
16
/* Thread interface for Win32 threads */
17
17
 
227
227
    if (mutex == NULL) caml_wthread_error("Thread.iolock");
228
228
    chan->mutex = (void *) mutex;
229
229
  }
 
230
  /* PR#4351: first try to acquire mutex without releasing the master lock */
 
231
  if (WaitForSingleObject((HANDLE) chan->mutex, 0) == WAIT_OBJECT_0) {
 
232
    TlsSetValue(last_channel_locked_key, (void *) chan);
 
233
    return;
 
234
  }
230
235
  enter_blocking_section();
231
236
  WaitForSingleObject((HANDLE) chan->mutex, INFINITE);
232
237
  /* Problem: if a signal occurs at this point,
518
523
CAMLprim value caml_mutex_lock(value mut)
519
524
{
520
525
  int retcode;
 
526
  /* PR#4351: first try to acquire mutex without releasing the master lock */
 
527
  retcode =  WaitForSingleObject(Mutex_val(mut), 0);
 
528
  if (retcode == WAIT_OBJECT_0) return Val_unit;
521
529
  Begin_root(mut)               /* prevent deallocation of mutex */
522
530
    enter_blocking_section();
523
531
    retcode = WaitForSingleObject(Mutex_val(mut), INFINITE);
530
538
CAMLprim value caml_mutex_unlock(value mut)
531
539
{
532
540
  BOOL retcode;
533
 
  Begin_root(mut)               /* prevent deallocation of mutex */
534
 
    enter_blocking_section();
535
 
    retcode = ReleaseMutex(Mutex_val(mut));
536
 
    leave_blocking_section();
537
 
  End_roots();
 
541
  /* PR#4351: no need to release and reacquire master lock */
 
542
  retcode = ReleaseMutex(Mutex_val(mut));
538
543
  if (!retcode) caml_wthread_error("Mutex.unlock");
539
544
  return Val_unit;
540
545
}
630
635
 
631
636
  if (Condition_val(cond)->count > 0) {
632
637
    Condition_val(cond)->count --;
633
 
    Begin_root(cond)           /* prevent deallocation of cond */
634
 
      enter_blocking_section();
635
 
      /* Increment semaphore by 1, waking up one waiter */
636
 
      ReleaseSemaphore(s, 1, NULL);
637
 
      leave_blocking_section();
638
 
    End_roots();
 
638
    /* Increment semaphore by 1, waking up one waiter */
 
639
    ReleaseSemaphore(s, 1, NULL);
639
640
  }
640
641
  return Val_unit;
641
642
}
647
648
 
648
649
  if (c > 0) {
649
650
    Condition_val(cond)->count = 0;
650
 
    Begin_root(cond)           /* prevent deallocation of cond */
651
 
      enter_blocking_section();
652
 
      /* Increment semaphore by c, waking up all waiters */
653
 
      ReleaseSemaphore(s, c, NULL);
654
 
      leave_blocking_section();
655
 
    End_roots();
 
651
    /* Increment semaphore by c, waking up all waiters */
 
652
    ReleaseSemaphore(s, c, NULL);
656
653
  }
657
654
  return Val_unit;
658
655
}