Skip to content

Commit d6c547b

Browse files
committed
Merge pull request #234 from eregon/boostvm_refs
Update ASIO wrapper constructors
2 parents 76914ec + 05e3bb0 commit d6c547b

File tree

12 files changed

+49
-59
lines changed

12 files changed

+49
-59
lines changed

boosthost/emulator/emulator.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,8 @@ int main(int argc, char** argv) {
349349
baseEnv = vm->protect(OptVar::build(vm));
350350

351351
UnstableNode baseValue;
352-
auto& bootLoader = boostEnv.getBootLoader();
353352

354-
if (!bootLoader(vm, baseFunctorPath.string(), baseValue)) {
353+
if (!boostEnv.bootLoader(vm, baseFunctorPath.string(), baseValue)) {
355354
std::cerr << "panic: could not load Base functor at "
356355
<< baseFunctorPath << std::endl;
357356
return false;
@@ -376,9 +375,8 @@ int main(int argc, char** argv) {
376375
initFunctor = vm->protect(OptVar::build(vm));
377376

378377
UnstableNode initValue;
379-
auto& bootLoader = boostEnv.getBootLoader();
380378

381-
if (!bootLoader(vm, initFunctorPath.string(), initValue)) {
379+
if (!boostEnv.bootLoader(vm, initFunctorPath.string(), initValue)) {
382380
std::cerr << "panic: could not load Init functor at "
383381
<< initFunctorPath << std::endl;
384382
return false;

vm/boostenv/main/boostenv-decl.hh

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public:
6464
BoostEnvironment(const VMStarter& vmStarter);
6565

6666
// VM Management
67+
// All public functions may be called by any thread!
6768

6869
public:
6970
inline
@@ -108,17 +109,6 @@ public:
108109
});
109110
}
110111

111-
// Configuration
112-
113-
public:
114-
const BootLoader& getBootLoader() {
115-
return _bootLoader;
116-
}
117-
118-
void setBootLoader(const BootLoader& loader) {
119-
_bootLoader = loader;
120-
}
121-
122112
// Run and preemption
123113

124114
public:
@@ -198,10 +188,9 @@ private:
198188
boost::mutex _gcMutex;
199189

200190
// Bootstrap
201-
private:
202-
BootLoader _bootLoader;
203191
public:
204-
VMStarter vmStarter;
192+
const BootLoader bootLoader;
193+
const VMStarter vmStarter;
205194

206195
// Unsafe process-wide operations
207196
private:

vm/boostenv/main/boostenv.hh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,8 @@ namespace internal {
113113

114114
BoostEnvironment::BoostEnvironment(const VMStarter& vmStarter) :
115115
_nextVMIdentifier(InitialVMIdentifier), _exitCode(0),
116+
bootLoader(&internal::defaultBootLoader),
116117
vmStarter(vmStarter) {
117-
// Set up a default boot loader
118-
setBootLoader(&internal::defaultBootLoader);
119-
120118
// Ignore SIGPIPE ourselves since Boost does not always do it
121119
#ifdef SIGPIPE
122120
std::signal(SIGPIPE, SIG_IGN);

vm/boostenv/main/boostenvpipe-decl.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class PipeConnection: public BaseSocketConnection<PipeConnection,
4141
boost::asio::local::stream_protocol> {
4242
public:
4343
inline
44-
PipeConnection(VM vm);
44+
PipeConnection(BoostEnvironment& env, VMIdentifier vm);
4545
};
4646

4747
#endif // BOOST_ASIO_HAS_LOCAL_SOCKETS

vm/boostenv/main/boostenvpipe.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ namespace mozart { namespace boostenv {
3939
// PipeConnection //
4040
////////////////////
4141

42-
PipeConnection::PipeConnection(VM vm):
43-
BaseSocketConnection(vm) {
42+
PipeConnection::PipeConnection(BoostEnvironment& env, VMIdentifier vm):
43+
BaseSocketConnection(env, vm) {
4444
}
4545

4646
#endif // BOOST_ASIO_HAS_LOCAL_SOCKETS

vm/boostenv/main/boostenvtcp-decl.hh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class TCPConnection: public BaseSocketConnection<TCPConnection,
3939
boost::asio::ip::tcp> {
4040
public:
4141
inline
42-
TCPConnection(VM vm);
42+
TCPConnection(BoostEnvironment& env, VMIdentifier vm);
4343

4444
public:
4545
inline
@@ -61,9 +61,9 @@ private:
6161
public:
6262
typedef std::shared_ptr<TCPAcceptor> pointer;
6363

64-
static pointer create(VM vm, const tcp::endpoint& endpoint) {
64+
static pointer create(BoostEnvironment& env, VMIdentifier vm, const tcp::endpoint& endpoint) {
6565
// Cannot use make_shared as constructor is private
66-
return pointer(new TCPAcceptor(vm, endpoint));
66+
return pointer(new TCPAcceptor(env, vm, endpoint));
6767
}
6868

6969
public:
@@ -72,8 +72,7 @@ public:
7272
}
7373

7474
inline
75-
void startAsyncAccept(TCPConnection::pointer connection,
76-
const ProtectedNode& connectionNode);
75+
void startAsyncAccept(const ProtectedNode& connectionNode);
7776

7877
inline
7978
boost::system::error_code cancel();
@@ -83,7 +82,7 @@ public:
8382

8483
private:
8584
inline
86-
TCPAcceptor(VM vm, const tcp::endpoint& endpoint);
85+
TCPAcceptor(BoostEnvironment& env, VMIdentifier vm, const tcp::endpoint& endpoint);
8786

8887
private:
8988
BoostEnvironment& env;

vm/boostenv/main/boostenvtcp.hh

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ namespace mozart { namespace boostenv {
3737
// TCPConnection //
3838
///////////////////
3939

40-
TCPConnection::TCPConnection(VM vm):
41-
BaseSocketConnection(vm), _resolver(env.io_service) {
40+
TCPConnection::TCPConnection(BoostEnvironment& env, VMIdentifier vm):
41+
BaseSocketConnection(env, vm), _resolver(env.io_service) {
4242
}
4343

4444
void TCPConnection::startAsyncConnect(std::string host, std::string service,
@@ -80,15 +80,14 @@ void TCPConnection::startAsyncConnect(std::string host, std::string service,
8080
// TCPAcceptor //
8181
/////////////////
8282

83-
TCPAcceptor::TCPAcceptor(VM vm,
83+
TCPAcceptor::TCPAcceptor(BoostEnvironment& env, VMIdentifier vm,
8484
const tcp::endpoint& endpoint):
85-
env(BoostEnvironment::forVM(vm)),
86-
vm(BoostVM::forVM(vm).identifier),
87-
_acceptor(env.io_service, endpoint) {
85+
env(env), vm(vm), _acceptor(env.io_service, endpoint) {
8886
}
8987

90-
void TCPAcceptor::startAsyncAccept(TCPConnection::pointer connection,
91-
const ProtectedNode& connectionNode) {
88+
void TCPAcceptor::startAsyncAccept(const ProtectedNode& connectionNode) {
89+
TCPConnection::pointer connection = TCPConnection::create(env, vm);
90+
9291
auto handler = [=] (const boost::system::error_code& error) {
9392
if (!error) {
9493
env.postVMEvent(vm, [=] (BoostVM& boostVM) {
@@ -101,7 +100,7 @@ void TCPAcceptor::startAsyncAccept(TCPConnection::pointer connection,
101100
});
102101
} else {
103102
// Try again
104-
startAsyncAccept(connection, connectionNode);
103+
startAsyncAccept(connectionNode);
105104
}
106105
};
107106

vm/boostenv/main/boostenvutils-decl.hh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ public:
4949
public:
5050
typedef std::shared_ptr<T> pointer;
5151

52-
static pointer create(VM vm) {
53-
return std::make_shared<T>(vm);
52+
static pointer create(BoostEnvironment& env, VMIdentifier vm) {
53+
return std::make_shared<T>(env, vm);
5454
}
5555

5656
public:
5757
inline
58-
BaseSocketConnection(VM vm);
58+
BaseSocketConnection(BoostEnvironment& env, VMIdentifier vm);
5959

6060
public:
6161
typename protocol::socket& socket() {

vm/boostenv/main/boostenvutils.hh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@ namespace mozart { namespace boostenv {
3838
//////////////////////////
3939

4040
template <typename T, typename P>
41-
BaseSocketConnection<T, P>::BaseSocketConnection(VM vm):
42-
env(BoostEnvironment::forVM(vm)),
43-
vm(BoostVM::forVM(vm).identifier),
44-
_socket(env.io_service) {
41+
BaseSocketConnection<T, P>::BaseSocketConnection(BoostEnvironment& env, VMIdentifier vm):
42+
env(env), vm(vm), _socket(env.io_service) {
4543
}
4644

4745
template <typename T, typename P>

vm/boostenv/main/boostvm-decl.hh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ public:
134134
}
135135

136136
public:
137-
VM vm;
138137
BoostEnvironment& env;
139-
VMIdentifier identifier;
138+
const VM vm;
139+
const VMIdentifier identifier;
140140

141141
// Random number and UUID generation
142142
public:
@@ -182,7 +182,7 @@ private:
182182

183183
// Running thread management
184184
private:
185-
boost::asio::io_service::work* _work;
185+
boost::asio::io_service::work* const _work;
186186
};
187187

188188
} }

0 commit comments

Comments
 (0)