Skip to content

Commit 3c8d430

Browse files
authored
Manually revert #3291. WatchCondition never uses a freed watch_list_. (#3496)
1 parent d32c4c6 commit 3c8d430

8 files changed

Lines changed: 279 additions & 36 deletions

File tree

cmake/NeuronFileLists.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ set(NRNCVODE_FILE_LIST
259259
cvodeobj.cpp
260260
cvodestb.cpp
261261
cvtrset.cpp
262+
htlist.cpp
262263
netcvode.cpp
263264
nrndaspk.cpp
264265
occvode.cpp

src/nrncvode/cvodeobj.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#pragma once
22

3-
#include <list>
4-
53
#include "nrnmpi.h"
64
#include "nrnneosm.h"
75
//#include "shared/nvector_serial.h"
86
#include "shared/nvector.h"
97
#include "membfunc.h"
108
#include "netcon.h"
119
#include "tqitem.hpp"
10+
#include "htlist.h"
1211

1312
class NetCvode;
1413
class Daspk;
@@ -82,7 +81,7 @@ class CvodeThreadData {
8281
int vnode_end_index_;
8382

8483
PreSynList* psl_th_; // with a threshold
85-
std::list<WatchCondition*>* watch_list_;
84+
HTList* watch_list_;
8685
// since scatter/gather are hot loops, don't want to use data_handle
8786
// std::vector<neuron::container::data_handle<double>> pv_, pvdot_;
8887
std::vector<double*> pv_, pvdot_;

src/nrncvode/htlist.cpp

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#ifdef HAVE_CONFIG_H
2+
#include <../../nrnconf.h>
3+
#endif
4+
/*
5+
Based on Unidraw UList but UList changed to HTList (head tail list)
6+
for fast insertion, deletion, iteration
7+
*/
8+
9+
/*
10+
* Copyright (c) 1990, 1991 Stanford University
11+
*
12+
* Permission to use, copy, modify, distribute, and sell this software and its
13+
* documentation for any purpose is hereby granted without fee, provided
14+
* that the above copyright notice appear in all copies and that both that
15+
* copyright notice and this permission notice appear in supporting
16+
* documentation, and that the name of Stanford not be used in advertising or
17+
* publicity pertaining to distribution of the software without specific,
18+
* written prior permission. Stanford makes no representations about
19+
* the suitability of this software for any purpose. It is provided "as is"
20+
* without express or implied warranty.
21+
*
22+
* STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
23+
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
24+
* IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
25+
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
26+
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
27+
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
28+
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
29+
*/
30+
31+
/*
32+
* HTList implementation.
33+
*/
34+
35+
#include <stdio.h>
36+
#include <OS/enter-scope.h>
37+
#include <htlist.h>
38+
39+
/*****************************************************************************/
40+
41+
HTList::HTList(void* p) {
42+
_next = this;
43+
_prev = this;
44+
_object = p;
45+
}
46+
47+
HTList::~HTList() {
48+
HTList* next = _next;
49+
if (next != this && next != NULL) {
50+
Remove(this);
51+
delete next;
52+
}
53+
}
54+
55+
void HTList::Append(HTList* e) {
56+
_prev->_next = e;
57+
e->_prev = _prev;
58+
e->_next = this;
59+
_prev = e;
60+
}
61+
62+
void HTList::Prepend(HTList* e) {
63+
_next->_prev = e;
64+
e->_prev = this;
65+
e->_next = _next;
66+
_next = e;
67+
}
68+
69+
void HTList::Remove(HTList* e) {
70+
e->_prev->_next = e->_next;
71+
e->_next->_prev = e->_prev;
72+
e->_prev = e->_next = NULL;
73+
}
74+
75+
void HTList::Remove() {
76+
if (_prev) {
77+
_prev->_next = _next;
78+
}
79+
if (_next) {
80+
_next->_prev = _prev;
81+
}
82+
_prev = _next = NULL;
83+
}
84+
void HTList::RemoveAll() {
85+
while (!IsEmpty()) {
86+
Remove(First());
87+
}
88+
}
89+
void HTList::Delete(void* p) {
90+
HTList* e;
91+
92+
e = Find(p);
93+
if (e != NULL) {
94+
Remove(e);
95+
delete e;
96+
}
97+
}
98+
99+
HTList* HTList::Find(void* p) {
100+
HTList* e;
101+
102+
for (e = _next; e != this; e = e->_next) {
103+
if (e->_object == p) {
104+
return e;
105+
}
106+
}
107+
return NULL;
108+
}
109+
110+
HTList* HTList::operator[](int count) {
111+
HTList* pos = First();
112+
int i;
113+
114+
for (i = 1; i < count && pos != End(); ++i) {
115+
pos = pos->Next();
116+
}
117+
if (i == count) {
118+
return pos;
119+
}
120+
return NULL;
121+
}

src/nrncvode/htlist.h

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
from Unidraw but UList changed to HTList (head tail list)
3+
for fast insertion, deletion, iteration
4+
*/
5+
6+
/*
7+
* Copyright (c) 1990, 1991 Stanford University
8+
*
9+
* Permission to use, copy, modify, distribute, and sell this software and its
10+
* documentation for any purpose is hereby granted without fee, provided
11+
* that the above copyright notice appear in all copies and that both that
12+
* copyright notice and this permission notice appear in supporting
13+
* documentation, and that the name of Stanford not be used in advertising or
14+
* publicity pertaining to distribution of the software without specific,
15+
* written prior permission. Stanford makes no representations about
16+
* the suitability of this software for any purpose. It is provided "as is"
17+
* without express or implied warranty.
18+
*
19+
* STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
20+
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
21+
* IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
22+
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
23+
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
24+
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
25+
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26+
*/
27+
28+
/*
29+
* UList - list object.
30+
*/
31+
32+
#pragma once
33+
34+
class HTList {
35+
public:
36+
HTList(void* = NULL);
37+
virtual ~HTList();
38+
39+
bool IsEmpty();
40+
void Append(HTList*);
41+
void Prepend(HTList*);
42+
void Remove(HTList*);
43+
void Remove();
44+
void RemoveAll();
45+
void Delete(void*);
46+
HTList* Find(void*);
47+
HTList* First();
48+
HTList* Last();
49+
HTList* End();
50+
HTList* Next();
51+
HTList* Prev();
52+
53+
void* vptr();
54+
void* operator()();
55+
HTList* operator[](int count);
56+
57+
protected:
58+
void* _object;
59+
HTList* _next;
60+
HTList* _prev;
61+
};
62+
63+
inline bool HTList::IsEmpty() {
64+
return _next == this;
65+
}
66+
inline HTList* HTList::First() {
67+
return _next;
68+
}
69+
inline HTList* HTList::Last() {
70+
return _prev;
71+
}
72+
inline HTList* HTList::End() {
73+
return this;
74+
}
75+
inline HTList* HTList::Next() {
76+
return _next;
77+
}
78+
inline HTList* HTList::Prev() {
79+
return _prev;
80+
}
81+
inline void* HTList::operator()() {
82+
return _object;
83+
}
84+
inline void* HTList::vptr() {
85+
return _object;
86+
}

src/nrncvode/netcon.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "nrnneosm.h"
88
#include "pool.hpp"
99
#include "tqitem.hpp"
10-
#include "utils/signal.hpp"
10+
#include "htlist.h"
1111

1212
#include <InterViews/observe.h>
1313

@@ -212,7 +212,7 @@ class ConditionEvent: public DiscreteEvent {
212212
static unsigned long deliver_qthresh_;
213213
};
214214

215-
class WatchCondition: public ConditionEvent {
215+
class WatchCondition: public ConditionEvent, public HTList {
216216
public:
217217
WatchCondition(Point_process*, double (*)(Point_process*));
218218
virtual ~WatchCondition();
@@ -242,8 +242,6 @@ class WatchCondition: public ConditionEvent {
242242

243243
static unsigned long watch_send_;
244244
static unsigned long watch_deliver_;
245-
246-
signal_<WatchCondition*> unregister;
247245
};
248246

249247
class STECondition: public WatchCondition {

0 commit comments

Comments
 (0)