Skip to content

Commit c9743fa

Browse files
committed
stupidly forgot these locks, also added clear(idx) which erases+unreserves
1 parent 58a9dce commit c9743fa

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

include/kit/kit.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,18 +479,21 @@ namespace kit
479479
}
480480

481481
unsigned add(std::shared_ptr<T> val) {
482+
auto l = this->lock();
482483
unsigned id = next();
483484
m_Group[id] = val;
484485
return id;
485486
}
486487

487488
bool add(unsigned id, std::shared_ptr<T> val) {
489+
auto l = this->lock();
488490
m_Group[id] = val;
489491
return true;
490492
}
491493

492494
unsigned remove_if(std::function<bool(const std::shared_ptr<T>&)> func)
493495
{
496+
auto l = this->lock();
494497
unsigned count = 0;
495498
for(auto itr = m_Group.begin();
496499
itr != m_Group.end();
@@ -504,6 +507,15 @@ namespace kit
504507
}
505508
return count;
506509
}
510+
void clear(unsigned idx) {
511+
auto l = this->lock();
512+
try{
513+
m_Reserved.erase(idx);
514+
}catch(const std::out_of_range&){}
515+
try{
516+
erase(idx);
517+
}catch(const std::out_of_range&){}
518+
}
507519
void clear() {
508520
auto l = this->lock();
509521
m_Unused=0;
@@ -538,21 +550,28 @@ namespace kit
538550
return m_Unused-1;
539551
}
540552

541-
unsigned reserve() { return next(); } // DEPRECATED
553+
unsigned reserve() {
554+
auto l = this->lock();
555+
return next();
556+
} // DEPRECATED
542557

543558
void reserve(unsigned idx){
559+
auto l = this->lock();
544560
m_Reserved.insert(idx);
545561
}
546562
unsigned reserve_next() {
563+
auto l = this->lock();
547564
unsigned id = next();
548565
reserve(id);
549566
return id;
550567
}
551568
bool is_reserved(unsigned idx) const {
569+
auto l = this->lock();
552570
return m_Reserved.find(idx) != m_Reserved.end();
553571
}
554572

555573
bool has(unsigned idx) {
574+
auto l = this->lock();
556575
return m_Group.find(idx) != m_Group.end();
557576
}
558577

0 commit comments

Comments
 (0)