home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1999 March B / SCO_CASTOR4RRT.iso / uccs / root.14 / udk / usr / include / machlock.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-19  |  1.8 KB  |  61 lines

  1. /*
  2.  * Copyright (c) 1998 The Santa Cruz Operation, Inc.. All Rights Reserved. 
  3.  *                                                                         
  4.  *        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF THE               
  5.  *                   SANTA CRUZ OPERATION INC.                             
  6.  *                                                                         
  7.  *   The copyright notice above does not evidence any actual or intended   
  8.  *   publication of such source code.                                      
  9.  */
  10.  
  11. #ifndef _MACHLOCK_H
  12. #define _MACHLOCK_H
  13. #ident    "@(#)sgs-head:i386/head/machlock.h    1.2"
  14.  
  15. typedef volatile unsigned char _simplelock_t;
  16.  
  17. #if defined(__USLC__) && (defined(_LIBLWPSYNCH_H) || defined(_LIBTHREAD_H))
  18.  
  19. #define _SIMPLE_UNLOCKED    0
  20. #define _SIMPLE_LOCKED        0xff
  21.  
  22. /*
  23.  * _lock_try() tries to acquire a simple lock.
  24.  * _lock_try() returns non-zero on success.
  25.  */
  26. asm int
  27. _lock_try(_simplelock_t *lockp)
  28. {
  29. %reg lockp
  30.     movl    $_SIMPLE_LOCKED, %eax    / value to exchange
  31.     xchgb    (lockp), %al        / try for the lock atomically
  32.     xorb    $_SIMPLE_LOCKED, %al    / return non-zero if success
  33.  
  34. %mem lockp
  35.     movl    lockp, %ecx
  36.     movl    $_SIMPLE_LOCKED, %eax    / value to exchange
  37.     xchgb    (%ecx), %al        / try for the lock atomically
  38.     xorb    $_SIMPLE_LOCKED, %al    / return non-zero if success
  39. }
  40. #pragma asm partial_optimization _lock_try
  41.  
  42. /* _lock_clear() unlocks a simple lock.
  43.  */
  44. asm void
  45. _lock_clear(_simplelock_t *lockp)
  46. {
  47. %reg lockp
  48.     movl    $_SIMPLE_UNLOCKED, %eax    / value to exchange
  49.     xchgb    (lockp), %al        / clear the lock atomically
  50.  
  51. %mem lockp
  52.     movl    lockp, %ecx
  53.     movl    $_SIMPLE_UNLOCKED, %eax    / value to exchange
  54.     xchgb    (%ecx), %al        / clear the lock atomically
  55. }
  56. #pragma asm partial_optimization _lock_clear
  57.  
  58. #endif /*__USLC__ && (_LIBLWPSYNCH_H || _LIBTHREAD_H)*/
  59.  
  60. #endif /*_MACHLOCK_H*/
  61.