2 Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
\r
5 Physics Effects is open software; you can redistribute it and/or
\r
6 modify it under the terms of the BSD License.
\r
8 Physics Effects is distributed in the hope that it will be useful,
\r
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
\r
11 See the BSD License for more details.
\r
13 A copy of the BSD License is distributed with
\r
14 Physics Effects under the filename: physics_effects_license.txt
\r
17 #ifndef _SCE_PFX_TASK_MANAGER_H
\r
18 #define _SCE_PFX_TASK_MANAGER_H
\r
20 #include "../../base_level/base/pfx_common.h"
\r
21 #include "../../base_level/base/pfx_heap_manager.h"
\r
22 #include "pfx_sync_components.h"
\r
24 #define SCE_PFX_IO_BUFF_BYTES 1048576
\r
26 namespace PhysicsEffects {
\r
28 //J 並列処理するためのタスクマネージャクラス
\r
29 //E Task manager class for parallel computation
\r
35 PfxBarrier *barrier;
\r
36 PfxCriticalSection *criticalSection;
\r
41 typedef void (*PfxTaskEntry)(PfxTaskArg *arg);
\r
43 class PfxTaskManager
\r
46 PfxUInt32 m_numTasks;
\r
47 PfxUInt32 m_maxTasks;
\r
48 SCE_PFX_PADDING(1,4)
\r
49 PfxUInt8 SCE_PFX_ALIGNED(16) m_ioBuff[SCE_PFX_IO_BUFF_BYTES];
\r
50 PfxHeapManager m_pool;
\r
51 PfxHeapManager m_ioPool;
\r
52 PfxTaskEntry m_taskEntry;
\r
53 PfxTaskArg *m_taskArg;
\r
54 SCE_PFX_PADDING(2,8)
\r
56 PfxTaskManager() : m_pool(NULL,0),m_ioPool(NULL,0) {}
\r
59 void *allocate(size_t bytes) {return m_ioPool.allocate(bytes);}
\r
60 void deallocate(void *p) {m_ioPool.deallocate(p);}
\r
61 void clearPool() {m_ioPool.clear();}
\r
63 virtual PfxUInt32 getSharedParam(int i) = 0;
\r
64 virtual void setSharedParam(int i,PfxUInt32 p) = 0;
\r
66 virtual void startTask(int taskId,void *io,PfxUInt32 data1,PfxUInt32 data2,PfxUInt32 data3,PfxUInt32 data4) = 0;
\r
67 virtual void waitTask(int &taskId,PfxUInt32 &data1,PfxUInt32 &data2,PfxUInt32 &data3,PfxUInt32 &data4) = 0;
\r
69 virtual void setTaskEntry(void *entry) {m_taskEntry = (PfxTaskEntry)entry;}
\r
72 PfxTaskManager(PfxUInt32 numTasks,PfxUInt32 maxTasks,void *workBuff,PfxUInt32 workBytes)
\r
73 : m_pool((unsigned char*)workBuff,workBytes),m_ioPool(m_ioBuff,SCE_PFX_IO_BUFF_BYTES)
\r
75 SCE_PFX_ASSERT(numTasks>0);
\r
76 SCE_PFX_ASSERT(numTasks<=maxTasks);
\r
77 m_numTasks = numTasks;
\r
78 m_maxTasks = maxTasks;
\r
79 m_taskArg = (PfxTaskArg*)m_pool.allocate(sizeof(PfxTaskArg)*m_maxTasks);
\r
82 virtual ~PfxTaskManager()
\r
87 virtual PfxUInt32 getNumTasks() const {return m_numTasks;}
\r
88 virtual void setNumTasks(PfxUInt32 tasks) {m_numTasks = SCE_PFX_MIN(tasks,m_maxTasks);}
\r
90 virtual void initialize() = 0;
\r
91 virtual void finalize() = 0;
\r
94 } //namespace PhysicsEffects
\r
96 #endif // _SCE_PFX_TASK_MANAGER_H