home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / Papers / C++ Exceptions / µShell / Threads Support / Futures.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-02  |  2.9 KB  |  106 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        Futures.h
  3.  
  4.     Contains:    Header file for futures
  5.  
  6.     Written by:    Andy Nicholas, Greg Anderson, Tom Conrad, Chris Bingham, Georgiann Puckett, John Thompson-Rohrlich, Max McFarland
  7.  
  8.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <2>     7/21/94    andy    include MixedMode.h to get kPascalStackBased
  13.          <1>      7/6/94    ga        first checked in
  14.                   7/6/94    ga        New today
  15.  
  16. */
  17.  
  18. #ifndef Futures_h
  19. #define Futures_h
  20.  
  21. #ifndef __MIXEDMODE__
  22. #include <MixedMode.h>
  23. #endif
  24. #ifndef __APPLEEVENTS__
  25. #include <AppleEvents.h>
  26. #endif
  27. #ifndef __THREADS__
  28. #include <Threads.h>
  29. #endif
  30.  
  31. //
  32. // Constants
  33. //
  34. #define kNoMaximumWait                    (0x7FFFFFFF)
  35.  
  36. #if 0
  37.  
  38. //
  39. // Keyword for refCon attribute not documented
  40. // in Inside Macintosh
  41. //
  42. #define keyRefconAttr                    'refc'
  43.  
  44. #endif
  45.  
  46. //
  47. // Keyword keyAEResetTimerFrequency specifies
  48. // approximately how frequently (in ticks) the 
  49. // client would like the server to call AEResetTimer.
  50. // This value is advisory only, and is typically
  51. // one-half of the timeout value.
  52. //
  53. #define keyAEResetTimerFrequencyAttr     'resf'
  54.  
  55. //
  56. // This is how frequently a server should call
  57. // AEResetTimer if the AppleEvent message doesn't
  58. // contain a 'reset timer frequency' attribute
  59. //
  60. #define kDefaultResetTimerFrequency        30
  61.  
  62. //
  63. // Values for InitFutures
  64. //
  65. #define kNoSpecialFutureFeatures        0
  66. #define kSpawnHousekeepingThread        0x0001
  67. #define kInstallAsyncPreDispatchHandler    0x0002
  68. #define kAllSpecialFutureFeatures        (kSpawnHousekeepingThread | kInstallAsyncPreDispatchHandler)
  69.  
  70. typedef pascal OSErr (*ThreadCreateProcPtr)(ThreadEntryProcPtr threadEntry, void* threadParam, long handlerRefCon, ThreadID* threadMade);
  71.  
  72. #ifdef __cplusplus
  73. extern "C" {
  74. #endif
  75.  
  76. //
  77. // Prototypes for Future functions
  78. //
  79. OSErr InitFutures(ThreadCreateProcPtr threadCreateProc, long initFuturesFlags);
  80. void BlockUntilReal(AppleEvent* reply);
  81. Boolean ReplyArrived(AppleEvent* reply);
  82. void SetReplyTimeoutValue(AppleEvent* reply, long timeoutValue, long maxWaitTime);
  83. void IdleFutures();
  84. OSErr AskForFuture(const AppleEvent* ae, AppleEvent* reply, long timeoutValue, long maxWaitTime, AESendMode sendMode, AESendPriority sendPriority);
  85. long GetResetTimerFrequency(AppleEvent* ae);
  86. OSErr ResetTimerIfNecessary(AppleEvent* reply, unsigned long* lastReset, long resetFrequency);
  87.  
  88. #ifdef __cplusplus
  89. }
  90.  
  91. //
  92. // Default parameters: for use with C++ compilers
  93. //
  94. inline OSErr InitFutures(ThreadCreateProcPtr threadCreateProc = nil /* kAllSpecialFutureFeatures */) { return InitFutures(threadCreateProc, kAllSpecialFutureFeatures); }
  95. inline OSErr AskForFuture(const AppleEvent* ae, AppleEvent* reply, long timeoutValue = kAEDefaultTimeout, long maxWaitTime = kNoMaximumWait, AESendMode sendMode = 0 /* kAENormalPriority */) { return AskForFuture(ae, reply, timeoutValue, maxWaitTime, sendMode, kAENormalPriority); }
  96.  
  97. #endif
  98.  
  99. //
  100. // Backwards compatability API
  101. //
  102. #define IsFuture(reply)        (!ReplyArrived(reply))
  103.  
  104. #endif // Futures_h
  105.  
  106.