Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nanomsg xp deadlock fix #4

Open
wants to merge 2 commits into
base: winxp
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/aio/usock_win.inc
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ void nn_usock_accept (struct nn_usock *self, struct nn_usock *listener)
/* Wait for the incoming connection. */
memset (&listener->in.olpd, 0, sizeof (listener->in.olpd));
brc = AcceptEx (listener->s, self->s, listener->ainfo, 0, 256, 256, &nbytes,
&listener->in.olpd);
&listener->in.olpd);

/* Immediate success. */
if (nn_fast (brc == TRUE)) {
Expand Down
55 changes: 0 additions & 55 deletions src/core/global.c
Original file line number Diff line number Diff line change
Expand Up @@ -1112,60 +1112,6 @@ static void nn_global_submit_errors (int i, struct nn_sock *s,
}
}

static void nn_global_submit_statistics ()
{
int i;
struct nn_sock *s;

/* TODO(tailhook) optimized it to use nsocks and unused */
for(i = 0; i < NN_MAX_SOCKETS; ++i) {

nn_glock_lock ();
s = self.socks [i];
if (!s) {
nn_glock_unlock ();
continue;
}
if (i == self.statistics_socket) {
nn_glock_unlock ();
continue;
}
nn_ctx_enter (&s->ctx);
nn_glock_unlock ();

nn_global_submit_counter (i, s,
"established_connections", s->statistics.established_connections);
nn_global_submit_counter (i, s,
"accepted_connections", s->statistics.accepted_connections);
nn_global_submit_counter (i, s,
"dropped_connections", s->statistics.dropped_connections);
nn_global_submit_counter (i, s,
"broken_connections", s->statistics.broken_connections);
nn_global_submit_counter (i, s,
"connect_errors", s->statistics.connect_errors);
nn_global_submit_counter (i, s,
"bind_errors", s->statistics.bind_errors);
nn_global_submit_counter (i, s,
"accept_errors", s->statistics.accept_errors);
nn_global_submit_counter (i, s,
"messages_sent", s->statistics.messages_sent);
nn_global_submit_counter (i, s,
"messages_received", s->statistics.messages_received);
nn_global_submit_counter (i, s,
"bytes_sent", s->statistics.bytes_sent);
nn_global_submit_counter (i, s,
"bytes_received", s->statistics.bytes_received);
nn_global_submit_level (i, s,
"current_connections", s->statistics.current_connections);
nn_global_submit_level (i, s,
"inprogress_connections", s->statistics.inprogress_connections);
nn_global_submit_level (i, s,
"current_snd_priority", s->statistics.current_snd_priority);
nn_global_submit_errors (i, s,
"current_ep_errors", s->statistics.current_ep_errors);
nn_ctx_leave (&s->ctx);
}
}

static int nn_global_create_ep (int s, const char *addr, int bind)
{
Expand Down Expand Up @@ -1285,7 +1231,6 @@ static void nn_global_handler (struct nn_fsm *self,
case NN_GLOBAL_SRC_STAT_TIMER:
switch (type) {
case NN_TIMER_TIMEOUT:
nn_global_submit_statistics ();
/* No need to change state */
nn_timer_stop (&global->stat_timer);
return;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/glock.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ static void nn_glock_init (void)
InitializeCriticalSection (&nn_glock_cs);
}

void nn_glock_lock (void)
void _nn_glock_lock (void)
{
nn_glock_init ();
EnterCriticalSection (&nn_glock_cs);
}

void nn_glock_unlock (void)
void _nn_glock_unlock (void)
{
nn_glock_init ();
LeaveCriticalSection (&nn_glock_cs);
Expand Down
32 changes: 30 additions & 2 deletions src/utils/glock.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,36 @@
/* Implementation of a global lock (critical section). The lock is meant to
be used to synchronise the initialisation/termination of the library. */

void nn_glock_lock (void);
void nn_glock_unlock (void);

#ifdef GLOBCAL_LOCK_DBG
#define nn_glock_lock() do { \
DWORD pid = GetCurrentProcessId(); \
FILE *fp = fopen("nanomsg-lock.log", "a"); \
fprintf(fp, "pid=%d:%s:%d[%s]: nn_glock_lock() IN\n", pid, __FILE__, __LINE__, __FUNCTION__); \
_nn_glock_lock(); \
fprintf(fp, "pid=%d:%s:%d[%s]: nn_glock_lock() OUT\n", pid, __FILE__, __LINE__, __FUNCTION__); \
fclose(fp); \
} while (0)


#define nn_glock_unlock() do { \
FILE *fp = fopen("nanomsg-lock.log", "a"); \
DWORD pid = GetCurrentProcessId(); \
fprintf(fp, "pid=%d:%s:%d[%s]: nn_glock_unlock() IN\n", pid, __FILE__, __LINE__, __FUNCTION__); \
_nn_glock_unlock(); \
fprintf(fp, "pid=%d:%s:%d[%s]: nn_glock_unlock() OUT\n", pid, __FILE__, __LINE__, __FUNCTION__); \
fclose(fp); \
} while (0)

#else

#define nn_glock_lock() _nn_glock_lock()
#define nn_glock_unlock() _nn_glock_unlock()

#endif

void _nn_glock_lock (void);
void _nn_glock_unlock (void);

#endif