115 void worker_push_one(
unsigned int slot, std::unique_ptr<T> & one,
signed int flag = 0);
122 void gather(std::deque<std::unique_ptr<T> > & ones, std::deque<signed int> & flag);
129 static const unsigned int cond_pending_data = 0;
130 static const unsigned int cond_full = 1;
134 std::unique_ptr<T> obj;
139 slot(
signed int val) { empty =
true; flag = val; };
140 slot(
const slot & ref) { obj.reset(); empty = ref.empty; index = ref.index; flag = ref.flag; };
143 unsigned int next_index;
144 std::vector<slot> table;
145 std::map<unsigned int, unsigned int> corres;
146 std::deque<unsigned int> empty_slot;
166 while(empty_slot.empty()
167 || ((empty_slot.size() == 1 && slot != next_index)
168 && corres.begin() != corres.end() && (corres.begin())->first != next_index))
169 verrou.wait(cond_full);
171 std::map<unsigned int, unsigned int>::iterator it = corres.find(slot);
174 if(it != corres.end())
175 throw exception_range(
"the ratelier_gather index to fill is already used");
177 index = empty_slot.back();
181 if(index >= table.size())
183 if( ! table[index].empty)
188 corres[slot] = index;
189 table[index].obj = std::move(one);
190 table[index].empty =
false;
191 table[index].index = slot;
192 table[index].flag = flag;
194 empty_slot.pop_back();
196 if(verrou.get_waiting_thread_count(cond_pending_data) > 0)
197 if(corres.find(next_index) != corres.end())
198 verrou.signal(cond_pending_data);
203 verrou.broadcast(cond_pending_data);
204 verrou.broadcast(cond_full);
218 std::map<unsigned int, unsigned int>::iterator it;
219 std::map<unsigned int, unsigned int>::iterator tmp;
225 while(it != corres.end())
227 if(it->first > next_index)
230 if(it->first == next_index)
235 if(it->second >= table.size())
237 if(table[it->second].index != next_index)
239 if(table[it->second].empty)
241 if( ! table[it->second].obj)
246 ones.push_back(std::move(table[it->second].obj));
247 flag.push_back(table[it->second].flag);
249 table[it->second].empty =
true;
250 empty_slot.push_back(it->second);
261 verrou.wait(cond_pending_data);
265 if(verrou.get_waiting_thread_count(cond_full) > 0)
266 verrou.broadcast(cond_full);
271 verrou.broadcast(cond_pending_data);
272 verrou.broadcast(cond_full);
277 if(ones.size() != flag.size())