Beatmup
recycle_bin.cpp
Go to the documentation of this file.
1
/*
2
Beatmup image and signal processing library
3
Copyright (C) 2019, lnstadrum
4
5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
14
15
You should have received a copy of the GNU General Public License
16
along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
#include "
recycle_bin.h
"
20
#include "../parallelism.h"
21
#include "../debug.h"
22
23
using namespace
Beatmup
;
24
using namespace
GL;
25
26
27
namespace
Internal
{
28
/**
29
A task to empty the recycle bin
30
*/
31
class
Recycler
:
public
AbstractTask
{
32
private
:
33
std::vector<RecycleBin::Item*>&
items
;
34
35
public
:
36
Recycler
(std::vector<RecycleBin::Item*>& items) : items(items) {}
37
38
39
TaskDeviceRequirement
getUsedDevices
()
const
{
40
return
TaskDeviceRequirement::GPU_OR_CPU;
41
}
42
43
44
bool
process
(
TaskThread
& thread) {
45
return
true
;
46
}
47
48
49
bool
processOnGPU
(
GraphicPipeline
& gpu,
TaskThread
& thread) {
50
for
(
auto
& item : items) {
51
RecycleBin::Item
* deleting = item;
52
item =
nullptr
;
53
if
(deleting)
54
delete
deleting;
55
}
56
items.clear();
57
return
true
;
58
}
59
};
60
}
61
62
63
RecycleBin::RecycleBin
(
Context
&
ctx
) :
ctx
(
ctx
) {
64
recycler
=
new
Internal::Recycler
(
items
);
65
}
66
67
68
RecycleBin::~RecycleBin
() {
69
delete
recycler
;
70
}
71
72
73
void
RecycleBin::put
(
RecycleBin::Item
* item) {
74
if
(item) {
75
lock
();
76
items
.push_back(item);
77
unlock
();
78
}
79
}
80
81
82
void
RecycleBin::put
(std::initializer_list<Item*> items) {
83
lock
();
84
for
(
auto
item :
items
)
85
if
(item)
86
this->items.push_back(item);
87
unlock
();
88
}
89
90
91
void
RecycleBin::emptyBin
() {
92
lock
();
93
if
(
items
.size() > 0)
94
ctx
.
performTask
(*
recycler
);
95
unlock
();
96
}
Beatmup::AbstractTask
Task: an operation that can be executed by multiple threads in parallel.
Definition:
parallelism.h:90
Beatmup::AbstractTask::TaskDeviceRequirement
TaskDeviceRequirement
Specifies which device (CPU and/or GPU) is used to run the task.
Definition:
parallelism.h:95
Beatmup::Context
Basic class: task and memory management, any kind of static data.
Definition:
context.h:59
Beatmup::Context::performTask
float performTask(AbstractTask &task, const PoolIndex pool=DEFAULT_POOL)
Performs a given task.
Definition:
context.cpp:240
Beatmup::GL::RecycleBin::Item
A wrapper for a GPU resource.
Definition:
recycle_bin.h:39
Beatmup::GL::RecycleBin::put
void put(Item *item)
Puts an item into the recycle bin.
Definition:
recycle_bin.cpp:73
Beatmup::GL::RecycleBin::items
std::vector< Item * > items
Definition:
recycle_bin.h:48
Beatmup::GL::RecycleBin::~RecycleBin
~RecycleBin()
Definition:
recycle_bin.cpp:68
Beatmup::GL::RecycleBin::emptyBin
void emptyBin()
Empty the bin destroying all the items in a GPU-aware thread.
Definition:
recycle_bin.cpp:91
Beatmup::GL::RecycleBin::recycler
AbstractTask * recycler
Definition:
recycle_bin.h:50
Beatmup::GL::RecycleBin::ctx
Context & ctx
Definition:
recycle_bin.h:49
Beatmup::GL::RecycleBin::RecycleBin
RecycleBin(Context &ctx)
Definition:
recycle_bin.cpp:63
Beatmup::GraphicPipeline
Internal low-level GPU control API.
Definition:
pipeline.h:33
Beatmup::LockableObject::unlock
void unlock()
Definition:
lockable_object.h:30
Beatmup::LockableObject::lock
void lock()
Definition:
lockable_object.h:28
Beatmup::TaskThread
Thread executing tasks.
Definition:
parallelism.h:154
Internal::Recycler
A task to empty the recycle bin.
Definition:
recycle_bin.cpp:31
Internal::Recycler::process
bool process(TaskThread &thread)
Executes the task on CPU within a given thread.
Definition:
recycle_bin.cpp:44
Internal::Recycler::processOnGPU
bool processOnGPU(GraphicPipeline &gpu, TaskThread &thread)
Executes the task on GPU.
Definition:
recycle_bin.cpp:49
Internal::Recycler::Recycler
Recycler(std::vector< RecycleBin::Item * > &items)
Definition:
recycle_bin.cpp:36
Internal::Recycler::items
std::vector< RecycleBin::Item * > & items
Definition:
recycle_bin.cpp:33
Internal::Recycler::getUsedDevices
TaskDeviceRequirement getUsedDevices() const
Communicates devices (CPU and/or GPU) the task is run on.
Definition:
recycle_bin.cpp:39
Beatmup
Definition:
basic_types.h:22
Internal
Beatmup internal declarations.
Definition:
basic_types.h:78
recycle_bin.h
ctx
Beatmup::Context * ctx
Definition:
wrapper_core.cpp:80
core
gpu
recycle_bin.cpp
Generated on Tue Nov 21 2023 13:54:26 for Beatmup by
1.9.1