Skip to content

Commit 4700394

Browse files
committed
server session BUGFIX make ps session count more deterministic
1 parent ef2b550 commit 4700394

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

src/session_server.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,12 +1126,25 @@ nc_ps_get_session(const struct nc_pollsession *ps, uint16_t idx)
11261126
API uint16_t
11271127
nc_ps_session_count(struct nc_pollsession *ps)
11281128
{
1129+
uint8_t q_id;
1130+
uint16_t session_count;
1131+
11291132
if (!ps) {
11301133
ERRARG("ps");
11311134
return 0;
11321135
}
11331136

1134-
return ps->session_count;
1137+
/* LOCK (just for memory barrier so that we read the current value) */
1138+
if (nc_ps_lock((struct nc_pollsession *)ps, &q_id, __func__)) {
1139+
return 0;
1140+
}
1141+
1142+
session_count = ps->session_count;
1143+
1144+
/* UNLOCK */
1145+
nc_ps_unlock((struct nc_pollsession *)ps, q_id, __func__);
1146+
1147+
return session_count;
11351148
}
11361149

11371150
/* should be called holding the session RPC lock! IO lock will be acquired as needed

0 commit comments

Comments
 (0)