00001 #ifndef _ofxsMultiThread_H_ 00002 #define _ofxsMultiThread_H_ 00003 /* 00004 OFX Support Library, a library that skins the OFX plug-in API with C++ classes. 00005 Copyright (C) 2004-2007 The Foundry Visionmongers Ltd 00006 Author Bruno Nicoletti bruno@thefoundry.co.uk 00007 00008 Redistribution and use in source and binary forms, with or without 00009 modification, are permitted provided that the following conditions are met: 00010 00011 * Redistributions of source code must retain the above copyright notice, 00012 this list of conditions and the following disclaimer. 00013 * Redistributions in binary form must reproduce the above copyright notice, 00014 this list of conditions and the following disclaimer in the documentation 00015 and/or other materials provided with the distribution. 00016 * Neither the name The Foundry Visionmongers Ltd, nor the names of its 00017 contributors may be used to endorse or promote products derived from this 00018 software without specific prior written permission. 00019 00020 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00021 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00022 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00023 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 00024 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00025 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00026 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00027 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00028 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00029 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 00031 The Foundry Visionmongers Ltd 00032 1 Wardour St 00033 London W1D 6PA 00034 England 00035 00036 00037 00038 */ 00039 00046 #include "ofxsCore.h" 00047 00048 typedef struct OfxMutex* OfxMutexHandle; 00049 00050 namespace OFX { 00051 00053 namespace MultiThread { 00054 00056 class Processor { 00057 private : 00059 static void staticMultiThreadFunction(unsigned int threadIndex, unsigned int threadMax, void *customArg); 00060 00061 public : 00063 Processor(); 00064 00066 virtual ~Processor(); 00067 00069 virtual void multiThreadFunction(unsigned int threadID, unsigned int nThreads) = 0; 00070 00075 virtual void multiThread(unsigned int nCPUs = 0); 00076 }; 00077 00079 bool isSpawnedThread(void); 00080 00082 unsigned int getNumCPUs(void); 00083 00085 unsigned int getThreadIndex(void); 00086 00088 class Mutex { 00089 protected : 00090 OfxMutexHandle _handle; 00092 public : 00094 Mutex(int lockCount = 0); 00095 00097 virtual ~Mutex(void); 00098 00100 void lock(); 00101 00103 void unlock(); 00104 00111 bool tryLock(); 00112 }; 00113 00116 class AutoMutex { 00117 protected : 00118 Mutex &_mutex; 00119 00120 public : 00122 explicit AutoMutex(Mutex &m) 00123 : _mutex(m) 00124 { 00125 _mutex.lock(); 00126 } 00127 00129 virtual ~AutoMutex() 00130 { 00131 _mutex.unlock(); 00132 } 00133 00134 }; 00135 }; 00136 }; 00137 00138 #endif
1.3.9.1