Skip to content

Commit 9d3d27a

Browse files
committed
Make it so all functions of BoostVM are called by its VM thread
* _portClosed is now public as it already has all protections in its type.
1 parent b5546cb commit 9d3d27a

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

vm/boostenv/main/boostvm-decl.hh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class BoostEnvironment;
4444
// BoostVM //
4545
/////////////
4646

47+
// All member functions are called by the thread running the VM.
48+
4749
class BoostVM : VirtualMachine {
4850
public:
4951
BoostVM(BoostEnvironment& environment, VMIdentifier parent,
@@ -69,11 +71,9 @@ private:
6971
static std::uint64_t bytes2uint64(const std::uint8_t* bytes);
7072

7173
// VM Port
72-
public:
74+
private:
7375
bool streamAsked();
74-
75-
bool portClosed();
76-
76+
public:
7777
UnstableNode getStream();
7878

7979
void closeStream();
@@ -146,10 +146,11 @@ private:
146146
boost::uuids::random_generator uuidGenerator;
147147

148148
// VM stream
149+
public:
150+
std::atomic_bool portClosed;
149151
private:
150152
StableNode* _headOfStream;
151153
StableNode* _stream;
152-
std::atomic_bool _portClosed;
153154

154155
// Number of asynchronous IO nodes - used for termination detection
155156
private:

vm/boostenv/main/boostvm.cc

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ BoostVM::BoostVM(BoostEnvironment& environment,
4242
VirtualMachine(environment, options), vm(this),
4343
env(environment), identifier(identifier),
4444
uuidGenerator(random_generator),
45-
_portClosed(false),
45+
portClosed(false),
4646
_asyncIONodeCount(0),
4747
preemptionTimer(environment.io_service),
4848
alarmTimer(environment.io_service),
@@ -200,10 +200,6 @@ bool BoostVM::streamAsked() {
200200
return _headOfStream == nullptr;
201201
}
202202

203-
bool BoostVM::portClosed() {
204-
return _portClosed;
205-
}
206-
207203
UnstableNode BoostVM::getStream() {
208204
UnstableNode stream;
209205
if (!streamAsked()) {
@@ -219,12 +215,12 @@ UnstableNode BoostVM::getStream() {
219215
}
220216

221217
void BoostVM::closeStream() {
222-
if (!portClosed()) {
218+
if (!portClosed) {
223219
if (streamAsked())
224220
_asyncIONodeCount--; // We are no more interested in the stream
225221
UnstableNode nil = buildNil(vm);
226222
BindableReadOnly(*_stream).bindReadOnly(vm, nil);
227-
_portClosed = true;
223+
portClosed = true;
228224
}
229225
}
230226

@@ -233,7 +229,7 @@ void BoostVM::sendOnVMPort(VMIdentifier to, RichNode value) {
233229
// we do not need to pickle value
234230
bool portClosed = true;
235231
env.findVM(to, [&portClosed] (BoostVM& targetVM) {
236-
portClosed = targetVM.portClosed();
232+
portClosed = targetVM.portClosed;
237233
});
238234
if (portClosed)
239235
return;
@@ -251,12 +247,12 @@ void BoostVM::sendOnVMPort(VMIdentifier to, RichNode value) {
251247
}
252248

253249
void BoostVM::receiveOnVMStream(RichNode value) {
254-
if (!portClosed())
250+
if (!portClosed)
255251
sendToReadOnlyStream(vm, _stream, value);
256252
}
257253

258254
void BoostVM::receiveOnVMStream(std::string* buffer) {
259-
if (portClosed()) {
255+
if (portClosed) {
260256
delete buffer;
261257
return;
262258
}
@@ -303,7 +299,7 @@ void BoostVM::terminate() {
303299
preemptionTimer.cancel();
304300
alarmTimer.cancel();
305301

306-
_portClosed = true; // close VM port
302+
portClosed = true; // close VM port
307303
notifyMonitors();
308304

309305
env.removeTerminatedVM(identifier, _terminationStatus, _work);

0 commit comments

Comments
 (0)