File tree 1 file changed +13
-3
lines changed
1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -226,10 +226,20 @@ void reset_session_id() { g_session_id = 1; }
226
226
*
227
227
* @return The next session ID.
228
228
*/
229
+ /**
230
+ * @brief Generates the next unique session ID.
231
+ *
232
+ * This function generates a monotonically increasing session ID by incrementing
233
+ * the global session ID counter by 2. This ensures each new session gets a unique
234
+ * odd-numbered ID, while even numbers are reserved for other purposes.
235
+ *
236
+ * @return The newly generated session ID
237
+ *
238
+ * @note The function increments by 2 to maintain odd-numbered IDs
239
+ */
229
240
uint32_t get_next_session_id () {
230
- uint32_t id = g_session_id ;
231
- g_session_id += 2 ;
232
- return id ;
241
+ uint32_t current_id = __atomic_fetch_add (& g_session_id , 2 , __ATOMIC_SEQ_CST );
242
+ return current_id ;
233
243
}
234
244
235
245
/**
You can’t perform that action at this time.
0 commit comments