Removed unused ParallelQueue
This commit is contained in:
parent
dc3584cefc
commit
915f43503e
8 changed files with 2 additions and 318 deletions
|
@ -5,7 +5,7 @@ CanvasFragment::CanvasFragment()
|
|||
}
|
||||
|
||||
CanvasFragment::CanvasFragment(double z, const Vector3 &location, int client, bool opaque):
|
||||
z(z), location(location), client(client), opaque(opaque)
|
||||
opaque(opaque), z(z), location(location), client(client)
|
||||
{
|
||||
color = COLOR_WHITE;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include "WaterRenderer.h"
|
||||
#include "TexturesRenderer.h"
|
||||
#include "Scenery.h"
|
||||
#include "ParallelQueue.h"
|
||||
#include "CanvasPortion.h"
|
||||
#include "CanvasFragment.h"
|
||||
|
||||
|
@ -189,38 +188,9 @@ void TerrainRasterizer::getTessellationInfo(CanvasPortion* canvas, int displaced
|
|||
}
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
TerrainRasterizer* rasterizer;
|
||||
CanvasPortion *canvas;
|
||||
TerrainRasterizer::TerrainChunkInfo chunk;
|
||||
} ParallelRasterInfo;
|
||||
|
||||
static int _parallelJobCallback(ParallelQueue*, int, void* data, int stopping)
|
||||
{
|
||||
ParallelRasterInfo* info = (ParallelRasterInfo*)data;
|
||||
|
||||
if (!stopping)
|
||||
{
|
||||
info->rasterizer->tessellateChunk(info->canvas, &info->chunk, info->chunk.detail_hint);
|
||||
}
|
||||
|
||||
delete info;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int TerrainRasterizer::processChunk(CanvasPortion* canvas, TerrainChunkInfo* chunk, double progress)
|
||||
{
|
||||
ParallelRasterInfo* info = new ParallelRasterInfo;
|
||||
|
||||
info->rasterizer = this;
|
||||
info->canvas = canvas;
|
||||
info->chunk = *chunk;
|
||||
|
||||
if (!queue->addJob(_parallelJobCallback, info))
|
||||
{
|
||||
delete info;
|
||||
}
|
||||
tessellateChunk(canvas, chunk, chunk->detail_hint);
|
||||
|
||||
renderer->render_progress = 0.05 * progress;
|
||||
return !renderer->render_interrupt;
|
||||
|
@ -228,13 +198,9 @@ int TerrainRasterizer::processChunk(CanvasPortion* canvas, TerrainChunkInfo* chu
|
|||
|
||||
void TerrainRasterizer::rasterizeToCanvas(CanvasPortion *canvas)
|
||||
{
|
||||
queue = new ParallelQueue();
|
||||
|
||||
renderer->render_progress = 0.0;
|
||||
getTessellationInfo(canvas, 0);
|
||||
renderer->render_progress = 0.05;
|
||||
|
||||
queue->wait();
|
||||
}
|
||||
|
||||
Color TerrainRasterizer::shadeFragment(const CanvasFragment &fragment) const
|
||||
|
|
|
@ -45,9 +45,6 @@ public:
|
|||
|
||||
virtual void rasterizeToCanvas(CanvasPortion* canvas) override;
|
||||
virtual Color shadeFragment(const CanvasFragment &fragment) const override;
|
||||
|
||||
private:
|
||||
ParallelQueue* queue;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include "SoftwareRenderer.h"
|
||||
#include "WaterRenderer.h"
|
||||
#include "ParallelQueue.h"
|
||||
#include "CanvasFragment.h"
|
||||
|
||||
WaterRasterizer::WaterRasterizer(SoftwareRenderer* renderer, int client_id):
|
||||
|
|
|
@ -1,181 +0,0 @@
|
|||
#include "ParallelQueue.h"
|
||||
|
||||
#include "Mutex.h"
|
||||
#include "Thread.h"
|
||||
#include "System.h"
|
||||
#include <cassert>
|
||||
|
||||
#define QUEUE_SIZE 1000
|
||||
|
||||
static void* _queueThreadCallback(ParallelQueue* queue)
|
||||
{
|
||||
ParallelQueue::ParallelJob* job;
|
||||
|
||||
while (!queue->stopping)
|
||||
{
|
||||
/* Try to take a job */
|
||||
queue->lock->acquire();
|
||||
job = queue->jobs + queue->jobs_index_pending;
|
||||
if (job->state == ParallelQueue::JOB_STATE_PENDING)
|
||||
{
|
||||
if (queue->jobs_index_pending >= QUEUE_SIZE - 1)
|
||||
{
|
||||
queue->jobs_index_pending = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
queue->jobs_index_pending++;
|
||||
}
|
||||
job->state = ParallelQueue::JOB_STATE_PROCESSING;
|
||||
}
|
||||
else
|
||||
{
|
||||
job = NULL;
|
||||
}
|
||||
queue->lock->release();
|
||||
|
||||
if (job)
|
||||
{
|
||||
/* Process the job */
|
||||
job->process(queue, job->id, job->data, 0);
|
||||
|
||||
queue->lock->acquire();
|
||||
if (queue->collect)
|
||||
{
|
||||
job->state = ParallelQueue::JOB_STATE_TOCOLLECT;
|
||||
/* TODO jobs_index_collect ? */
|
||||
}
|
||||
else
|
||||
{
|
||||
job->state = ParallelQueue::JOB_STATE_FREE;
|
||||
queue->jobs_count--;
|
||||
}
|
||||
queue->lock->release();
|
||||
}
|
||||
else
|
||||
{
|
||||
Thread::timeSleepMs(50);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ParallelQueue::ParallelQueue(int collect)
|
||||
{
|
||||
int i;
|
||||
|
||||
assert(!collect); /* Not fully implemented yet ! */
|
||||
|
||||
this->collect = collect;
|
||||
this->stopping = 0;
|
||||
this->lock = new Mutex();
|
||||
|
||||
this->jobs = new ParallelJob[QUEUE_SIZE];
|
||||
for (i = 0; i < QUEUE_SIZE; i++)
|
||||
{
|
||||
this->jobs[i].state = JOB_STATE_FREE;
|
||||
}
|
||||
this->jobs_count = 0;
|
||||
this->jobs_index_free = 0;
|
||||
this->jobs_index_collect = 0;
|
||||
this->jobs_index_pending = 0;
|
||||
this->jobs_next_id = 1;
|
||||
|
||||
/* Start workers */
|
||||
this->workers_count = System::getCoreCount();
|
||||
this->workers = new Thread*[this->workers_count];
|
||||
for (i = 0; i < this->workers_count; i++)
|
||||
{
|
||||
this->workers[i] = new Thread((ThreadFunction)_queueThreadCallback);
|
||||
this->workers[i]->start(this);
|
||||
}
|
||||
}
|
||||
|
||||
ParallelQueue::~ParallelQueue()
|
||||
{
|
||||
interrupt();
|
||||
|
||||
assert(not collect or jobs[jobs_index_collect].state != JOB_STATE_TOCOLLECT);
|
||||
assert(jobs_count == 0);
|
||||
|
||||
delete lock;
|
||||
delete[] jobs;
|
||||
delete[] workers;
|
||||
}
|
||||
|
||||
void ParallelQueue::interrupt()
|
||||
{
|
||||
int i;
|
||||
|
||||
if (not stopping)
|
||||
{
|
||||
stopping = 1;
|
||||
|
||||
for (i = 0; i < workers_count; i++)
|
||||
{
|
||||
workers[i]->join();
|
||||
delete workers[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ParallelQueue::wait()
|
||||
{
|
||||
while (jobs_count > 0)
|
||||
{
|
||||
Thread::timeSleepMs(100);
|
||||
}
|
||||
}
|
||||
|
||||
int ParallelQueue::addJob(FuncParallelJob func_process, void* data)
|
||||
{
|
||||
if (stopping)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Wait for a free slot */
|
||||
while (jobs[jobs_index_free].state != JOB_STATE_FREE)
|
||||
{
|
||||
Thread::timeSleepMs(50);
|
||||
if (stopping)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Prepare the job */
|
||||
ParallelJob job;
|
||||
job.state = JOB_STATE_PENDING;
|
||||
job.id = jobs_next_id++;
|
||||
job.process = func_process;
|
||||
job.data = data;
|
||||
|
||||
/* Add the job to the queue */
|
||||
lock->acquire();
|
||||
if (stopping)
|
||||
{
|
||||
lock->release();
|
||||
return 0;
|
||||
}
|
||||
jobs[jobs_index_free] = job;
|
||||
if (jobs_index_free >= QUEUE_SIZE - 1)
|
||||
{
|
||||
jobs_index_free = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
jobs_index_free++;
|
||||
}
|
||||
jobs_count++;
|
||||
assert(jobs_count <= QUEUE_SIZE);
|
||||
lock->release();
|
||||
|
||||
return job.id;
|
||||
}
|
||||
|
||||
int ParallelQueue::collectJobs(FuncParallelJob)
|
||||
{
|
||||
/* TODO */
|
||||
return 0;
|
||||
}
|
|
@ -1,94 +0,0 @@
|
|||
#ifndef PARALLELQUEUE_H
|
||||
#define PARALLELQUEUE_H
|
||||
|
||||
#include "system_global.h"
|
||||
|
||||
namespace paysages {
|
||||
namespace system {
|
||||
|
||||
class SYSTEMSHARED_EXPORT ParallelQueue
|
||||
{
|
||||
public:
|
||||
typedef int (*FuncParallelJob)(ParallelQueue* queue, int job_id, void* data, int stopping);
|
||||
|
||||
typedef enum
|
||||
{
|
||||
JOB_STATE_FREE,
|
||||
JOB_STATE_PENDING,
|
||||
JOB_STATE_PROCESSING,
|
||||
JOB_STATE_TOCOLLECT
|
||||
} EnumJobState;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
EnumJobState state;
|
||||
int id;
|
||||
FuncParallelJob process;
|
||||
void* data;
|
||||
} ParallelJob;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Create a parallel processing queue.
|
||||
*
|
||||
* This queue will use parallel workers to process jobs added to it.
|
||||
* @param collect True to collect finished jobs and wait for a call to collectJobs, False to discard finished jobs.
|
||||
* @return The newly allocated queue.
|
||||
*/
|
||||
ParallelQueue(int collect=0);
|
||||
|
||||
/**
|
||||
* Delete a parallel queue.
|
||||
*
|
||||
* This will interrupt the queue.
|
||||
* If the queue is in collect mode, you should call interrupt, then collectJobs, before calling this.
|
||||
*/
|
||||
~ParallelQueue();
|
||||
|
||||
/**
|
||||
* Interrupt the queue processing.
|
||||
*
|
||||
* This will wait for running jobs to end, cancel pending jobs (still calling their callbacks with stopping=1) and
|
||||
* refuse future jobs.
|
||||
*/
|
||||
void interrupt();
|
||||
|
||||
/**
|
||||
* Wait for all jobs to finish.
|
||||
*
|
||||
* This function will return as soon as there is no pending jobs. It is recommended to stop feeding the queue, or this
|
||||
* function may never return.
|
||||
*/
|
||||
void wait();
|
||||
|
||||
/**
|
||||
* Add a job to the queue.
|
||||
*
|
||||
* Don't call this method concurrently from several threads.
|
||||
* @param func_process The function that will be called for the job processing.
|
||||
* @param data The data that will be passed to the callback.
|
||||
* @return The job ID, 0 if the queue doesn't accept jobs.
|
||||
*/
|
||||
int addJob(FuncParallelJob func_process, void* data);
|
||||
|
||||
int collectJobs(FuncParallelJob func_collect);
|
||||
|
||||
int collect;
|
||||
volatile int stopping;
|
||||
Mutex* lock;
|
||||
|
||||
int workers_count;
|
||||
Thread** workers;
|
||||
|
||||
ParallelJob* jobs;
|
||||
int jobs_count; /** Number of jobs in queue (all status except JOB_STATE_FREE) */
|
||||
int jobs_index_free; /** Index of next free position */
|
||||
int jobs_index_collect; /** Index of first job to collect */
|
||||
int jobs_index_pending; /** Index of first pending job to process */
|
||||
int jobs_next_id;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // PARALLELQUEUE_H
|
|
@ -21,7 +21,6 @@ SOURCES += \
|
|||
RandomGenerator.cpp \
|
||||
Memory.cpp \
|
||||
ParallelWork.cpp \
|
||||
ParallelQueue.cpp \
|
||||
CacheFile.cpp \
|
||||
PictureWriter.cpp \
|
||||
Logs.cpp \
|
||||
|
@ -38,7 +37,6 @@ HEADERS += \
|
|||
RandomGenerator.h \
|
||||
Memory.h \
|
||||
ParallelWork.h \
|
||||
ParallelQueue.h \
|
||||
CacheFile.h \
|
||||
PictureWriter.h \
|
||||
Logs.h \
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
namespace paysages {
|
||||
namespace system {
|
||||
class PackStream;
|
||||
class ParallelQueue;
|
||||
class ParallelWork;
|
||||
class ParallelPool;
|
||||
class ParallelWorker;
|
||||
|
|
Loading…
Reference in a new issue