Beatmup
recycle_bin.h
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 #pragma once
20 #include <mutex>
21 #include <vector>
22 #include "../context.h"
23 #include "../utils/lockable_object.h"
24 #include <initializer_list>
25 
26 namespace Beatmup {
27  namespace GL {
28 
29  /**
30  Stores references to GPU resources that will not be used anymore and needed to be recycled in a thread having access to the GPU.
31  GPU resources such as texture handles generally cannot be destroyed in a user thread due to OpenGL API restrictions.
32  They are kept in a RecycleBin until the application empties it, which launches a task running in the thread that can access the GPU.
33  */
34  class RecycleBin : public LockableObject {
35  public:
36  /**
37  A wrapper for a GPU resource. Destroyed in a GPU-aware thread when emptying the recycle bin.
38  */
39  class Item {
40  private:
41  Item(const Item&) = delete; //!< disabling copying constructor
42  public:
43  Item() {}
44  virtual ~Item() {}
45  };
46 
47  private:
48  std::vector<Item*> items;
51 
52  public:
54  ~RecycleBin();
55 
56  /**
57  Puts an item into the recycle bin
58  */
59  void put(Item* item);
60 
61  /**
62  Puts items into the recycle bin
63  */
64  void put(std::initializer_list<Item*> items);
65 
66  /**
67  Empty the bin destroying all the items in a GPU-aware thread
68  */
69  void emptyBin();
70  };
71  }
72 }
Task: an operation that can be executed by multiple threads in parallel.
Definition: parallelism.h:90
Basic class: task and memory management, any kind of static data.
Definition: context.h:59
A wrapper for a GPU resource.
Definition: recycle_bin.h:39
Item(const Item &)=delete
disabling copying constructor
Stores references to GPU resources that will not be used anymore and needed to be recycled in a threa...
Definition: recycle_bin.h:34
void put(Item *item)
Puts an item into the recycle bin.
Definition: recycle_bin.cpp:73
std::vector< Item * > items
Definition: recycle_bin.h:48
void emptyBin()
Empty the bin destroying all the items in a GPU-aware thread.
Definition: recycle_bin.cpp:91
AbstractTask * recycler
Definition: recycle_bin.h:50
RecycleBin(Context &ctx)
Definition: recycle_bin.cpp:63