mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-10 07:56:09 +00:00
use mutex implementation if fixed signaler_port!=5905
This commit is contained in:
parent
b4395d15f9
commit
7f22995e35
@ -69,6 +69,7 @@
|
|||||||
|
|
||||||
#if defined ZMQ_HAVE_WINDOWS
|
#if defined ZMQ_HAVE_WINDOWS
|
||||||
#include "windows.hpp"
|
#include "windows.hpp"
|
||||||
|
#include <tchar.h>
|
||||||
#else
|
#else
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <netinet/tcp.h>
|
#include <netinet/tcp.h>
|
||||||
@ -309,7 +310,11 @@ int zmq::signaler_t::make_fdpair (fd_t *r_, fd_t *w_)
|
|||||||
HANDLE sync = NULL;
|
HANDLE sync = NULL;
|
||||||
|
|
||||||
// Create critical section only if using fixed signaler port
|
// Create critical section only if using fixed signaler port
|
||||||
if (signaler_port != 0) {
|
// Use problematic Event implementation for compatibility if using old port 5905.
|
||||||
|
// Otherwise use Mutex implementation.
|
||||||
|
int event_signaler_port = 5905;
|
||||||
|
|
||||||
|
if (signaler_port == event_signaler_port) {
|
||||||
# if !defined _WIN32_WCE
|
# if !defined _WIN32_WCE
|
||||||
sync = CreateEvent (&sa, FALSE, TRUE, TEXT ("Global\\zmq-signaler-port-sync"));
|
sync = CreateEvent (&sa, FALSE, TRUE, TEXT ("Global\\zmq-signaler-port-sync"));
|
||||||
# else
|
# else
|
||||||
@ -321,6 +326,20 @@ int zmq::signaler_t::make_fdpair (fd_t *r_, fd_t *w_)
|
|||||||
|
|
||||||
win_assert (sync != NULL);
|
win_assert (sync != NULL);
|
||||||
}
|
}
|
||||||
|
else if (signaler_port != 0) {
|
||||||
|
TCHAR mutex_name[64];
|
||||||
|
_stprintf (mutex_name, TEXT ("Global\\zmq-signaler-port-%d"), signaler_port);
|
||||||
|
|
||||||
|
# if !defined _WIN32_WCE
|
||||||
|
sync = CreateMutex (&sa, FALSE, mutex_name);
|
||||||
|
# else
|
||||||
|
sync = CreateMutex (NULL, FALSE, mutex_name);
|
||||||
|
# endif
|
||||||
|
if (sync == NULL && GetLastError () == ERROR_ACCESS_DENIED)
|
||||||
|
sync = OpenMutex (SYNCHRONIZE, FALSE, mutex_name);
|
||||||
|
|
||||||
|
win_assert (sync != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
// Windows has no 'socketpair' function. CreatePipe is no good as pipe
|
// Windows has no 'socketpair' function. CreatePipe is no good as pipe
|
||||||
// handles cannot be polled on. Here we create the socketpair by hand.
|
// handles cannot be polled on. Here we create the socketpair by hand.
|
||||||
@ -361,7 +380,7 @@ int zmq::signaler_t::make_fdpair (fd_t *r_, fd_t *w_)
|
|||||||
if (sync != NULL) {
|
if (sync != NULL) {
|
||||||
// Enter the critical section.
|
// Enter the critical section.
|
||||||
DWORD dwrc = WaitForSingleObject (sync, INFINITE);
|
DWORD dwrc = WaitForSingleObject (sync, INFINITE);
|
||||||
zmq_assert (dwrc == WAIT_OBJECT_0);
|
zmq_assert (dwrc == WAIT_OBJECT_0 || dwrc == WAIT_ABANDONED);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bind listening socket to signaler port.
|
// Bind listening socket to signaler port.
|
||||||
@ -395,7 +414,11 @@ int zmq::signaler_t::make_fdpair (fd_t *r_, fd_t *w_)
|
|||||||
|
|
||||||
if (sync != NULL) {
|
if (sync != NULL) {
|
||||||
// Exit the critical section.
|
// Exit the critical section.
|
||||||
BOOL brc = SetEvent (sync);
|
BOOL brc;
|
||||||
|
if (signaler_port == event_signaler_port)
|
||||||
|
brc = SetEvent (sync);
|
||||||
|
else
|
||||||
|
brc = ReleaseMutex (sync);
|
||||||
win_assert (brc != 0);
|
win_assert (brc != 0);
|
||||||
|
|
||||||
// Release the kernel object
|
// Release the kernel object
|
||||||
|
Loading…
x
Reference in New Issue
Block a user