Max 5 API Reference
00001 // critical.h -- platform-independent way to define critical regions 00002 00003 #ifndef _CRITICAL_H_ 00004 #define _CRITICAL_H_ 00005 00006 #ifdef __cplusplus 00007 extern "C" { 00008 #endif 00009 00010 #if C74_PRAGMA_STRUCT_PACKPUSH 00011 #pragma pack(push, 2) 00012 #elif C74_PRAGMA_STRUCT_PACK 00013 #pragma pack(2) 00014 #endif 00015 00016 #define CRITICAL_DEFAULT 2000 * kDurationMillisecond 00017 00018 #ifdef WIN_VERSION 00019 typedef LPCRITICAL_SECTION t_critical; 00020 typedef unsigned long t_thread; 00021 #elif TARGET_API_MAC_CARBON 00022 typedef MPCriticalRegionID t_critical; 00023 typedef ThreadID t_thread; 00024 #else 00025 /** 00026 A Max critical region. 00027 @ingroup critical 00028 */ 00029 typedef void t_critical; 00030 00031 /** 00032 A Max thread. 00033 @ingroup threading 00034 */ 00035 typedef void t_thread; 00036 #endif 00037 00038 00039 /** 00040 Create a new critical region. 00041 Normally, you do not need to create your own critical region, because 00042 you can use Max’s global critical region. Only use this function (in 00043 your object’s instance creation method) if you are certain you are not 00044 able to use the global critical region. 00045 00046 @ingroup critical 00047 @param x A #t_critical struct will be returned to you via this pointer. 00048 */ 00049 void critical_new(t_critical *x); 00050 00051 00052 /** 00053 Enter a critical region. 00054 Typically you will want the argument to be zero to enter the global 00055 critical region, although you could pass your own critical created with 00056 critical_new(). It is important to try to keep the amount of code in 00057 the critical region to a minimum. 00058 Exit the critical region with critical_exit(). 00059 00060 @ingroup critical 00061 @param x A pointer to a #t_critical struct, or zero to uses Max’s global critical region. 00062 @see critical_exit() 00063 */ 00064 void critical_enter(t_critical x); 00065 00066 00067 /** 00068 Leave a critical region. 00069 Typically you will want the argument to be zero to exit the global 00070 critical region, although, you if you are using your own critical regions 00071 you will want to pass the same one that you previously passed to 00072 critical_enter(). 00073 00074 @ingroup critical 00075 @param x A pointer to a #t_critical struct, or zero to uses Max’s global critical region. 00076 */ 00077 void critical_exit(t_critical x); 00078 00079 00080 /** 00081 Free a critical region created with critical_new(). 00082 If you created your own critical region, you will need to free it in your object’s free method. 00083 00084 @ingroup critical 00085 @param x The #t_critical struct that will be freed. 00086 */ 00087 void critical_free(t_critical x); 00088 00089 00090 /** Try to enter a critical region if it is not locked. 00091 @ingroup critical 00092 @param x A pointer to a #t_critical struct, or zero to uses Max’s global critical region. 00093 @return returns non-zero if there was a problem entering 00094 @see critical_enter() 00095 */ 00096 short critical_tryenter(t_critical x); 00097 00098 00099 #if C74_PRAGMA_STRUCT_PACKPUSH 00100 #pragma pack(pop) 00101 #elif C74_PRAGMA_STRUCT_PACK 00102 #pragma pack() 00103 #endif 00104 00105 #ifdef __cplusplus 00106 } 00107 #endif 00108 00109 #endif // _CRITICAL_H_
Copyright © 2008, Cycling '74