home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Headers / mach / sparc / simple_lock.h < prev    next >
Text File  |  1997-04-27  |  1KB  |  70 lines

  1. /* Copyright (c) 1994 NeXT Computer, Inc.  All rights reserved.
  2.  * 
  3.  *    File:    mach/sparc/simple_lock.h
  4.  *
  5.  *    This file contains machine dependent code for exclusion
  6.  *    lock handling on SPARC-based products.
  7.  *
  8.  * HISTORY
  9.  * 21-Apr-1994  Mac Gillon at NeXT
  10.  *    Created.
  11.  */
  12.  
  13. #import <mach/boolean.h>
  14.  
  15. #ifndef    _MACH_SPARC_SIMPLE_LOCK_
  16. #define _MACH_SPARC_SIMPLE_LOCK_
  17.  
  18. #define _MACHINE_SIMPLE_LOCK_DATA_
  19.  
  20. struct slock {
  21.     volatile boolean_t    locked;
  22. };
  23.  
  24. typedef struct slock    simple_lock_data_t;
  25. typedef struct slock    *simple_lock_t;
  26.  
  27. extern simple_lock_t    simple_lock_alloc(void);
  28. extern void        simple_lock_free(simple_lock_t);
  29. extern boolean_t    simple_lock_try();
  30.  
  31. #if    !defined(DEFINE_SIMPLE_LOCK_PRIMS)
  32. static __inline__
  33. #endif
  34. void
  35. simple_lock_init(
  36.     simple_lock_t    slock
  37. )
  38. {
  39.     slock->locked = FALSE;
  40. }
  41.  
  42. #if    !defined(DEFINE_SIMPLE_LOCK_PRIMS)
  43. static __inline__
  44. #endif
  45. void
  46. simple_lock(
  47.     simple_lock_t    slock
  48. )
  49. {    
  50.     do
  51.         {
  52.         while (slock->locked)
  53.         continue;
  54.     }
  55.     while (!simple_lock_try(slock));
  56. }
  57.  
  58. #if    !defined(DEFINE_SIMPLE_LOCK_PRIMS)
  59. static __inline__
  60. #endif
  61. void
  62. simple_unlock(
  63.     simple_lock_t    slock
  64. )
  65. {
  66.     slock->locked = FALSE;
  67. }
  68.  
  69. #endif    _MACH_SPARC_SIMPLE_LOCK_
  70.