Skip to content

Commit 27eadb4

Browse files
Add the ability to abort xml serialisation from a separate thread. For Minsky/Ravel optimisation.
1 parent 2a9c04b commit 27eadb4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

xml_pack_base.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ namespace classdesc
9999
public:
100100
string schema;
101101
bool prettyPrint; /// if true, the layout XML in more human friendly form
102-
102+
volatile bool abort=false; /// set to true to cancel packing from another thread
103+
struct PackAborted: public std::exception {};
104+
103105
xml_pack_t(std::ostream& o, const string& schema=""):
104106
o(&o), taglevel(0), schema(schema), prettyPrint(false) {}
105107

@@ -142,6 +144,7 @@ namespace classdesc
142144
template <class T>
143145
void pack(const string& d, const T&x)
144146
{
147+
if (abort) throw PackAborted();
145148
std::string tag=tail(d);
146149
pretty(d);
147150
*o << "<"<<tag<<">";
@@ -155,6 +158,7 @@ namespace classdesc
155158
*/
156159
template <class T>
157160
void pack_notag(const string& d, const T&x) {
161+
if (abort) throw PackAborted();
158162
*o<<x;
159163
if (!*o) throw std::runtime_error("failed to serialise");
160164
}
@@ -192,7 +196,7 @@ namespace classdesc
192196
inline void xml_pack(xml_pack_t& x,const string& d, std::string& a)
193197
{
194198
std::string tmp;
195-
for (std::string::size_type i=0; i<a.length(); i++) tmp+=classdesc::xml_quote(a[i]);
199+
for (std::string::size_type i=0; i<a.length() && !x.abort; i++) tmp+=classdesc::xml_quote(a[i]);
196200
x.pack(d,tmp);
197201
}
198202

0 commit comments

Comments
 (0)