Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
margo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
13
Issues
13
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
sds
margo
Commits
70ef3d41
Commit
70ef3d41
authored
Sep 25, 2017
by
Matthieu Dorier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added mutex to protect access to the cache
parent
c7262ef5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
6 deletions
+23
-6
src/margo.c
src/margo.c
+23
-6
No files found.
src/margo.c
View file @
70ef3d41
...
...
@@ -91,6 +91,7 @@ struct margo_instance
/* linked list of free hg handles and a hash of in-use handles */
struct
margo_handle_cache_el
*
free_handle_list
;
struct
margo_handle_cache_el
*
used_handle_hash
;
ABT_mutex
handle_cache_mtx
;
/* mutex protecting access to above caches */
/* optional diagnostics data tracking */
/* NOTE: technically the following fields are subject to races if they
...
...
@@ -578,7 +579,7 @@ hg_return_t margo_addr_to_string(
hg_return_t
margo_create
(
margo_instance_id
mid
,
hg_addr_t
addr
,
hg_id_t
id
,
hg_handle_t
*
handle
)
{
hg_return_t
hret
;
hg_return_t
hret
=
HG_OTHER_ERROR
;
/* look for a handle to reuse */
hret
=
margo_handle_cache_get
(
mid
,
addr
,
id
,
handle
);
...
...
@@ -594,7 +595,7 @@ hg_return_t margo_create(margo_instance_id mid, hg_addr_t addr,
hg_return_t
margo_destroy
(
hg_handle_t
handle
)
{
margo_instance_id
mid
;
hg_return_t
hret
;
hg_return_t
hret
=
HG_OTHER_ERROR
;
/* use the handle to get the associated mid */
mid
=
margo_hg_handle_get_instance
(
handle
);
...
...
@@ -1177,6 +1178,9 @@ static hg_return_t margo_handle_cache_init(margo_instance_id mid)
int
i
;
struct
margo_handle_cache_el
*
el
;
hg_return_t
hret
=
HG_SUCCESS
;
int
ret
;
ret
=
ABT_mutex_create
(
&
(
mid
->
handle_cache_mtx
));
for
(
i
=
0
;
i
<
DEFAULT_MERCURY_HANDLE_CACHE_SIZE
;
i
++
)
{
...
...
@@ -1216,6 +1220,8 @@ static void margo_handle_cache_destroy(margo_instance_id mid)
free
(
el
);
}
ABT_mutex_free
(
mid
->
handle_cache_mtx
);
return
;
}
...
...
@@ -1223,12 +1229,15 @@ static hg_return_t margo_handle_cache_get(margo_instance_id mid,
hg_addr_t
addr
,
hg_id_t
id
,
hg_handle_t
*
handle
)
{
struct
margo_handle_cache_el
*
el
;
hg_return_t
hret
;
hg_return_t
hret
=
HG_SUCCESS
;
ABT_mutex_lock
(
mid
->
handle_cache_mtx
);
if
(
!
mid
->
free_handle_list
)
{
/* if no available handles, just fall through */
return
HG_OTHER_ERROR
;
hret
=
HG_OTHER_ERROR
;
goto
finish
;
}
/* pop first element from the free handle list */
...
...
@@ -1249,6 +1258,8 @@ static hg_return_t margo_handle_cache_get(margo_instance_id mid,
LL_APPEND
(
mid
->
free_handle_list
,
el
);
}
finish:
ABT_mutex_unlock
(
mid
->
handle_cache_mtx
);
return
hret
;
}
...
...
@@ -1256,13 +1267,17 @@ static hg_return_t margo_handle_cache_put(margo_instance_id mid,
hg_handle_t
handle
)
{
struct
margo_handle_cache_el
*
el
;
hg_return_t
hret
=
HG_SUCCESS
;
ABT_mutex_lock
(
mid
->
handle_cache_mtx
);
/* look for handle in the in-use hash */
HASH_FIND
(
hh
,
mid
->
used_handle_hash
,
&
handle
,
sizeof
(
hg_handle_t
),
el
);
if
(
!
el
)
{
/* this handle was manually allocated -- just fall through */
return
HG_OTHER_ERROR
;
hret
=
HG_OTHER_ERROR
;
goto
finish
;
}
/* remove from the in-use hash */
...
...
@@ -1271,5 +1286,7 @@ static hg_return_t margo_handle_cache_put(margo_instance_id mid,
/* add to the tail of the free handle list */
LL_APPEND
(
mid
->
free_handle_list
,
el
);
return
HG_SUCCESS
;
finish:
ABT_mutex_unlock
(
mid
->
handle_cache_mtx
);
return
hret
;
}
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