/* Mutex to guard the initialization of array of socket_info structures */
static pthread_mutex_t sockets_mutex;
+/* Mutex to guard the socket reset in swrap_close() and swrap_remove_stale() */
+static pthread_mutex_t socket_reset_mutex;
+
/* Mutex to synchronize access to first free index in socket_info array */
static pthread_mutex_t first_free_mutex;
SWRAP_LOG(SWRAP_LOG_TRACE, "remove stale wrapper for %d", fd);
+ swrap_mutex_lock(&socket_reset_mutex);
+
si_index = find_socket_info_index(fd);
if (si_index == -1) {
+ swrap_mutex_unlock(&socket_reset_mutex);
return;
}
- si = swrap_get_socket_info(si_index);
-
reset_socket_info_index(fd);
+ swrap_mutex_unlock(&socket_reset_mutex);
+
+ si = swrap_get_socket_info(si_index);
+
swrap_mutex_lock(&first_free_mutex);
SWRAP_LOCK_SI(si);
int si_index;
int ret;
+ swrap_mutex_lock(&socket_reset_mutex);
+
si_index = find_socket_info_index(fd);
if (si_index == -1) {
+ swrap_mutex_unlock(&socket_reset_mutex);
return libc_close(fd);
}
reset_socket_info_index(fd);
+ swrap_mutex_unlock(&socket_reset_mutex);
+
si = swrap_get_socket_info(si_index);
swrap_mutex_lock(&first_free_mutex);
exit(-1);
}
+ ret = socket_wrapper_init_mutex(&socket_reset_mutex);
+ if (ret != 0) {
+ SWRAP_LOG(SWRAP_LOG_ERROR,
+ "Failed to initialize pthread mutex");
+ exit(-1);
+ }
+
ret = socket_wrapper_init_mutex(&first_free_mutex);
if (ret != 0) {
SWRAP_LOG(SWRAP_LOG_ERROR,