NEURON
tqueue.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 #include <InterViews/resource.h>
3 #include "tqueue.h"
4 #include "pool.h"
5 
6 #include "classreg.h"
7 #include "nrnoc2iv.h"
8 
9 #define PROFILE 0
10 #include "profile.h"
11 
12 #define DOCHECK 0
13 
14 #if COLLECT_TQueue_STATISTICS
15 #define STAT(arg) ++arg;
16 #else
17 #define STAT(arg) /**/
18 #endif
19 
20 static const char* errmess_;
21 
22 static double insert(void* v) {
23  TQueue* q = (TQueue*)v;
24  q->insert(*getarg(1), (void*)1);
25  return 1.;
26 }
27 static double print(void* v) {
28  TQueue* q = (TQueue*)v;
29  q->print();
30  return 1.;
31 }
32 
33 static double least(void* v) {
34  TQueue* q = (TQueue*)v;
35  TQItem* i = q->least();
36  double x = -1e9;
37  if (i) {
38  x = i->t_;
39  }
40  return x;
41 }
42 static double rmleast(void* v) {
43  TQueue* q = (TQueue*)v;
44  TQItem* i = q->least();
45  double x = -1e9;
46  if (i) {
47  x = i->t_;
48  q->remove(i);
49  }
50  return x;
51 }
52 
53 static double mvleast(void* v) {
54  TQueue* q = (TQueue*)v;
55  q->move_least(*getarg(1));
56  return 1.;
57 }
58 
59 static double remove(void* v) {
60  TQueue* q = (TQueue*)v;
61  q->remove(q->find(*getarg(1)));
62  return 1.;
63 }
64 
65 static double find(void* v) {
66  TQueue* q = (TQueue*)v;
67  TQItem* i = q->find(*getarg(1));
68  double x = -1e9;
69  if (i) {
70  x = i->t_;
71  q->remove(i);
72  }
73  return x;
74 }
75 static double stats(void* v) {
76  TQueue* q = (TQueue*)v;
77  q->statistics();
78  return 1.;
79 }
80 
81 static Member_func members[] = {
82  "insrt", insert,
83  "least", least,
84  "move_least", mvleast,
85  "remove_least", rmleast,
86  "remove", remove,
87  "find", find,
88  "stats", stats,
89  "printf", print,
90  0,0
91 };
92 
93 static void* cons(Object*) {
94  assert(0);
95  TQueue* q = new TQueue(0);
96  return (void*)q;
97 }
98 
99 static void destruct(void* v) {
100  TQueue* q = (TQueue*)v;
101  delete q;
102 }
103 
104 void TQueue_reg() {
105  class2oc("TQueue", cons, destruct, members, NULL, NULL, NULL);
106 }
107 
108 //----------------
109 
110 implementPool(TQItemPool, TQItem)
111 
112 #if BBTQ == 0
113 #include <bbtqueue.cpp>
114 #endif
115 
116 #if BBTQ == 1
117 #include <rbtqueue.cpp>
118 #endif
119 
120 #if BBTQ == 2
121 #include <sptqueue.cpp>
122 #endif
123 
124 #if BBTQ == 3
125 #include <sptfifoq.cpp>
126 #endif
127 
128 #if BBTQ == 4
129 #include <spt2queue.cpp>
130 #endif
131 
132 #if BBTQ == 5
133 #include <sptbinq.cpp>
134 #endif
135 
136 SelfQueue::SelfQueue(TQItemPool* tp, int mkmut) {
137  MUTCONSTRUCT(mkmut)
138  tpool_ = tp;
139  head_ = nil;
140 }
141 SelfQueue::~SelfQueue() {
142  remove_all();
144 }
145 TQItem* SelfQueue::insert(void* d) {
146  MUTLOCK
147  TQItem* q = tpool_->alloc();
148  q->left_ = nil;
149  q->right_ = head_;
150  if (head_) { head_->left_ = q; }
151  head_ = q;
152  q->data_ = d;
153  MUTUNLOCK
154  return q;
155 }
156 void* SelfQueue::remove(TQItem* q) {
157  MUTLOCK
158  if (q->left_) { q->left_->right_ = q->right_; }
159  if (q->right_) { q->right_->left_ = q->left_; }
160  if (q == head_) { head_ = q->right_; }
161  tpool_->hpfree(q);
162  MUTUNLOCK
163  return q->data_;
164 }
165 void SelfQueue::remove_all() {
166  MUTLOCK
167  for (TQItem* q = first(); q; q = next(q)) {
168  tpool_->hpfree(q);
169  }
170  head_ = nil;
171  MUTUNLOCK
172 }
173 
174 
void TQueue_reg()
Definition: tqueue.cpp:104
static double find(void *v)
Definition: tqueue.cpp:65
#define assert(ex)
Definition: hocassrt.h:26
void print()
Definition: bbtqueue.cpp:114
TQItem * find(double t)
Definition: bbtqueue.cpp:220
static double stats(void *v)
Definition: tqueue.cpp:75
static double remove(void *v)
Definition: tqueue.cpp:59
#define MUTLOCK
Definition: nrnmutdec.h:32
static double print(void *v)
Definition: tqueue.cpp:27
static int first
Definition: fmenu.cpp:186
#define MUTUNLOCK
Definition: nrnmutdec.h:33
static void * cons(Object *)
Definition: tqueue.cpp:93
#define v
Definition: md1redef.h:4
static Member_func members[]
Definition: tqueue.cpp:81
static double rmleast(void *v)
Definition: tqueue.cpp:42
implementPool(TQItemPool, TQItem) SelfQueue
Definition: tqueue.cpp:110
Item * next(Item *item)
Definition: list.cpp:95
double t_
Definition: bbtqueue.h:18
Definition: bbtqueue.h:6
void statistics()
Definition: bbtqueue.cpp:474
void remove_all(EventButton)
TQItem * least()
Definition: bbtqueue.cpp:145
void class2oc(const char *, void *(*cons)(Object *), void(*destruct)(void *), Member_func *, int(*checkpoint)(void **), Member_ret_obj_func *, Member_ret_str_func *)
Definition: hoc_oop.cpp:1581
static double insert(void *v)
Definition: tqueue.cpp:22
static double mvleast(void *v)
Definition: tqueue.cpp:53
TQItem * insert(double t, void *data_)
Definition: bbtqueue.cpp:391
#define nil
Definition: enter-scope.h:36
TQItem * left_
Definition: bbtqueue.h:19
#define MUTCONSTRUCT(mkmut)
Definition: nrnmutdec.h:30
static void destruct(void *v)
Definition: tqueue.cpp:99
void move_least(double tnew)
Definition: bbtqueue.cpp:181
Definition: hocdec.h:226
static const char * errmess_
Definition: tqueue.cpp:20
#define getarg
Definition: hocdec.h:15
#define i
Definition: md1redef.h:12
#define MUTDESTRUCT
Definition: nrnmutdec.h:31
static double least(void *v)
Definition: tqueue.cpp:33
void * data_
Definition: bbtqueue.h:17
void remove(TQItem *)
Definition: bbtqueue.cpp:239
size_t q
TQItem * right_
Definition: bbtqueue.h:20
return NULL
Definition: cabcode.cpp:461