home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Examples / ThreadedApp-1.0.1 / CJRLock.h < prev    next >
Encoding:
Text File  |  1997-04-02  |  1.3 KB  |  64 lines

  1. /*
  2.  *  $Id: CJRLock.h,v 1.1 1997/04/02 18:28:20 croehrig Exp $
  3.  *
  4.  *  CJRLock  -- Foundation Kit-less NSLock, NSConditionLock
  5.  *  Compatibile with Foundation Kit from EOF 1.1, which shipped with 
  6.  *  NS3.3 Academic Bundle).
  7.  *
  8.  *  (c) 1997 Chris Roehrig <croehrig@House.ORG>
  9.  *
  10.  *  Doesn't implement timeout methods.
  11.  *  Doesn't implement NSRecursiveLock.
  12.  */
  13.  
  14. #import <objc/Object.h>
  15. #import <mach/cthreads.h>
  16.  
  17. @protocol CJRLocking
  18. - (void)lock;
  19. - (void)unlock;
  20. @end
  21.  
  22.  
  23. /***************    CJRLock        ***************/
  24.  
  25. @interface CJRLock:Object <CJRLocking> {
  26.     @private
  27.     mutex_t    mutex;
  28. }
  29.  
  30. - (BOOL)tryLock;
  31.     /* Returns YES iff lock acquired; returns immediately */
  32.  
  33. @end
  34.  
  35.  
  36. /***************    CJRConditionLock        ***************/
  37.  
  38.  
  39. @interface CJRConditionLock:Object <CJRLocking> {
  40.     @private
  41.     mutex_t    mutex;    // lock to protect data
  42.     volatile int    data;
  43.     condition_t    cond;
  44. }
  45.  
  46. - initWithCondition:(int)condition;
  47.     // init & set condition variable
  48.     
  49. - (int)condition;
  50.  
  51. - (void)lockWhenCondition:(int)condition;
  52.     // acquire lock when conditionVar == condition
  53.     
  54. - (BOOL)tryLock;
  55.     /* Returns YES iff lock acquired; returns immediately */
  56.  
  57. - (BOOL)tryLockWhenCondition:(int)condition;
  58.     // acquire lock when conditionVar == condition
  59.     
  60. - (void)unlockWithCondition:(int)condition;
  61.     // release lock and update conditionVar
  62.     
  63. @end
  64.