usermode/library/malloc-original/src/arch-specific.h

00001 
00002 //
00003 // The Hoard Multiprocessor Memory Allocator
00004 // www.hoard.org
00005 //
00006 // Author: Emery Berger, http://www.cs.utexas.edu/users/emery
00007 //
00008 // Copyright (c) 1998-2001, The University of Texas at Austin.
00009 //
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Library General Public License as
00012 // published by the Free Software Foundation, http://www.fsf.org.
00013 //
00014 // This library is distributed in the hope that it will be useful, but
00015 // WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 // Library General Public License for more details.
00018 //
00020 
00021 #ifndef _ARCH_SPECIFIC_H_
00022 #define _ARCH_SPECIFIC_H_
00023 
00024 #include "config.h"
00025 
00026 // Wrap architecture-specific functions.
00027 
00028 #if defined(WIN32) || defined(__WIN32__) || defined(_WIN32)
00029 
00030 // Windows
00031 
00032 #ifndef WIN32
00033 #define WIN32 1
00034 #endif
00035 
00036 // Set maximal inlining.
00037 #pragma inline_depth(255)
00038 #define inline __forceinline
00039 
00040 #include <windows.h>
00041 #include <process.h>
00042 //typedef CRITICAL_SECTION      hoardLockType;
00043 typedef long hoardLockType;
00044 typedef HANDLE  hoardThreadType;
00045 
00046 #elif USE_SPROC
00047 
00048 // SGI's SPROC library
00049 
00050 #include <sys/types.h>
00051 #include <sys/prctl.h>
00052 
00053 #else
00054 
00055 // Generic UNIX
00056 
00057 #if defined(__SVR4) // Solaris
00058 #include <thread.h>
00059 #endif
00060 
00061 #include <pthread.h>
00062 #include <unistd.h>
00063 
00064 #endif
00065 
00066 
00067 #ifndef WIN32
00068 #if USER_LOCKS && (defined(i386) || defined(sparc) || defined(__sgi))
00069 typedef unsigned long   hoardLockType;
00070 #else
00071 typedef pthread_mutex_t hoardLockType;
00072 #endif
00073 
00074 #if USE_SPROC
00075 typedef pid_t                   hoardThreadType;
00076 #else
00077 typedef pthread_t               hoardThreadType;
00078 #endif
00079 
00080 #endif
00081 
00082 extern "C" {
00083 
00085 
00086   void  hoardCreateThread (hoardThreadType& t,
00087                            void *(*function) (void *),
00088                            void * arg);
00089   void  hoardJoinThread (hoardThreadType& t);
00090   void  hoardSetConcurrency (int n);
00091 
00092   // Return a thread identifier appropriate for hashing:
00093   // if the system doesn't produce consecutive thread id's,
00094   // some hackery may be necessary.
00095   int   hoardGetThreadID (void);
00096 
00098 
00099 #if !defined(WIN32) && !USER_LOCKS
00100 
00101   // Define the lock operations inline to save a little overhead.
00102 
00103   inline void hoardLockInit (hoardLockType& lock) {
00104     pthread_mutex_init (&lock, NULL);
00105   }
00106 
00107   inline void hoardLock (hoardLockType& lock) {
00108     pthread_mutex_lock (&lock);
00109   }
00110 
00111   inline void hoardUnlock (hoardLockType& lock) {
00112     pthread_mutex_unlock (&lock);
00113   }
00114 
00115 #else
00116   void  hoardLockInit (hoardLockType& lock);
00117   void  hoardLock (hoardLockType& lock);
00118   void  hoardUnlock (hoardLockType& lock);
00119 #endif
00120 
00121   inline void  hoardLockDestroy (hoardLockType&) {
00122   }
00123 
00125 
00126   int   hoardGetPageSize (void);
00127   void *        hoardGetMemory (long size);
00128   void  hoardFreeMemory (void * ptr);
00129 
00131 
00132   void  hoardYield (void);
00133   int   hoardGetNumProcessors (void);
00134   unsigned long hoardInterlockedExchange (unsigned long * oldval,
00135                                           unsigned long newval);
00136 }
00137 
00138 #endif // _ARCH_SPECIFIC_H_
00139 

Generated on Sat Apr 23 11:43:35 2011 for Mnemosyne by  doxygen 1.4.7