2525#include < thread>
2626#include < utility>
2727#include < vector>
28+ #include < unordered_map>
2829
2930// #include "profiler.hpp"
3031
@@ -55,16 +56,6 @@ class Queue {
5556 return idleStreamFuture;
5657 }
5758
58- void extendQueue () {
59- if (!constructFunc.has_value ()) {
60- return ;
61- }
62- size_t streamSize = streams.size ();
63- streams.push_back (streamSize - 1 );
64- inferRequests.reserve (streams.size ());
65- inferRequests.push_back (constructFunc.value ()());
66- }
67-
6859 std::optional<int > tryToGetIdleStream () {
6960 // OVMS_PROFILE_FUNCTION();
7061 int value;
@@ -79,6 +70,7 @@ class Queue {
7970 return value;
8071 }
8172 }
73+
8274 /* *
8375 * @brief Release stream after execution
8476 */
@@ -104,16 +96,13 @@ class Queue {
10496 /* *
10597 * @brief Constructor with initialization
10698 */
107- // change constructor so that it can also accept lambda which returns T. This lambda
108- // is optional but if exists it will be used to construct T objects
109- Queue (int streamsLength, std::optional<std::function<T()>> constructFunc = std::nullopt ) : streams(streamsLength),
110- constructFunc (constructFunc),
99+ Queue (int streamsLength) :
100+ streams (streamsLength),
111101 front_idx{0 },
112102 back_idx{0 } {
113103 for (int i = 0 ; i < streamsLength; ++i) {
114104 streams[i] = i;
115105 }
116- streams.reserve (50 );
117106 }
118107
119108 /* *
@@ -128,7 +117,7 @@ class Queue {
128117 * @brief Vector representing circular buffer for infer queue
129118 */
130119 std::vector<int > streams;
131- std::optional<std::function<T()>> constructFunc = std:: nullopt ;
120+
132121 /* *
133122 * @brief Index of the front of the idle streams list
134123 */
@@ -147,7 +136,7 @@ class Queue {
147136 /* *
148137 *
149138 */
150- std::vector< T> inferRequests;
139+ std::unordered_map< int , T> inferRequests;
151140 std::queue<std::promise<int >> promises;
152141};
153142} // namespace ovms
0 commit comments