mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-13 10:52:56 +01:00
Merge pull request #785 from pijyoi/mutex_signaler
support signaler_port in config.hpp set to value other than 0 and 5905
This commit is contained in:
commit
02a8d1ea4c
@ -69,6 +69,7 @@
|
||||
|
||||
#if defined ZMQ_HAVE_WINDOWS
|
||||
#include "windows.hpp"
|
||||
#include <tchar.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <netinet/tcp.h>
|
||||
@ -309,7 +310,11 @@ int zmq::signaler_t::make_fdpair (fd_t *r_, fd_t *w_)
|
||||
HANDLE sync = NULL;
|
||||
|
||||
// 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
|
||||
sync = CreateEvent (&sa, FALSE, TRUE, TEXT ("Global\\zmq-signaler-port-sync"));
|
||||
# else
|
||||
@ -321,6 +326,20 @@ int zmq::signaler_t::make_fdpair (fd_t *r_, fd_t *w_)
|
||||
|
||||
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
|
||||
// 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) {
|
||||
// Enter the critical section.
|
||||
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.
|
||||
@ -395,7 +414,11 @@ int zmq::signaler_t::make_fdpair (fd_t *r_, fd_t *w_)
|
||||
|
||||
if (sync != NULL) {
|
||||
// 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);
|
||||
|
||||
// Release the kernel object
|
||||
|
Loading…
Reference in New Issue
Block a user