Boron 0.1.0

os.h

00001 #ifndef OS_H
00002 #define OS_H
00003 /*
00004    Boron operating system interface.
00005 */
00006 
00007 
00008 #include <assert.h>
00009 #include <math.h>
00010 #include <stdarg.h>
00011 #include <stdio.h>
00012 #include <stdlib.h>
00013 #include <string.h>
00014 #ifdef __sun__
00015 #include <inttypes.h>
00016 #else
00017 #include <stdint.h>
00018 #endif
00019 
00020 
00021 #ifdef _WIN32
00022 
00023 // Must define _WIN32_WINNT to use InitializeCriticalSectionAndSpinCount
00024 #define _WIN32_WINNT    0x0403
00025 // ws2 header included here for uc_wait because it must come before windows.h
00026 #include <winsock2.h>
00027 #include <windows.h>
00028 
00029 #ifdef _MSC_VER
00030 #define inline  __inline
00031 #endif
00032 
00033 #define vaStrPrint  _vsnprintf
00034 
00035 typedef HANDLE              OSThread;
00036 typedef CRITICAL_SECTION    OSMutex;
00037 typedef CONDITION_VARIABLE  OSCond;
00038 
00039 #define mutexInitF(mh) \
00040     (InitializeCriticalSectionAndSpinCount(&mh,0x80000400) == 0)
00041 #define mutexFree(mh)       DeleteCriticalSection(&mh)
00042 #define mutexLock(mh)       EnterCriticalSection(&mh)
00043 #define mutexUnlock(mh)     LeaveCriticalSection(&mh)
00044 #define condInit(cond)      InitializeConditionVariable(&cond)
00045 #define condFree(cond)
00046 #define condWaitF(cond,mh)  (! SleepConditionVariableCS(&cond,&mh,INFINITE))
00047 #define condSignal(cond)    WakeConditionVariable(&cond)
00048 
00049 #else
00050 
00051 #include <pthread.h>
00052 #include <unistd.h>
00053 
00054 #define vaStrPrint  vsnprintf
00055 
00056 typedef pthread_t           OSThread;
00057 typedef pthread_mutex_t     OSMutex;
00058 typedef pthread_cond_t      OSCond;
00059 
00060 #define mutexInitF(mh)      (pthread_mutex_init(&mh,0) == -1)
00061 #define mutexFree(mh)       pthread_mutex_destroy(&mh)
00062 #define mutexLock(mh)       pthread_mutex_lock(&mh)
00063 #define mutexUnlock(mh)     pthread_mutex_unlock(&mh)
00064 #define condInit(cond)      pthread_cond_init(&cond,0)
00065 #define condFree(cond)      pthread_cond_destroy(&cond)
00066 #define condWaitF(cond,mh)  pthread_cond_wait(&cond,&mh)
00067 #define condSignal(cond)    pthread_cond_signal(&cond)
00068 
00069 #endif
00070 
00071 
00072 #define strPrint    sprintf
00073 #define strNCpy     strncpy
00074 #define strLen      strlen
00075 
00076 #define memCpy      memcpy
00077 #define memSet      memset
00078 #define memMove     memmove
00079 
00080 
00081 #ifdef __cplusplus
00082 extern "C" {
00083 #endif
00084 
00085 #ifdef TRACK_MALLOC
00086 void* memAlloc( size_t );
00087 void* memRealloc( void*, size_t );
00088 void  memFree( void* );
00089 void  memReport( int verbose );
00090 #else
00091 #define memAlloc    malloc
00092 #define memRealloc  realloc
00093 #define memFree     free
00094 #endif
00095 
00096 #ifdef UR_CONFIG_EMH
00097 extern void ur_dprint( const char*, ... );
00098 #define dprint      ur_dprint
00099 #else
00100 #define dprint      printf
00101 #endif
00102 
00103 #ifdef __cplusplus
00104 }
00105 #endif
00106 
00107 
00108 #endif  /* OS_H */

Generated on 27 Jan 2012 by Doxygen 1.5.1