NEURON
sptbinq.h
Go to the documentation of this file.
1 //#ifndef tqueue_h
2 //#define tqueue_h
3 
4 // bin queue for the fixed step method for NetCons and PreSyns. Splay tree
5 // for others.
6 // fifo for the NetCons and PreSyns with same delay. Splay tree for
7 // others (especially SelfEvents).
8 // note that most methods below assume a TQItem is in the splay tree
9 // For the bin part, only insert_fifo, and remove make sense,
10 // and forall_callback does the splay tree first and then the bin (so
11 // not in time order)
12 // The bin part assumes a fixed step method.
13 
14 #include <assert.h>
15 
16 #define COLLECT_TQueue_STATISTICS 1
17 template<typename T> struct SPTREE;
18 class TQItemPool;
19 
20 class TQItem {
21 public:
22  TQItem();
23  virtual ~TQItem();
24  bool check();
25  void clear(){};
26 public:
27  void* data_;
28  double t_;
29  TQItem* left_;
30  TQItem* right_;
31  TQItem* parent_;
32  int cnt_; // reused: -1 means it is in the splay tree, >=0 gives bin
33 };
34 
35 // helper class for the TQueue (SplayTBinQueue).
36 class BinQ {
37 public:
38  BinQ();
39  virtual ~BinQ();
40  void enqueue(double tt, TQItem*);
41  void shift(double tt) { assert(!bins_[qpt_]); tt_ = tt; if (++qpt_ >= nbin_) { qpt_ = 0; }}
42  TQItem* top() { return bins_[qpt_]; }
43  TQItem* dequeue();
44  double tbin() { return tt_; }
45  // for iteration
46  TQItem* first();
47  TQItem* next(TQItem*);
48  void remove(TQItem*);
49  void resize(int);
50 #if COLLECT_TQueue_STATISTICS
51 public:
52  int nfenq, nfdeq, nfrem;
53 #endif
54 private:
55  double tt_; // time at beginning of qpt_ interval
56  int nbin_, qpt_;
58 };
59 
60 class TQueue {
61 public:
62  TQueue(TQItemPool*, int mkmut = 0);
63  virtual ~TQueue();
64 
65 #if FAST_LEAST
66  TQItem* least() {return least_;}
67  TQItem* second_least(double t);
68 #if USE_PTHREAD
69  double least_t(){double tt; MUTLOCK; if (least_) { tt = least_->t_;}else{tt = 1e15;} MUTUNLOCK; return tt;}
70 #else
71  double least_t(){if (least_) { return least_->t_;}else{return 1e15;}}
72 #endif
73 #else
74  TQItem* least(); // does not remove from TQueue
75  double least_t();
76 #endif
77  TQItem* atomic_dq(double til);
78  TQItem* insert(double t, void* data);
79  TQItem* enqueue_bin(double t, void* data);
80  TQItem* dequeue_bin() { return binq_->dequeue(); }
81  void shift_bin(double t) { ++nshift_; binq_->shift(t); }
82  double tbin() { return binq_->tbin(); }
83  TQItem* top() { return binq_->top(); }
84  void release(TQItem*);
85  TQItem* find(double t);
86  void remove(TQItem*);
87  void move(TQItem*, double tnew);
88  void move_least(double tnew);
89  void print();
90  void check(const char* errmess);
91  void statistics();
92  void spike_stat(double*);
93  void forall_callback(void (*)(const TQItem*, int));
94  int nshift_;
95  void deleteitem(TQItem*);
96 public:
97  BinQ* binq(){return binq_;}
98 private:
99  double least_t_nolock(){if (least_) { return least_->t_;}else{return 1e15;}}
100  void move_least_nolock(double tnew);
103  TQItem* least_;
104  TQItemPool* tpool_;
105  MUTDEC
106 #if COLLECT_TQueue_STATISTICS
107  unsigned long ninsert, nrem, nleast, nbal, ncmplxrem;
108  unsigned long ncompare, nleastsrch, nfind, nfindsrch, nmove, nfastmove;
109 #endif
110 };
111 
112 //#endif
#define data
Definition: rbtqueue.cpp:49
#define assert(ex)
Definition: hocassrt.h:26
TQItem()
Definition: bbtqueue.cpp:3
void clear()
Definition: sptbinq.h:25
MUTDEC unsigned long nrem
Definition: sptbinq.h:107
TQItem * top()
Definition: sptbinq.h:42
#define MUTLOCK
Definition: nrnmutdec.h:32
void shift_bin(double t)
Definition: sptbinq.h:81
static int first
Definition: fmenu.cpp:186
SPTREE< TQItem > * sptree_
Definition: sptbinq.h:101
#define MUTUNLOCK
Definition: nrnmutdec.h:33
TQItem ** bins_
Definition: sptbinq.h:57
#define print
Definition: redef.h:109
Item * next(Item *item)
Definition: list.cpp:95
double t_
Definition: bbtqueue.h:18
Definition: bbtqueue.h:6
double tbin()
Definition: sptbinq.h:82
bool check()
Definition: bbtqueue.cpp:30
static double statistics(void *v)
Definition: cvodeobj.cpp:115
virtual ~TQItem()
Definition: bbtqueue.cpp:9
int qpt_
Definition: sptbinq.h:56
#define MUTDEC
Definition: nrnmutdec.h:28
BinQ * binq()
Definition: sptbinq.h:97
static double insert(void *v)
Definition: tqueue.cpp:22
TQItem * top()
Definition: sptbinq.h:83
TQItemPool * tpool_
Definition: sptbinq.h:104
static void deleteitem(TQItem *i)
Definition: bbtqueue.cpp:18
TQItem * dequeue_bin()
Definition: sptbinq.h:80
virtual void move(const Event &e)
Definition: ocinput.h:19
static double resize(void *v)
virtual void release(const Event &e)
Definition: ocinput.h:22
TQItem * left_
Definition: bbtqueue.h:19
double tbin()
Definition: sptbinq.h:44
BinQ * binq_
Definition: sptbinq.h:102
Definition: sptbinq.h:17
double least_t_nolock()
Definition: sptbinq.h:99
int nfrem
Definition: sptbinq.h:52
TQItem * parent_
Definition: bbtqueue.h:21
void shift(double tt)
Definition: sptbinq.h:41
static double least(void *v)
Definition: tqueue.cpp:33
int find(const int, const int, const int, const int, const int)
void * data_
Definition: bbtqueue.h:17
Definition: sptbinq.h:36
double t
Definition: init.cpp:123
int cnt_
Definition: spt2queue.h:23
double tt_
Definition: sptbinq.h:55
TQItem * right_
Definition: bbtqueue.h:20
static double spike_stat(void *v)
Definition: ocbbs.cpp:693
int nshift_
Definition: sptbinq.h:94