home *** CD-ROM | disk | FTP | other *** search
/ Openstep 4.2 (Developer) / Openstep Developer 4.2.iso / NextDeveloper / Headers / mach / hppa / simple_lock.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-16  |  1.5 KB  |  88 lines

  1. /* Copyright (c) 1993 NeXT Computer, Inc.  All rights reserved.
  2.  * 
  3.  *    File:    mach/hppa/simple_lock.h
  4.  *
  5.  *    This file contains machine dependent code for exclusion
  6.  *    lock handling on HPPA-based products.
  7.  *
  8.  * HISTORY
  9.  * 2-July-1993  Mac Gillon at NeXT
  10.  *    Created.
  11.  */
  12.  
  13. #import <mach/hppa/boolean.h>
  14.  
  15. #ifndef    _MACH_HPPA_SIMPLE_LOCK_
  16. #define _MACH_HPPA_SIMPLE_LOCK_
  17.  
  18. #define    _MACHINE_SIMPLE_LOCK_DATA_
  19.  
  20. struct slock{
  21.     volatile unsigned int lock_data[4];/* in general 1 bit is sufficient */
  22. };
  23.  
  24. typedef struct slock    simple_lock_data_t;
  25. typedef struct slock    *simple_lock_t;
  26.  
  27. #if    !defined(DEFINE_SIMPLE_LOCK_PRIMS)
  28. static __inline__
  29. #endif
  30. void
  31. simple_lock_init(
  32.     simple_lock_t    slock
  33. )
  34. {
  35.     *((volatile int *)(((int)(slock) + 0x0c) & ~0x0f))  = 1;
  36. }
  37.  
  38. #if    !defined(DEFINE_SIMPLE_LOCK_PRIMS)
  39. static __inline__
  40. #endif
  41. void
  42. simple_unlock(
  43.     simple_lock_t    slock
  44. )
  45. {
  46.     *((volatile int *)(((int)(slock) + 0x0c) & ~0x0f))  = 1;
  47. }
  48.  
  49. #if    !defined(DEFINE_SIMPLE_LOCK_PRIMS)
  50. static __inline__
  51. #endif
  52. boolean_t
  53. simple_lock_try(
  54.     simple_lock_t    slock
  55. )
  56. {
  57.     boolean_t        result;
  58.     volatile int   *lock_word;
  59.     
  60.     lock_word = (volatile int *)(((int)(slock) + 0x0c) & ~0x0f);
  61.     
  62.     asm volatile (
  63.         "ldcws 0(%1),%0"
  64.         : "=r" (result): "r" (lock_word));
  65.     
  66.     return (result);
  67. }
  68.  
  69.  
  70.  
  71. #if    !defined(DEFINE_SIMPLE_LOCK_PRIMS)
  72. static __inline__
  73. #endif
  74. void
  75. simple_lock(
  76.     simple_lock_t    slock
  77. )
  78. {    
  79.     do
  80.         {
  81.         while (*((volatile int *)(((int)(slock) + 0x0c) & ~0x0f))  == 0)
  82.         continue;
  83.     }
  84.     while (!simple_lock_try(slock));
  85. }
  86.  
  87. #endif    _MACH_HPPA_SIMPLE_LOCK_
  88.