Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make MutexPool an allocator #2766

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/nrncvode/hocevent.cpp
@@ -1,10 +1,10 @@
#include <objcmd.h>
#include <pool.hpp>
#include <utils/pool.hpp>
#include <netcon.h>
#include <nrnoc2iv.h>
#include <mymath.h>

using HocEventPool = MutexPool<HocEvent>;
using HocEventPool = Pool<HocEvent, PoolMutexed>;
HocEventPool* HocEvent::hepool_;

HocEvent::HocEvent() {
Expand All @@ -27,11 +27,11 @@ HocEvent* HocEvent::alloc(const char* stmt, Object* ppobj, int reinit, Object* p
if (!hepool_) {
nrn_hoc_lock();
if (!hepool_) {
hepool_ = new HocEventPool(100, 1);
hepool_ = new HocEventPool();
}
nrn_hoc_unlock();
}
HocEvent* he = hepool_->alloc();
HocEvent* he = hepool_->allocate();
he->stmt_ = nullptr;
he->ppobj_ = ppobj;
he->reinit_ = reinit;
Expand All @@ -48,7 +48,7 @@ void HocEvent::hefree() {
delete stmt_;
stmt_ = nullptr;
}
hepool_->hpfree(this);
hepool_->deallocate(this);
}

void HocEvent::clear() {
Expand Down
4 changes: 2 additions & 2 deletions src/nrncvode/netcon.h
Expand Up @@ -7,7 +7,7 @@
#include "neuron/container/data_handle.hpp"
#include "nrnmpi.h"
#include "nrnneosm.h"
#include "pool.hpp"
#include "utils/pool.hpp"
#include "tqitem.hpp"

#include <InterViews/observe.h>
Expand All @@ -29,7 +29,7 @@ class TQueue;
struct NrnThread;
class NetCvode;
class HocEvent;
using HocEventPool = MutexPool<HocEvent>;
using HocEventPool = Pool<HocEvent, PoolMutexed>;
class HocCommand;
struct STETransition;
class IvocVect;
Expand Down
13 changes: 6 additions & 7 deletions src/nrncvode/netcvode.cpp
Expand Up @@ -13,7 +13,7 @@
#include "parse.hpp"
#include "cvodeobj.h"
#include "hoclist.h"
#include "pool.hpp"
#include "utils/pool.hpp"
#include "tqueue.hpp"
#include "ocobserv.h"
#include "nrnneosm.h"
Expand Down Expand Up @@ -427,7 +427,6 @@ struct InterThreadEvent {
};

typedef std::vector<WatchCondition*> WatchList;
using SelfEventPool = MutexPool<SelfEvent>;
typedef std::vector<TQItem*> TQList;

// allows marshalling of all items in the event queue that need to be
Expand Down Expand Up @@ -1032,10 +1031,10 @@ Object** NetCvode::netconlist() {

#define ITE_SIZE 10
NetCvodeThreadData::NetCvodeThreadData() {
tpool_ = new TQItemPool(1000, 1);
tpool_ = new TQItemPool();
JCGoran marked this conversation as resolved.
Show resolved Hide resolved
// tqe_ accessed only by thread i so no locking
tqe_ = new TQueue(tpool_, 0);
sepool_ = new SelfEventPool(1000, 1);
sepool_ = new SelfEventPool();
selfqueue_ = nullptr;
psl_thr_ = nullptr;
tq_ = nullptr;
Expand Down Expand Up @@ -2295,7 +2294,7 @@ void nrn_net_send(Datum* v, double* weight, Point_process* pnt, double td, doubl
STATISTICS(SelfEvent::selfevent_send_);
NrnThread* nt = PP2NT(pnt);
NetCvodeThreadData& p = net_cvode_instance->p[nt->id];
SelfEvent* se = p.sepool_->alloc();
SelfEvent* se = p.sepool_->allocate();
se->flag_ = flag;
se->target_ = pnt;
se->weight_ = weight;
Expand Down Expand Up @@ -2331,7 +2330,7 @@ void artcell_net_send(Datum* v, double* weight, Point_process* pnt, double td, d
STATISTICS(SelfEvent::selfevent_send_);
NrnThread* nt = PP2NT(pnt);
NetCvodeThreadData& p = net_cvode_instance->p[nt->id];
SelfEvent* se = p.sepool_->alloc();
SelfEvent* se = p.sepool_->allocate();
se->flag_ = flag;
se->target_ = pnt;
se->weight_ = weight;
Expand Down Expand Up @@ -3366,7 +3365,7 @@ void SelfEvent::call_net_receive(NetCvode* ns) {
}
NetCvodeThreadData& nctd = ns->p[PP2NT(target_)->id];
--nctd.unreffed_event_cnt_;
nctd.sepool_->hpfree(this);
nctd.sepool_->deallocate(this);
}

void SelfEvent::pr(const char* s, double tt, NetCvode* ns) {
Expand Down
2 changes: 1 addition & 1 deletion src/nrncvode/netcvode.h
Expand Up @@ -20,7 +20,7 @@ using PreSynTable = std::unordered_map<neuron::container::data_handle<double>, P
class NetCon;
class DiscreteEvent;
class SelfEvent;
using SelfEventPool = MutexPool<SelfEvent>;
using SelfEventPool = Pool<SelfEvent, PoolMutexed>;
struct hoc_Item;
class PlayRecord;
class IvocVect;
Expand Down
135 changes: 0 additions & 135 deletions src/nrncvode/pool.hpp

This file was deleted.

17 changes: 8 additions & 9 deletions src/nrncvode/tqueue.cpp
Expand Up @@ -7,7 +7,6 @@
#include <section.h>

#include "tqueue.hpp"
#include "pool.hpp"

#define PROFILE 0
#include "profile.h"
Expand Down Expand Up @@ -81,7 +80,7 @@
}

void TQueue::deleteitem(TQItem* i) {
tpool_->hpfree(i);
tpool_->deallocate(i);
}

void TQueue::print() {
Expand Down Expand Up @@ -186,7 +185,7 @@
TQItem* TQueue::insert(double t, void* d) {
MUTLOCK
STAT(ninsert);
TQItem* i = tpool_->alloc();
TQItem* i = tpool_->allocate();
i->data_ = d;
i->t_ = t;
i->cnt_ = -1;
Expand All @@ -205,7 +204,7 @@
TQItem* TQueue::enqueue_bin(double td, void* d) {
MUTLOCK
STAT(ninsert);
TQItem* i = tpool_->alloc();
TQItem* i = tpool_->allocate();
i->data_ = d;
i->t_ = td;
binq_->enqueue(td, i);
Expand All @@ -215,7 +214,7 @@

void TQueue::release(TQItem* q) {
// if lockable then the pool is internally handles locking
tpool_->hpfree(q);
tpool_->deallocate(q);
}

void TQueue::remove(TQItem* q) {
Expand All @@ -233,7 +232,7 @@
} else {
spdelete(q, sptree_);
}
tpool_->hpfree(q);
tpool_->deallocate(q);
}
MUTUNLOCK
}
Expand Down Expand Up @@ -401,7 +400,7 @@
}
TQItem* SelfQueue::insert(void* d) {
MUTLOCK
TQItem* q = tpool_->alloc();
TQItem* q = tpool_->allocate();
q->left_ = nullptr;
q->right_ = head_;
if (head_) {
Expand All @@ -423,14 +422,14 @@
if (q == head_) {
head_ = q->right_;
}
tpool_->hpfree(q);
tpool_->deallocate(q);
MUTUNLOCK
return q->data_;
}
void SelfQueue::remove_all() {
MUTLOCK
for (TQItem* q = first(); q; q = next(q)) {
tpool_->hpfree(q);
tpool_->deallocate(q);

Check warning on line 432 in src/nrncvode/tqueue.cpp

View check run for this annotation

Codecov / codecov/patch

src/nrncvode/tqueue.cpp#L432

Added line #L432 was not covered by tests
}
head_ = nullptr;
MUTUNLOCK
Expand Down
4 changes: 2 additions & 2 deletions src/nrncvode/tqueue.hpp
Expand Up @@ -5,11 +5,11 @@
#include <assert.h>

#include <nrnmutdec.h>
#include <pool.hpp>
#include <utils/pool.hpp>

#include "tqitem.hpp"

using TQItemPool = MutexPool<TQItem>;
using TQItemPool = Pool<TQItem, PoolMutexed>;

// bin queue for the fixed step method for NetCons and PreSyns. Splay tree
// for others.
Expand Down