home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1999 March B / SCO_CASTOR4RRT.iso / uccs / root.14 / udk / usr / include / lwpsynch.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-19  |  2.7 KB  |  91 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 _LWPSYNCH_H
  12. #define _LWPSYNCH_H
  13. #ident    "@(#)sgs-head:i386/head/lwpsynch.h    1.6"
  14. /*
  15.  * LWP synchronization
  16.  */
  17.  
  18. #include <sys/time.h>
  19. #include <machlock.h>
  20. #include <sys/usync.h>
  21.  
  22. typedef volatile struct __lwp_mutex {
  23.     char        wanted;
  24.     _simplelock_t    lock;
  25. #ifdef FATMUTEX
  26.     long        fill[2];
  27. #endif
  28. } lwp_mutex_t;
  29.  
  30. typedef volatile struct __lwp_cond {
  31.     char        wanted;
  32. #ifdef FATMUTEX
  33.     long        fill[2];
  34. #endif
  35. } lwp_cond_t;
  36.  
  37. #ifdef _LIBTHREAD_H
  38. /*
  39.  * LWP_MUTEX_TRYLOCK() returns zero on success.
  40.  * LWP_MUTEX_ISLOCKED() returns non-zero if the mutex islocked.
  41.  */
  42. #define LWP_MUTEX_TRYLOCK(/* lwp_mutex_t * */ mp) (!_lock_try(&(mp)->lock))
  43. #define LWP_MUTEX_ISLOCKED(/* lwp_mutex_t * */ mp) ((mp)->lock)
  44. #endif /*_LIBTHREAD_H*/
  45.  
  46. #ifdef __cplusplus
  47. extern "C" {
  48. #endif
  49.  
  50. #if defined(__USLC__) && (defined(_LIBLWPSYNCH_H) || defined(_LIBTHREAD_H))
  51. /*
  52.  * _lock_and_flag_clear() clears the first word of memory in an lwp_mutex_t
  53.  * and returns the value of the wanted flag.  This is used by _lwp_mutex_unlock
  54.  * to determine if LWPs are waiting on the lock while avoiding access to the
  55.  * lock structure after clearing the lock to avoid the danger that the lock
  56.  * might be unmapped after the lock is cleared.
  57.  */
  58. asm int
  59. _lock_and_flag_clear(lwp_mutex_t *lmp)
  60. {
  61. %reg lmp;
  62.     xorl    %eax, %eax    / value to put into lock
  63.     xchgw    (lmp), %ax    / swap 0 with lmp->wanted, lmp->lock
  64.     movb    $0, %ah        / zero out lmp->lock portion of return
  65. %mem lmp;
  66.     movl    lmp, %ecx    / ecx = lock address
  67.     xorl    %eax, %eax    / value to put into lock
  68.     xchgw    (%ecx), %ax    / swap 0 with lmp->wanted, lmp->lock
  69.     movb    $0, %ah        / zero out lmp->lock portion of return
  70. }
  71. #pragma asm partial_optimization _lock_and_flag_clear
  72. #endif /*__USLC__ && (_LIBLWPSYNCH_H || _LIBTHREAD_H)*/
  73.  
  74. int    _lwp_mutex_trylock(lwp_mutex_t *);
  75. int    _lwp_mutex_lock(lwp_mutex_t *);
  76. int    _lwp_mutex_unlock(lwp_mutex_t *);
  77. int    _lwp_cond_signal(lwp_cond_t *);
  78. int    _lwp_cond_broadcast(lwp_cond_t *);
  79. int    _lwp_cond_wait(lwp_cond_t *, lwp_mutex_t *);
  80. int    _lwp_cond_timedwait(lwp_cond_t *, lwp_mutex_t *, const timestruc_t *);
  81. int    _lwp_sema_init(_lwp_sema_t *, int);
  82. int    _lwp_sema_post(_lwp_sema_t *);
  83. int    _lwp_sema_trywait(_lwp_sema_t *);
  84. int    _lwp_sema_wait(_lwp_sema_t *);
  85.  
  86. #ifdef __cplusplus
  87. }
  88. #endif
  89.  
  90. #endif /*_LWPSYNCH_H*/
  91.