Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
margo
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
15
Issues
15
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
sds
margo
Commits
a660d149
Commit
a660d149
authored
Apr 04, 2018
by
Matthieu Dorier
Browse files
Options
Browse Files
Download
Plain Diff
fixed merge conflicts
parents
b5a24e99
ca395517
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
4 deletions
+85
-4
margo.h
include/margo.h
+42
-4
margo.c
src/margo.c
+43
-0
No files found.
include/margo.h
View file @
a660d149
...
...
@@ -804,6 +804,35 @@ void margo_set_param(margo_instance_id mid, int option, const void *param);
void
margo_get_param
(
margo_instance_id
mid
,
int
option
,
void
*
param
);
/**
* @private
* Internal function used by MARGO_REGISTER, not
* supposed to be called by users!
*
* @param mid Margo instance
*
* @return whether margo_finalize() was called.
*/
int
__margo_internal_finalize_requested
(
margo_instance_id
mid
);
/**
* @private
* Internal function used by MARGO_REGISTER, not
* supposed to be called by users!
*
* @param mid Margo instance
*/
void
__margo_internal_incr_pending
(
margo_instance_id
mid
);
/**
* @private
* Internal function used by MARGO_REGISTER, not
* supposed to be called by users!
*
* @param mid Margo instance
*/
void
__margo_internal_decr_pending
(
margo_instance_id
mid
);
/**
* macro that registers a function as an RPC.
*/
...
...
@@ -828,16 +857,25 @@ void margo_get_param(margo_instance_id mid, int option, void *param);
* @param [in] __name name of handler function
*/
#define DEFINE_MARGO_RPC_HANDLER(__name) \
void __name##_wrapper(hg_handle_t handle) { \
__name(handle); \
margo_instance_id __mid; \
__mid = margo_hg_handle_get_instance(handle); \
__margo_internal_decr_pending(__mid); \
if(__margo_internal_finalize_requested(__mid)) { \
margo_finalize(__mid); \
} \
} \
hg_return_t __name##_handler(hg_handle_t handle) { \
int __ret; \
ABT_pool __pool; \
margo_instance_id __mid; \
__mid = margo_hg_handle_get_instance(handle); \
if(__mid == MARGO_INSTANCE_NULL) { \
return(HG_OTHER_ERROR); \
} \
if(__mid == MARGO_INSTANCE_NULL) { return(HG_OTHER_ERROR); } \
if(__margo_internal_finalize_requested(__mid)) { return(HG_CANCELED); } \
__pool = margo_hg_handle_get_handler_pool(handle); \
__ret = ABT_thread_create(__pool, (void (*)(void *))__name, handle, ABT_THREAD_ATTR_NULL, NULL); \
__margo_internal_incr_pending(__mid); \
__ret = ABT_thread_create(__pool, (void (*)(void *))__name##_wrapper, handle, ABT_THREAD_ATTR_NULL, NULL); \
if(__ret != 0) { \
return(HG_NOMEM_ERROR); \
} \
...
...
src/margo.c
View file @
a660d149
...
...
@@ -84,6 +84,12 @@ struct margo_instance
ABT_cond
finalize_cond
;
struct
margo_finalize_cb
*
finalize_cb
;
/* control logic to prevent margo_finalize from destroying
the instance when some operations are pending */
unsigned
pending_operations
;
ABT_mutex
pending_operations_mtx
;
int
finalize_requested
;
/* control logic for shutting down */
hg_id_t
shutdown_rpc_id
;
int
enable_remote_shutdown
;
...
...
@@ -334,6 +340,10 @@ margo_instance_id margo_init_pool(ABT_pool progress_pool, ABT_pool handler_pool,
mid
->
finalize_cb
=
NULL
;
mid
->
enable_remote_shutdown
=
0
;
mid
->
pending_operations
=
0
;
ABT_mutex_create
(
&
mid
->
pending_operations_mtx
);
mid
->
finalize_requested
=
0
;
mid
->
timer_list
=
margo_timer_list_create
();
if
(
mid
->
timer_list
==
NULL
)
goto
err
;
...
...
@@ -357,6 +367,7 @@ err:
margo_timer_list_free
(
mid
->
timer_list
);
ABT_mutex_free
(
&
mid
->
finalize_mutex
);
ABT_cond_free
(
&
mid
->
finalize_cond
);
ABT_mutex_free
(
&
mid
->
pending_operations_mtx
);
free
(
mid
);
}
return
MARGO_INSTANCE_NULL
;
...
...
@@ -379,6 +390,7 @@ static void margo_cleanup(margo_instance_id mid)
ABT_mutex_free
(
&
mid
->
finalize_mutex
);
ABT_cond_free
(
&
mid
->
finalize_cond
);
ABT_mutex_free
(
&
mid
->
pending_operations_mtx
);
if
(
mid
->
owns_progress_pool
)
{
...
...
@@ -415,6 +427,16 @@ void margo_finalize(margo_instance_id mid)
{
int
do_cleanup
;
/* check if there are pending operations */
int
pending
;
ABT_mutex_lock
(
mid
->
pending_operations_mtx
);
pending
=
mid
->
pending_operations
;
ABT_mutex_unlock
(
mid
->
pending_operations_mtx
);
if
(
pending
)
{
mid
->
finalize_requested
=
1
;
return
;
}
/* tell progress thread to wrap things up */
mid
->
hg_progress_shutdown_flag
=
1
;
...
...
@@ -1495,3 +1517,24 @@ static hg_id_t margo_register_internal(margo_instance_id mid, hg_id_t id,
return
(
id
);
}
int
__margo_internal_finalize_requested
(
margo_instance_id
mid
)
{
if
(
!
mid
)
return
0
;
return
mid
->
finalize_requested
;
}
void
__margo_internal_incr_pending
(
margo_instance_id
mid
)
{
if
(
!
mid
)
return
;
ABT_mutex_lock
(
mid
->
pending_operations_mtx
);
mid
->
pending_operations
+=
1
;
ABT_mutex_unlock
(
mid
->
pending_operations_mtx
);
}
void
__margo_internal_decr_pending
(
margo_instance_id
mid
)
{
if
(
!
mid
)
return
;
ABT_mutex_lock
(
mid
->
pending_operations_mtx
);
mid
->
pending_operations
-=
1
;
ABT_mutex_unlock
(
mid
->
pending_operations_mtx
);
}
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