Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
sds
thallium
Commits
ff876239
Commit
ff876239
authored
Jul 20, 2018
by
Matthieu Dorier
Browse files
added on_finalize callback
parent
1c622385
Changes
2
Hide whitespace changes
Inline
Side-by-side
examples/04_stop/server.cpp
View file @
ff876239
...
...
@@ -17,6 +17,8 @@ int main(int argc, char** argv) {
myEngine
.
define
(
"sum"
,
sum
);
myEngine
.
on_finalize
([]()
{
std
::
cout
<<
"Finalization was called"
<<
std
::
endl
;
});
return
0
;
}
include/thallium/engine.hpp
View file @
ff876239
...
...
@@ -9,6 +9,7 @@
#include <iostream>
#include <string>
#include <functional>
#include <stack>
#include <unordered_map>
#include <atomic>
#include <margo.h>
...
...
@@ -51,13 +52,14 @@ private:
using
rpc_t
=
std
::
function
<
void
(
const
request
&
,
const
buffer
&
)
>
;
margo_instance_id
m_mid
;
std
::
unordered_map
<
hg_id_t
,
rpc_t
>
m_rpcs
;
bool
m_is_server
;
bool
m_owns_mid
;
std
::
atomic
<
bool
>
m_finalize_called
;
hg_context_t
*
m_hg_context
=
nullptr
;
hg_class_t
*
m_hg_class
=
nullptr
;
margo_instance_id
m_mid
;
std
::
unordered_map
<
hg_id_t
,
rpc_t
>
m_rpcs
;
bool
m_is_server
;
bool
m_owns_mid
;
std
::
atomic
<
bool
>
m_finalize_called
;
hg_context_t
*
m_hg_context
=
nullptr
;
hg_class_t
*
m_hg_class
=
nullptr
;
std
::
stack
<
std
::
function
<
void
(
void
)
>>
m_finalize_callbacks
;
/**
* @brief Encapsulation of some data needed by RPC callbacks
...
...
@@ -130,9 +132,14 @@ private:
return
HG_SUCCESS
;
}
static
void
on_finalize
(
void
*
arg
)
{
static
void
on_finalize
_cb
(
void
*
arg
)
{
engine
*
e
=
static_cast
<
engine
*>
(
arg
);
e
->
m_finalize_called
=
true
;
while
(
!
(
e
->
m_finalize_callbacks
.
empty
()))
{
auto
&
cb
=
e
->
m_finalize_callbacks
.
top
();
cb
();
e
->
m_finalize_callbacks
.
pop
();
}
}
public:
...
...
@@ -158,7 +165,7 @@ public:
// XXX throw an exception if m_mid not initialized
m_owns_mid
=
true
;
margo_push_finalize_callback
(
m_mid
,
&
engine
::
on_finalize
,
static_cast
<
void
*>
(
this
));
&
engine
::
on_finalize
_cb
,
static_cast
<
void
*>
(
this
));
}
engine
(
const
std
::
string
&
addr
,
int
mode
,
...
...
@@ -178,7 +185,7 @@ public:
default_handler_pool
.
native_handle
(),
m_hg_context
);
// XXX throw an exception if m_mid not initialized
margo_push_finalize_callback
(
m_mid
,
&
engine
::
on_finalize
,
static_cast
<
void
*>
(
this
));
&
engine
::
on_finalize
_cb
,
static_cast
<
void
*>
(
this
));
}
engine
(
margo_instance_id
mid
,
int
mode
)
{
...
...
@@ -314,6 +321,18 @@ public:
*/
bulk
expose
(
const
std
::
vector
<
std
::
pair
<
void
*
,
size_t
>>&
segments
,
bulk_mode
flag
);
/**
* @brief Pushes a finalization callback into the engine. This callback will be
* called when margo_finalize is called (e.g. through engine::finalize()).
*
* @tparam F type of callback. Must have a operator() defined.
* @param f callback.
*/
template
<
typename
F
>
void
on_finalize
(
F
&&
f
)
{
m_finalize_callbacks
.
emplace
(
std
::
forward
<
F
>
(
f
));
}
};
}
// namespace thallium
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment