--- BDB/BDB.xs 2009/07/14 19:29:23 1.68 +++ BDB/BDB.xs 2009/07/15 14:40:00 1.69 @@ -10,7 +10,7 @@ #include "schmorp.h" -// perl stupidly defines these as macros, breaking +// perl stupidly defines these as argument-less macros, breaking // lots and lots of code. #undef open #undef close @@ -249,7 +249,7 @@ static volatile unsigned int nreqs, nready, npending; static volatile unsigned int max_idle = 4; static volatile unsigned int max_outstanding = 0xffffffff; -static int respipe_osf [2], respipe [2] = { -1, -1 }; +static s_epipe respipe; static mutex_t reslock = X_MUTEX_INIT; static mutex_t reqlock = X_MUTEX_INIT; @@ -463,38 +463,8 @@ static void create_respipe (void) { -#ifdef _WIN32 - int arg; /* argg */ -#endif - int old_readfd = respipe [0]; - - if (respipe [1] >= 0) - respipe_close (S_TO_SOCKET (respipe [1])); - - if (s_pipe (respipe)) - croak ("unable to initialize result pipe"); - - if (old_readfd >= 0) - { - if (dup2 (S_TO_SOCKET (respipe [0]), S_TO_SOCKET (old_readfd)) < 0) - croak ("unable to initialize result pipe(2)"); - - respipe_close (respipe [0]); - respipe [0] = old_readfd; - } - -#ifdef _WIN32 - arg = 1; - if (ioctlsocket (S_TO_SOCKET (respipe [0]), FIONBIO, &arg) - || ioctlsocket (S_TO_SOCKET (respipe [1]), FIONBIO, &arg)) -#else - if (fcntl (respipe [0], F_SETFL, O_NONBLOCK) - || fcntl (respipe [1], F_SETFL, O_NONBLOCK)) -#endif - croak ("unable to initialize result pipe(3)"); - - respipe_osf [0] = S_TO_SOCKET (respipe [0]); - respipe_osf [1] = S_TO_SOCKET (respipe [1]); + if (s_epipe_renew (&respipe)) + croak ("BDB: unable to create event pipe"); } static void bdb_request (bdb_req req); @@ -654,10 +624,7 @@ maybe_start_thread (); - FD_ZERO (&rfd); - FD_SET (respipe [0], &rfd); - - PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); + s_epipe_wait (&respipe); } } @@ -687,12 +654,8 @@ --npending; if (!res_queue.size) - { - /* read any signals sent by the worker threads */ - char buf [4]; - while (respipe_read (respipe [0], buf, 4) == 4) - ; - } + /* read any signals sent by the worker threads */ + s_epipe_drain (&respipe); } X_UNLOCK (reslock); @@ -918,7 +881,7 @@ for (;;) { - ts.tv_sec = time (0) + IDLE_TIMEOUT; + ts.tv_sec = time (0) + IDLE_TIMEOUT; X_LOCK (reqlock); @@ -973,8 +936,7 @@ ++npending; if (!reqq_push (&res_queue, req)) - /* write a dummy byte to the pipe so fh becomes ready */ - respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1); + s_epipe_signal (&respipe); self->req = 0; worker_clear (self); @@ -1519,7 +1481,7 @@ poll_fileno () PROTOTYPE: CODE: - RETVAL = respipe [0]; + RETVAL = s_epipe_fd (&respipe); OUTPUT: RETVAL