Search in sources :

Example 1 with TaskExecutor

use of io.xol.chunkstories.api.workers.TaskExecutor in project chunkstories by Hugobros3.

the class ConverterWorkers method dropAll.

public void dropAll() {
    CompoundFence readyAll = new CompoundFence();
    CompoundFence doneAll = new CompoundFence();
    SimpleFence atSignal = new SimpleFence();
    for (int i = 0; i < workers.length; i++) {
        SimpleFence ready = new SimpleFence();
        readyAll.add(ready);
        SimpleFence done = new SimpleFence();
        doneAll.add(done);
        scheduleTask(new Task() {

            @Override
            protected boolean task(TaskExecutor taskExecutor) {
                ready.signal();
                atSignal.traverse();
                ConverterWorkerThread cwt = (ConverterWorkerThread) taskExecutor;
                for (ChunkHolder holder : cwt.registeredCS_Holders) {
                    holder.unregisterUser(cwt);
                    cwt.chunksAquired--;
                }
                for (Heightmap summary : cwt.registeredCS_Summaries) summary.unregisterUser(cwt);
                cwt.registeredCS_Summaries.clear();
                cwt.registeredCS_Holders.clear();
                done.signal();
                return true;
            }
        });
    }
    readyAll.traverse();
    atSignal.signal();
    doneAll.traverse();
}
Also used : CompoundFence(io.xol.chunkstories.util.concurrency.CompoundFence) Task(io.xol.chunkstories.api.workers.Task) TaskExecutor(io.xol.chunkstories.api.workers.TaskExecutor) Heightmap(io.xol.chunkstories.api.world.heightmap.Heightmap) ChunkHolder(io.xol.chunkstories.api.world.chunk.ChunkHolder) SimpleFence(io.xol.chunkstories.util.concurrency.SimpleFence)

Aggregations

Task (io.xol.chunkstories.api.workers.Task)1 TaskExecutor (io.xol.chunkstories.api.workers.TaskExecutor)1 ChunkHolder (io.xol.chunkstories.api.world.chunk.ChunkHolder)1 Heightmap (io.xol.chunkstories.api.world.heightmap.Heightmap)1 CompoundFence (io.xol.chunkstories.util.concurrency.CompoundFence)1 SimpleFence (io.xol.chunkstories.util.concurrency.SimpleFence)1