Subversion Repositories HelenOS-historic

Rev

Rev 1113 | Rev 1663 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1113 Rev 1143
Line 459... Line 459...
459
#define MALLOC_ALIGNMENT ((size_t)8U)
459
#define MALLOC_ALIGNMENT ((size_t)8U)
460
#define FOOTERS 0
460
#define FOOTERS 0
461
#define ABORT  abort()
461
#define ABORT  abort()
462
#define ABORT_ON_ASSERT_FAILURE 1
462
#define ABORT_ON_ASSERT_FAILURE 1
463
#define PROCEED_ON_ERROR 0
463
#define PROCEED_ON_ERROR 0
464
#define USE_LOCKS 0
464
#define USE_LOCKS 1
465
#define INSECURE 0
465
#define INSECURE 0
466
#define HAVE_MMAP 0
466
#define HAVE_MMAP 0
467
 
467
 
468
#define MMAP_CLEARS 1
468
#define MMAP_CLEARS 1
469
 
469
 
Line 761... Line 761...
761
 
761
 
762
  * magic_init_mutex ensures that mparams.magic and other
762
  * magic_init_mutex ensures that mparams.magic and other
763
    unique mparams values are initialized only once.
763
    unique mparams values are initialized only once.
764
*/
764
*/
765
 
765
 
766
#ifndef WIN32
-
 
767
/* By default use posix locks */
766
/* By default use posix locks */
768
#include <pthread.h>
767
#include <futex.h>
769
#define MLOCK_T pthread_mutex_t
768
#define MLOCK_T atomic_t
770
#define INITIAL_LOCK(l)      pthread_mutex_init(l, NULL)
769
#define INITIAL_LOCK(l)      futex_initialize(l, 1)
-
 
770
/* futex_down cannot fail, but can return different
-
 
771
 * retvals for OK
-
 
772
 */
771
#define ACQUIRE_LOCK(l)      pthread_mutex_lock(l)
773
#define ACQUIRE_LOCK(l)      ({futex_down(l);0;})
772
#define RELEASE_LOCK(l)      pthread_mutex_unlock(l)
774
#define RELEASE_LOCK(l)      futex_up(l)
773
 
775
 
774
#if HAVE_MORECORE
776
#if HAVE_MORECORE
775
static MLOCK_T morecore_mutex = PTHREAD_MUTEX_INITIALIZER;
777
static MLOCK_T morecore_mutex = FUTEX_INITIALIZER;
776
#endif /* HAVE_MORECORE */
778
#endif /* HAVE_MORECORE */
777
 
779
 
778
static MLOCK_T magic_init_mutex = PTHREAD_MUTEX_INITIALIZER;
780
static MLOCK_T magic_init_mutex = FUTEX_INITIALIZER;
779
 
781
 
780
#else /* WIN32 */
-
 
781
/*
-
 
782
   Because lock-protected regions have bounded times, and there
-
 
783
   are no recursive lock calls, we can use simple spinlocks.
-
 
784
*/
-
 
785
 
-
 
786
#define MLOCK_T long
-
 
787
static int win32_acquire_lock (MLOCK_T *sl) {
-
 
788
  for (;;) {
-
 
789
#ifdef InterlockedCompareExchangePointer
-
 
790
    if (!InterlockedCompareExchange(sl, 1, 0))
-
 
791
      return 0;
-
 
792
#else  /* Use older void* version */
-
 
793
    if (!InterlockedCompareExchange((void**)sl, (void*)1, (void*)0))
-
 
794
      return 0;
-
 
795
#endif /* InterlockedCompareExchangePointer */
-
 
796
    Sleep (0);
-
 
797
  }
-
 
798
}
-
 
799
 
-
 
800
static void win32_release_lock (MLOCK_T *sl) {
-
 
801
  InterlockedExchange (sl, 0);
-
 
802
}
-
 
803
 
-
 
804
#define INITIAL_LOCK(l)      *(l)=0
-
 
805
#define ACQUIRE_LOCK(l)      win32_acquire_lock(l)
-
 
806
#define RELEASE_LOCK(l)      win32_release_lock(l)
-
 
807
#if HAVE_MORECORE
-
 
808
static MLOCK_T morecore_mutex;
-
 
809
#endif /* HAVE_MORECORE */
-
 
810
static MLOCK_T magic_init_mutex;
-
 
811
#endif /* WIN32 */
-
 
812
 
782
 
813
#define USE_LOCK_BIT               (2U)
783
#define USE_LOCK_BIT               (2U)
814
#else  /* USE_LOCKS */
784
#else  /* USE_LOCKS */
815
#define USE_LOCK_BIT               (0U)
785
#define USE_LOCK_BIT               (0U)
816
#define INITIAL_LOCK(l)
786
#define INITIAL_LOCK(l)