-
Notifications
You must be signed in to change notification settings - Fork 0
/
impl-keyval-map-winerrh.h
42 lines (39 loc) · 1.42 KB
/
impl-keyval-map-winerrh.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// SPDX-License-Identifier: MIT
int add_win_errhandler_callback(MPI_Errhandler errhandler, WRAP_Win_errhandler_function * user_fn)
{
const std::lock_guard<std::mutex> lock(errhandler_win_cb_mutex);
#if DEBUG
printf("%s: insert_or_assign(errhandler=%lx, user_fn=%p)\n",
__func__, (intptr_t)errhandler, user_fn);
#endif
// insert_or_assign (C++17) inserts an element or assigns to the current element if the key already exists
auto [it,rc] = errhandler_win_cb_map.insert_or_assign(errhandler, user_fn);
return 1; // SUCCESS int{rc};
(void)it;
(void)rc;
}
int find_win_errhandler_callback(MPI_Errhandler errhandler, WRAP_Win_errhandler_function ** user_fn)
{
const std::lock_guard<std::mutex> lock(errhandler_win_cb_mutex);
try {
auto fn = errhandler_win_cb_map.at(errhandler);
#if DEBUG
printf("%s: lookup(errhandler=%lx) -> user_fn=%p\n",
__func__, (intptr_t)errhandler, user_fn);
#endif
if (fn != NULL) {
*user_fn = fn;
}
return 1;
}
catch (...) {
printf("%s: lookup(errhandler=%lx) failed\n", __func__, (intptr_t)errhandler);
return 0;
}
}
int remove_win_errhandler_callback(MPI_Errhandler errhandler)
{
const std::lock_guard<std::mutex> lock(errhandler_win_cb_mutex);
// returns the number of elements removed, so 0=failure and 1=success
return errhandler_win_cb_map.erase(errhandler);
}