From 5d776422e8726d887c9b93fede610e4cbc50179d Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Sun, 6 Mar 2005 04:56:00 +0000 Subject: introduce compile time error reporting for architectures not supported Lifos and Fifos with reservoir svn path=/trunk/; revision=2598 --- externals/grill/flext/source/flcontainers.h | 46 ++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 11 deletions(-) (limited to 'externals/grill/flext') diff --git a/externals/grill/flext/source/flcontainers.h b/externals/grill/flext/source/flcontainers.h index 14d793de..ad32055a 100644 --- a/externals/grill/flext/source/flcontainers.h +++ b/externals/grill/flext/source/flcontainers.h @@ -12,6 +12,7 @@ WARRANTIES, see the file, "license.txt," in this distribution. \brief Lock-free container classes This code has been adapted from the MidiShare project (c)Grame + http://midishare.sourceforge.net */ #ifndef __FLCONTAINERS_H @@ -21,12 +22,8 @@ WARRANTIES, see the file, "license.txt," in this distribution. #include "flprefix.h" -#if 1 //def __Pentium__ -#define VTYPE volatile -#else -#define VTYPE -#endif - +// define that precautiously... +// it's faster without that but we can't really know... #define __SMP__ @@ -47,7 +44,7 @@ public: inline Cell *Avail() { return (Cell *)top; } -#if defined(_WIN32) && defined(_MSC_VER) +#if defined(_MSC_VER) && (defined(_WIN32)) #ifdef __SMP__ #define LOCK lock #else @@ -112,7 +109,7 @@ public: } inline size_t Size() const { return ic-oc; } -#elif defined(__GNUC__) && (defined(_X86_) || defined(__i386__) || defined(__i586__) || defined(__i686__)) +#elif defined(__GNUC__) && (defined(_X86_) || defined(__i386__)) #ifndef SMPLOCK # ifdef __SMP__ # define SMPLOCK "lock ; " @@ -183,6 +180,10 @@ public: :"memory", "edx"); return n; } +#elif defined(__GNUC__) && defined(__x86_64__) + +#error x86-64 architecture not supported yet + #elif defined(__GNUC__) && defined(__POWERPC__) inline void Push(register Cell *cl) { @@ -244,13 +245,15 @@ public: } inline size_t Size() const { return oc; } +#else +#error Platform not supported #endif private: // don't change order! - VTYPE size_t ic; // input (push) count - VTYPE Cell *top; // top of the stack - VTYPE size_t oc; // output (pop) count + volatile size_t ic; // input (push) count + volatile Cell *top; // top of the stack + volatile size_t oc; // output (pop) count #ifdef __POWERPC__ size_t unused[5]; // lifo size must be at least 32 bytes // to avoid livelock in multiprocessor @@ -267,6 +270,17 @@ public: inline T *Pop() { return static_cast(Lifo::Pop()); } }; +template +class PooledLifo + : public TypedLifo +{ +public: + inline T *New() { T *n = reuse.Pop(); return n?n:new T; } + inline Free(T *p) { if(reuse.Size() < Size()) reuse.Push(p); else delete p; } +private: + TypedLifo reuse; +}; + class FLEXT_SHARE Fifo { @@ -333,5 +347,15 @@ public: inline T *Clear() { return static_cast(Fifo::Clear()); } }; +template +class PooledFifo + : public TypedFifo +{ +public: + inline T *New() { T *n = reuse.Pop(); return n?n:new T; } + inline Free(T *p) { if(reuse.Size() < Size()) reuse.Push(p); else delete p; } +private: + TypedLifo reuse; +}; #endif -- cgit v1.2.1