Skip to content

Commit 1726dc2

Browse files
committed
session server BUGFIX prevent data races
Was harmless but thread safety checkers complained. Fixes #586
1 parent 65863d8 commit 1726dc2

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/session_server.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,8 @@ static void
11411141
nc_server_init_cb_ctx(const struct ly_ctx *ctx)
11421142
{
11431143
struct lysc_node *rpc;
1144+
void *exp;
1145+
int result;
11441146

11451147
if (global_rpc_clb) {
11461148
/* expect it to handle these RPCs as well */
@@ -1152,14 +1154,20 @@ nc_server_init_cb_ctx(const struct ly_ctx *ctx)
11521154
if (ly_ctx_get_module_implemented(ctx, "ietf-netconf-monitoring")) {
11531155
rpc = (struct lysc_node *)lys_find_path(ctx, NULL, "/ietf-netconf-monitoring:get-schema", 0);
11541156
}
1155-
if (rpc && !rpc->priv) {
1156-
rpc->priv = nc_clb_default_get_schema;
1157+
if (rpc) {
1158+
exp = NULL;
1159+
ATOMIC_COMPARE_EXCHANGE_RELAXED(rpc->priv, exp, nc_clb_default_get_schema, result);
1160+
1161+
/* whatever */
1162+
(void)result;
11571163
}
11581164

11591165
/* set default <close-session> callback if not specified */
11601166
rpc = (struct lysc_node *)lys_find_path(ctx, NULL, "/ietf-netconf:close-session", 0);
1161-
if (rpc && !rpc->priv) {
1162-
rpc->priv = nc_clb_default_close_session;
1167+
if (rpc) {
1168+
exp = NULL;
1169+
ATOMIC_COMPARE_EXCHANGE_RELAXED(rpc->priv, exp, nc_clb_default_close_session, result);
1170+
(void)result;
11631171
}
11641172
}
11651173

0 commit comments

Comments
 (0)