From: Mazet Laurent Date: Thu, 12 Jun 2025 09:43:22 +0000 (+0200) Subject: add thread protection X-Git-Tag: v1.0~8 X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=1a7aa77de900557f710a17cb3c539e86439f2c8b;p=morep.git add thread protection --- diff --git a/morep.c b/morep.c index b9be600..254428e 100644 --- a/morep.c +++ b/morep.c @@ -278,9 +278,13 @@ int find_unused_morep (int sock) VERBOSE (morep, TRACE, PRINTF ("find_unused_morep\n")); for (int i = 0; i < MAX_MOREP_NUMBER; i++) { - // FIXIT: not thread safe +#if 0 + i// FIXIT: not thread safe if (MOREP_list[i]->sock < 0) { MOREP_list[i]->sock = sock; +#else + if (__sync_bool_compare_and_swap (&MOREP_list[i]->sock, -1, sock)) { +#endif VERBOSE (morep, DEBUG, PRINTF ("find morep: %d\n", i)); return i; } @@ -351,6 +355,10 @@ int MOREP_Connect (char *url) memcpy (MOREP_list[index]->tx_buffer + 6, sock_addr.sll_addr, 6); MOREP_list[index]->n_etype = htons (addr.ether_type); memcpy (MOREP_list[index]->tx_buffer + 12, (void *) &(MOREP_list[index]->n_etype), 2); + } else { + close (sock); + VERBOSE (morep, ERROR, PRINTF ("can't store MOREP for socket %d\n", sock)); + return -1; } return sock;