Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
sds
margo
Commits
154b81be
Commit
154b81be
authored
Jul 04, 2019
by
Matthieu Dorier
Browse files
added provider finalize callbacks
parent
6ed94e4f
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/margo.h
View file @
154b81be
...
...
@@ -172,6 +172,45 @@ void margo_push_finalize_callback(
void
(
*
cb
)(
void
*
),
void
*
uargs
);
/**
* @brief Removes the last finalize callback that was pushed into the margo instance
* without calling it. If a callback was remoted, this function returns 1, otherwise
* it returns 0.
*
* @param mid Margo instance.
*/
int
margo_pop_finalize_callback
(
margo_instance_id
mid
);
/**
* @brief Installs a callback to be called before the margo instance is finalized.
* The owner pointer allows to identify callbacks installed by particular providers.
* Note that the same owner can install multiple callbacks. If they are not popped,
* they will be called in reverse order of installation by the margo cleanup procedure.
*
* @param mid The margo instance
* @param owner Owner of the callback (to be used when popping callbacks)
* @param cb Callback to install
* @param uargs User-provider argument to pass to the callback when called
*/
void
margo_provider_push_finalize_callback
(
margo_instance_id
mid
,
void
*
owner
,
void
(
*
cb
)(
void
*
),
void
*
uargs
);
/**
* @brief Removes the last finalize callback that was pushed into the margo instance
* by the specified owner. If a callback was remoted, this function returns 1, otherwise
* it returns 0.
*
* @param mid Margo instance.
* @param owner Owner of the callback.
*/
int
margo_provider_pop_finalize_callback
(
margo_instance_id
mid
,
void
*
owner
);
/**
* Allows the passed Margo instance to be shut down remotely
* using margo_shutdown_remote_instance().
...
...
src/margo.c
View file @
154b81be
...
...
@@ -48,6 +48,7 @@ struct margo_handle_cache_el
struct
margo_finalize_cb
{
void
*
owner
;
void
(
*
callback
)(
void
*
);
void
*
uargs
;
struct
margo_finalize_cb
*
next
;
...
...
@@ -528,6 +529,25 @@ hg_bool_t margo_is_listening(
void
margo_push_finalize_callback
(
margo_instance_id
mid
,
void
(
*
cb
)(
void
*
),
void
*
uargs
)
{
margo_provider_push_finalize_callback
(
mid
,
NULL
,
cb
,
uargs
);
}
int
margo_pop_finalize_callback
(
margo_instance_id
mid
)
{
return
margo_provider_pop_finalize_callback
(
mid
,
NULL
);
}
void
margo_provider_push_finalize_callback
(
margo_instance_id
mid
,
void
*
owner
,
void
(
*
cb
)(
void
*
),
void
*
uargs
)
{
...
...
@@ -535,14 +555,35 @@ void margo_push_finalize_callback(
struct
margo_finalize_cb
*
fcb
=
(
struct
margo_finalize_cb
*
)
malloc
(
sizeof
(
*
fcb
));
fcb
->
owner
=
owner
;
fcb
->
callback
=
cb
;
fcb
->
uargs
=
uargs
;
fcb
->
uargs
=
uargs
;
struct
margo_finalize_cb
*
next
=
mid
->
finalize_cb
;
fcb
->
next
=
next
;
mid
->
finalize_cb
=
fcb
;
}
int
margo_provider_pop_finalize_callback
(
margo_instance_id
mid
,
void
*
owner
)
{
struct
margo_finalize_cb
*
prev
=
NULL
;
struct
margo_finalize_cb
*
fcb
=
mid
->
finalize_cb
;
while
(
fcb
!=
NULL
&&
fcb
->
owner
!=
owner
)
{
prev
=
fcb
;
fcb
=
fcb
->
next
;
}
if
(
fcb
==
NULL
)
return
0
;
if
(
prev
==
NULL
)
{
mid
->
finalize_cb
=
fcb
->
next
;
}
else
{
prev
->
next
=
fcb
->
next
;
}
free
(
fcb
);
return
1
;
}
void
margo_enable_remote_shutdown
(
margo_instance_id
mid
)
{
mid
->
enable_remote_shutdown
=
1
;
...
...
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