diff --git a/src/nrncvode/netcvode.cpp b/src/nrncvode/netcvode.cpp index 1573d190e4..83de062306 100644 --- a/src/nrncvode/netcvode.cpp +++ b/src/nrncvode/netcvode.cpp @@ -1034,7 +1034,7 @@ Object** NetCvode::netconlist() { NetCvodeThreadData::NetCvodeThreadData() { tpool_ = new TQItemPool(1000, 1); // tqe_ accessed only by thread i so no locking - tqe_ = new TQueue(tpool_, 0); + tqe_ = new TQueue(tpool_); sepool_ = new SelfEventPool(1000, 1); selfqueue_ = nullptr; psl_thr_ = nullptr; @@ -2794,7 +2794,7 @@ void NetCvode::clear_events() { d.ite_cnt_ = 0; if (nrn_use_selfqueue_) { if (!d.selfqueue_) { - d.selfqueue_ = new SelfQueue(d.tpool_, 0); + d.selfqueue_ = new SelfQueue(d.tpool_); } else { d.selfqueue_->remove_all(); } diff --git a/src/nrncvode/tqueue.cpp b/src/nrncvode/tqueue.cpp index 8e51035838..a12fed2f1b 100644 --- a/src/nrncvode/tqueue.cpp +++ b/src/nrncvode/tqueue.cpp @@ -51,8 +51,8 @@ static void prnt(const TQItem* b, int level) { Printf("%g %c %d Q=%p D=%p\n", b->t_, b->data_ ? 'x' : 'o', b->cnt_, b, b->data_); } -TQueue::TQueue(TQItemPool* tp, int mkmut) { - MUTCONSTRUCT(mkmut) + +TQueue::TQueue(TQItemPool* tp) { tpool_ = tp; nshift_ = 0; sptree_ = new SPTREE; @@ -77,7 +77,6 @@ TQueue::~TQueue() { remove(q); } delete binq_; - MUTDESTRUCT } void TQueue::deleteitem(TQItem* i) { @@ -85,7 +84,6 @@ void TQueue::deleteitem(TQItem* i) { } void TQueue::print() { - MUTLOCK if (least_) { prnt(least_, 0); } @@ -93,11 +91,9 @@ void TQueue::print() { for (TQItem* q = binq_->first(); q; q = binq_->next(q)) { prnt(q, 0); } - MUTUNLOCK } void TQueue::forall_callback(void (*f)(const TQItem*, int)) { - MUTLOCK if (least_) { f(least_, 0); } @@ -105,7 +101,6 @@ void TQueue::forall_callback(void (*f)(const TQItem*, int)) { for (TQItem* q = binq_->first(); q; q = binq_->next(q)) { f(q, 0); } - MUTUNLOCK } void TQueue::check(const char* mes) {} @@ -122,9 +117,7 @@ TQItem* TQueue::second_least(double t) { } void TQueue::move_least(double tnew) { - MUTLOCK move_least_nolock(tnew); - MUTUNLOCK } void TQueue::move_least_nolock(double tnew) { @@ -142,7 +135,6 @@ void TQueue::move_least_nolock(double tnew) { } void TQueue::move(TQItem* i, double tnew) { - MUTLOCK STAT(nmove) if (i == least_) { move_least_nolock(tnew); @@ -156,7 +148,6 @@ void TQueue::move(TQItem* i, double tnew) { i->t_ = tnew; spenq(i, sptree_); } - MUTUNLOCK } void TQueue::statistics() { @@ -184,7 +175,6 @@ void TQueue::spike_stat(double* d) { } TQItem* TQueue::insert(double t, void* d) { - MUTLOCK STAT(ninsert); TQItem* i = tpool_->alloc(); i->data_ = d; @@ -198,18 +188,15 @@ TQItem* TQueue::insert(double t, void* d) { } else { spenq(i, sptree_); } - MUTUNLOCK return i; } TQItem* TQueue::enqueue_bin(double td, void* d) { - MUTLOCK STAT(ninsert); TQItem* i = tpool_->alloc(); i->data_ = d; i->t_ = td; binq_->enqueue(td, i); - MUTUNLOCK return i; } @@ -219,7 +206,6 @@ void TQueue::release(TQItem* q) { } void TQueue::remove(TQItem* q) { - MUTLOCK STAT(nrem); if (q) { if (q == least_) { @@ -235,12 +221,10 @@ void TQueue::remove(TQItem* q) { } tpool_->hpfree(q); } - MUTUNLOCK } TQItem* TQueue::atomic_dq(double tt) { TQItem* q = 0; - MUTLOCK if (least_ && least_->t_ <= tt) { q = least_; STAT(nrem); @@ -250,13 +234,11 @@ TQItem* TQueue::atomic_dq(double tt) { least_ = nullptr; } } - MUTUNLOCK return q; } TQItem* TQueue::find(double t) { TQItem* q; - MUTLOCK // search only in the splay tree. if this is a bug then fix it. STAT(nfind) if (t == least_t_nolock()) { @@ -264,7 +246,6 @@ TQItem* TQueue::find(double t) { } else { q = splookup(t, sptree_); } - MUTUNLOCK return (q); } @@ -390,17 +371,14 @@ void BinQ::remove(TQItem* q) { } } -SelfQueue::SelfQueue(TQItemPool* tp, int mkmut) { - MUTCONSTRUCT(mkmut) +SelfQueue::SelfQueue(TQItemPool* tp) { tpool_ = tp; head_ = nullptr; } SelfQueue::~SelfQueue() { remove_all(); - MUTDESTRUCT } TQItem* SelfQueue::insert(void* d) { - MUTLOCK TQItem* q = tpool_->alloc(); q->left_ = nullptr; q->right_ = head_; @@ -409,11 +387,9 @@ TQItem* SelfQueue::insert(void* d) { } head_ = q; q->data_ = d; - MUTUNLOCK return q; } void* SelfQueue::remove(TQItem* q) { - MUTLOCK if (q->left_) { q->left_->right_ = q->right_; } @@ -424,14 +400,11 @@ void* SelfQueue::remove(TQItem* q) { head_ = q->right_; } tpool_->hpfree(q); - MUTUNLOCK return q->data_; } void SelfQueue::remove_all() { - MUTLOCK for (TQItem* q = first(); q; q = next(q)) { tpool_->hpfree(q); } head_ = nullptr; - MUTUNLOCK } diff --git a/src/nrncvode/tqueue.hpp b/src/nrncvode/tqueue.hpp index 4ee6cf23cc..0f8fa0c34f 100644 --- a/src/nrncvode/tqueue.hpp +++ b/src/nrncvode/tqueue.hpp @@ -4,7 +4,6 @@ #include -#include #include #include "tqitem.hpp" @@ -62,26 +61,13 @@ class BinQ { class TQueue { public: - TQueue(TQItemPool*, int mkmut = 0); + explicit TQueue(TQItemPool*); virtual ~TQueue(); TQItem* least() { return least_; } TQItem* second_least(double t); -#if NRN_ENABLE_THREADS - double least_t() { - double tt; - MUTLOCK; - if (least_) { - tt = least_->t_; - } else { - tt = 1e15; - } - MUTUNLOCK; - return tt; - } -#else double least_t() { if (least_) { return least_->t_; @@ -89,7 +75,6 @@ class TQueue { return 1e15; } } -#endif TQItem* atomic_dq(double til); TQItem* insert(double t, void* data); TQItem* enqueue_bin(double t, void* data); @@ -137,7 +122,6 @@ class TQueue { BinQ* binq_; TQItem* least_; TQItemPool* tpool_; - MUTDEC #if COLLECT_TQueue_STATISTICS unsigned long ninsert, nrem, nleast, nbal, ncmplxrem; unsigned long ncompare, nleastsrch, nfind, nfindsrch, nmove, nfastmove; @@ -146,7 +130,7 @@ class TQueue { class SelfQueue { // not really a queue but a doubly linked list for fast public: // insertion, deletion, iteration - SelfQueue(TQItemPool*, int mkmut = 0); + explicit SelfQueue(TQItemPool*); virtual ~SelfQueue(); TQItem* insert(void*); void* remove(TQItem*); @@ -161,5 +145,4 @@ class SelfQueue { // not really a queue but a doubly linked list for fast private: TQItem* head_; TQItemPool* tpool_; - MUTDEC };