ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/BDB/BDB.xs
(Generate patch)

Comparing BDB/BDB.xs (file contents):
Revision 1.8 by root, Sun Feb 11 22:07:23 2007 UTC vs.
Revision 1.13 by root, Sun Jul 8 11:12:12 2007 UTC

1/* solaris */ 1#include "xthread.h"
2#define _POSIX_PTHREAD_SEMANTICS 1
3
4#if __linux && !defined(_GNU_SOURCE)
5# define _GNU_SOURCE
6#endif
7
8/* just in case */
9#define _REENTRANT 1
10 2
11#include <errno.h> 3#include <errno.h>
12 4
13#include "EXTERN.h" 5#include "EXTERN.h"
14#include "perl.h" 6#include "perl.h"
15#include "XSUB.h" 7#include "XSUB.h"
16 8
17#include <pthread.h> 9// perl stupidly defines these as macros, breaking
10// lots and lots of code.
11#undef open
12#undef close
13#undef abort
14#undef malloc
15#undef free
16#undef send
18 17
19#include <stddef.h> 18#include <stddef.h>
20#include <stdlib.h> 19#include <stdlib.h>
21#include <errno.h> 20#include <errno.h>
22#include <sys/time.h>
23#include <sys/types.h> 21#include <sys/types.h>
24#include <limits.h> 22#include <limits.h>
25#include <unistd.h>
26#include <fcntl.h> 23#include <fcntl.h>
27 24
25#ifndef _WIN32
26# include <sys/time.h>
27# include <unistd.h>
28#endif
29
28#include <db.h> 30#include <db.h>
31
32#if DB_VERSION_MAJOR < 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 4)
33# error you need Berkeley DB 4.4 or newer installed
34#endif
29 35
30/* number of seconds after which idle threads exit */ 36/* number of seconds after which idle threads exit */
31#define IDLE_TIMEOUT 10 37#define IDLE_TIMEOUT 10
32
33/* wether word reads are potentially non-atomic.
34 * this is conservatice, likely most arches this runs
35 * on have atomic word read/writes.
36 */
37#ifndef WORDACCESS_UNSAFE
38# if __i386 || __x86_64
39# define WORDACCESS_UNSAFE 0
40# else
41# define WORDACCESS_UNSAFE 1
42# endif
43#endif
44 38
45typedef DB_ENV DB_ENV_ornull; 39typedef DB_ENV DB_ENV_ornull;
46typedef DB_TXN DB_TXN_ornull; 40typedef DB_TXN DB_TXN_ornull;
47typedef DBC DBC_ornull; 41typedef DBC DBC_ornull;
48typedef DB DB_ornull; 42typedef DB DB_ornull;
51typedef SV SV8; /* byte-sv, used for argument-checking */ 45typedef SV SV8; /* byte-sv, used for argument-checking */
52typedef char *octetstring; 46typedef char *octetstring;
53 47
54static SV *prepare_cb; 48static SV *prepare_cb;
55 49
56static inline char * 50static char *
57strdup_ornull (const char *s) 51strdup_ornull (const char *s)
58{ 52{
59 return s ? strdup (s) : 0; 53 return s ? strdup (s) : 0;
60} 54}
61 55
62static inline void 56static void
63sv_to_dbt (DBT *dbt, SV *sv) 57sv_to_dbt (DBT *dbt, SV *sv)
64{ 58{
65 STRLEN len; 59 STRLEN len;
66 char *data = SvPVbyte (sv, len); 60 char *data = SvPVbyte (sv, len);
67 61
69 memcpy (dbt->data, data, len); 63 memcpy (dbt->data, data, len);
70 dbt->size = len; 64 dbt->size = len;
71 dbt->flags = DB_DBT_REALLOC; 65 dbt->flags = DB_DBT_REALLOC;
72} 66}
73 67
74static inline void 68static void
75dbt_to_sv (SV *sv, DBT *dbt) 69dbt_to_sv (SV *sv, DBT *dbt)
76{ 70{
77 if (sv) 71 if (sv)
78 { 72 {
79 SvREADONLY_off (sv); 73 SvREADONLY_off (sv);
143 137
144static int next_pri = DEFAULT_PRI + PRI_BIAS; 138static int next_pri = DEFAULT_PRI + PRI_BIAS;
145 139
146static unsigned int started, idle, wanted; 140static unsigned int started, idle, wanted;
147 141
148#if __linux && defined (PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP)
149# define AIO_MUTEX_INIT PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
150#else
151# define AIO_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
152#endif
153
154#define LOCK(mutex) pthread_mutex_lock (&(mutex))
155#define UNLOCK(mutex) pthread_mutex_unlock (&(mutex))
156
157/* worker threads management */ 142/* worker threads management */
158static pthread_mutex_t wrklock = AIO_MUTEX_INIT; 143static mutex_t wrklock = X_MUTEX_INIT;
159 144
160typedef struct worker { 145typedef struct worker {
161 /* locked by wrklock */ 146 /* locked by wrklock */
162 struct worker *prev, *next; 147 struct worker *prev, *next;
163 148
164 pthread_t tid; 149 thread_t tid;
165 150
166 /* locked by reslock, reqlock or wrklock */ 151 /* locked by reslock, reqlock or wrklock */
167 aio_req req; /* currently processed request */ 152 aio_req req; /* currently processed request */
168 void *dbuf; 153 void *dbuf;
169 DIR *dirp; 154 DIR *dirp;
184} 169}
185 170
186static volatile unsigned int nreqs, nready, npending; 171static volatile unsigned int nreqs, nready, npending;
187static volatile unsigned int max_idle = 4; 172static volatile unsigned int max_idle = 4;
188static volatile unsigned int max_outstanding = 0xffffffff; 173static volatile unsigned int max_outstanding = 0xffffffff;
189static int respipe [2]; 174static int respipe [2], respipe_osf [2];
190 175
191static pthread_mutex_t reslock = AIO_MUTEX_INIT; 176static mutex_t reslock = X_MUTEX_INIT;
192static pthread_mutex_t reqlock = AIO_MUTEX_INIT; 177static mutex_t reqlock = X_MUTEX_INIT;
193static pthread_cond_t reqwait = PTHREAD_COND_INITIALIZER; 178static cond_t reqwait = X_COND_INIT;
194 179
195#if WORDACCESS_UNSAFE 180#if WORDACCESS_UNSAFE
196 181
197static unsigned int get_nready () 182static unsigned int get_nready ()
198{ 183{
199 unsigned int retval; 184 unsigned int retval;
200 185
201 LOCK (reqlock); 186 X_LOCK (reqlock);
202 retval = nready; 187 retval = nready;
203 UNLOCK (reqlock); 188 X_UNLOCK (reqlock);
204 189
205 return retval; 190 return retval;
206} 191}
207 192
208static unsigned int get_npending () 193static unsigned int get_npending ()
209{ 194{
210 unsigned int retval; 195 unsigned int retval;
211 196
212 LOCK (reslock); 197 X_LOCK (reslock);
213 retval = npending; 198 retval = npending;
214 UNLOCK (reslock); 199 X_UNLOCK (reslock);
215 200
216 return retval; 201 return retval;
217} 202}
218 203
219static unsigned int get_nthreads () 204static unsigned int get_nthreads ()
220{ 205{
221 unsigned int retval; 206 unsigned int retval;
222 207
223 LOCK (wrklock); 208 X_LOCK (wrklock);
224 retval = started; 209 retval = started;
225 UNLOCK (wrklock); 210 X_UNLOCK (wrklock);
226 211
227 return retval; 212 return retval;
228} 213}
229 214
230#else 215#else
365 free (req->buf1); 350 free (req->buf1);
366 free (req->buf2); 351 free (req->buf2);
367 Safefree (req); 352 Safefree (req);
368} 353}
369 354
370static void *aio_proc (void *arg); 355#ifdef USE_SOCKETS_AS_HANDLES
356# define TO_SOCKET(x) (win32_get_osfhandle (x))
357#else
358# define TO_SOCKET(x) (x)
359#endif
360
361static void
362create_pipe (int fd[2])
363{
364#ifdef _WIN32
365 int arg = 1;
366 if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, fd)
367 || ioctlsocket (TO_SOCKET (fd [0]), FIONBIO, &arg)
368 || ioctlsocket (TO_SOCKET (fd [1]), FIONBIO, &arg))
369#else
370 if (pipe (fd)
371 || fcntl (fd [0], F_SETFL, O_NONBLOCK)
372 || fcntl (fd [1], F_SETFL, O_NONBLOCK))
373#endif
374 croak ("unable to initialize result pipe");
375
376 respipe_osf [0] = TO_SOCKET (respipe [0]);
377 respipe_osf [1] = TO_SOCKET (respipe [1]);
378}
379
380X_THREAD_PROC (bdb_proc);
371 381
372static void start_thread (void) 382static void start_thread (void)
373{ 383{
374 sigset_t fullsigset, oldsigset;
375 pthread_attr_t attr;
376
377 worker *wrk = calloc (1, sizeof (worker)); 384 worker *wrk = calloc (1, sizeof (worker));
378 385
379 if (!wrk) 386 if (!wrk)
380 croak ("unable to allocate worker thread data"); 387 croak ("unable to allocate worker thread data");
381 388
382 pthread_attr_init (&attr);
383 pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
384#ifdef PTHREAD_SCOPE_PROCESS
385 pthread_attr_setscope (&attr, PTHREAD_SCOPE_PROCESS);
386#endif
387
388 sigfillset (&fullsigset);
389
390 LOCK (wrklock); 389 X_LOCK (wrklock);
391 pthread_sigmask (SIG_SETMASK, &fullsigset, &oldsigset);
392
393 if (pthread_create (&wrk->tid, &attr, aio_proc, (void *)wrk) == 0) 390 if (thread_create (&wrk->tid, bdb_proc, (void *)wrk))
394 { 391 {
395 wrk->prev = &wrk_first; 392 wrk->prev = &wrk_first;
396 wrk->next = wrk_first.next; 393 wrk->next = wrk_first.next;
397 wrk_first.next->prev = wrk; 394 wrk_first.next->prev = wrk;
398 wrk_first.next = wrk; 395 wrk_first.next = wrk;
399 ++started; 396 ++started;
400 } 397 }
401 else 398 else
402 free (wrk); 399 free (wrk);
403 400
404 pthread_sigmask (SIG_SETMASK, &oldsigset, 0);
405 UNLOCK (wrklock); 401 X_UNLOCK (wrklock);
406} 402}
407 403
408static void maybe_start_thread () 404static void maybe_start_thread ()
409{ 405{
410 if (get_nthreads () >= wanted) 406 if (get_nthreads () >= wanted)
422 SV *wait_callback = 0; 418 SV *wait_callback = 0;
423 419
424 // synthesize callback if none given 420 // synthesize callback if none given
425 if (!SvOK (req->callback)) 421 if (!SvOK (req->callback))
426 { 422 {
423 int count;
424
427 dSP; 425 dSP;
428 PUSHMARK (SP); 426 PUSHMARK (SP);
429 PUTBACK; 427 PUTBACK;
430 int count = call_sv (prepare_cb, G_ARRAY); 428 count = call_sv (prepare_cb, G_ARRAY);
431 SPAGAIN; 429 SPAGAIN;
432 430
433 if (count != 2) 431 if (count != 2)
434 croak ("prepare callback must return exactly two values\n"); 432 croak ("prepare callback must return exactly two values\n");
435 433
438 req->callback = SvREFCNT_inc (POPs); 436 req->callback = SvREFCNT_inc (POPs);
439 } 437 }
440 438
441 ++nreqs; 439 ++nreqs;
442 440
443 LOCK (reqlock); 441 X_LOCK (reqlock);
444 ++nready; 442 ++nready;
445 reqq_push (&req_queue, req); 443 reqq_push (&req_queue, req);
446 pthread_cond_signal (&reqwait); 444 X_COND_SIGNAL (reqwait);
447 UNLOCK (reqlock); 445 X_UNLOCK (reqlock);
448 446
449 maybe_start_thread (); 447 maybe_start_thread ();
450 448
451 if (wait_callback) 449 if (wait_callback)
452 { 450 {
465 Newz (0, req, 1, aio_cb); 463 Newz (0, req, 1, aio_cb);
466 464
467 req->type = REQ_QUIT; 465 req->type = REQ_QUIT;
468 req->pri = PRI_MAX + PRI_BIAS; 466 req->pri = PRI_MAX + PRI_BIAS;
469 467
470 LOCK (reqlock); 468 X_LOCK (reqlock);
471 reqq_push (&req_queue, req); 469 reqq_push (&req_queue, req);
472 pthread_cond_signal (&reqwait); 470 X_COND_SIGNAL (reqwait);
473 UNLOCK (reqlock); 471 X_UNLOCK (reqlock);
474 472
475 LOCK (wrklock); 473 X_LOCK (wrklock);
476 --started; 474 --started;
477 UNLOCK (wrklock); 475 X_UNLOCK (wrklock);
478} 476}
479 477
480static void set_max_idle (int nthreads) 478static void set_max_idle (int nthreads)
481{ 479{
482 if (WORDACCESS_UNSAFE) LOCK (reqlock); 480 if (WORDACCESS_UNSAFE) X_LOCK (reqlock);
483 max_idle = nthreads <= 0 ? 1 : nthreads; 481 max_idle = nthreads <= 0 ? 1 : nthreads;
484 if (WORDACCESS_UNSAFE) UNLOCK (reqlock); 482 if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock);
485} 483}
486 484
487static void min_parallel (int nthreads) 485static void min_parallel (int nthreads)
488{ 486{
489 if (wanted < nthreads) 487 if (wanted < nthreads)
504 fd_set rfd; 502 fd_set rfd;
505 503
506 while (nreqs) 504 while (nreqs)
507 { 505 {
508 int size; 506 int size;
509 if (WORDACCESS_UNSAFE) LOCK (reslock); 507 if (WORDACCESS_UNSAFE) X_LOCK (reslock);
510 size = res_queue.size; 508 size = res_queue.size;
511 if (WORDACCESS_UNSAFE) UNLOCK (reslock); 509 if (WORDACCESS_UNSAFE) X_UNLOCK (reslock);
512 510
513 if (size) 511 if (size)
514 return; 512 return;
515 513
516 maybe_start_thread (); 514 maybe_start_thread ();
517 515
518 FD_ZERO(&rfd); 516 FD_ZERO (&rfd);
519 FD_SET(respipe [0], &rfd); 517 FD_SET (respipe [0], &rfd);
520 518
521 select (respipe [0] + 1, &rfd, 0, 0, 0); 519 PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0);
522 } 520 }
523} 521}
524 522
525static int poll_cb () 523static int poll_cb ()
526{ 524{
538 { 536 {
539 for (;;) 537 for (;;)
540 { 538 {
541 maybe_start_thread (); 539 maybe_start_thread ();
542 540
543 LOCK (reslock); 541 X_LOCK (reslock);
544 req = reqq_shift (&res_queue); 542 req = reqq_shift (&res_queue);
545 543
546 if (req) 544 if (req)
547 { 545 {
548 --npending; 546 --npending;
549 547
550 if (!res_queue.size) 548 if (!res_queue.size)
551 { 549 {
552 /* read any signals sent by the worker threads */ 550 /* read any signals sent by the worker threads */
553 char buf [4]; 551 char buf [4];
554 while (read (respipe [0], buf, 4) == 4) 552 while (respipe_read (respipe [0], buf, 4) == 4)
555 ; 553 ;
556 } 554 }
557 } 555 }
558 556
559 UNLOCK (reslock); 557 X_UNLOCK (reslock);
560 558
561 if (!req) 559 if (!req)
562 break; 560 break;
563 561
564 --nreqs; 562 --nreqs;
594 } 592 }
595 593
596 return count; 594 return count;
597} 595}
598 596
599static void create_pipe ()
600{
601 if (pipe (respipe))
602 croak ("unable to initialize result pipe");
603
604 if (fcntl (respipe [0], F_SETFL, O_NONBLOCK))
605 croak ("cannot set result pipe to nonblocking mode");
606
607 if (fcntl (respipe [1], F_SETFL, O_NONBLOCK))
608 croak ("cannot set result pipe to nonblocking mode");
609}
610
611/*****************************************************************************/ 597/*****************************************************************************/
612 598
613static void *aio_proc (void *thr_arg) 599X_THREAD_PROC (bdb_proc)
614{ 600{
615 aio_req req; 601 aio_req req;
616 struct timespec ts; 602 struct timespec ts;
617 worker *self = (worker *)thr_arg; 603 worker *self = (worker *)thr_arg;
618 604
619 /* try to distribute timeouts somewhat evenly */ 605 /* try to distribute timeouts somewhat evenly */
620 ts.tv_nsec = (((unsigned long)self + (unsigned long)ts.tv_sec) & 1023UL) 606 ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL);
621 * (1000000000UL / 1024UL);
622 607
623 for (;;) 608 for (;;)
624 { 609 {
625 ts.tv_sec = time (0) + IDLE_TIMEOUT; 610 ts.tv_sec = time (0) + IDLE_TIMEOUT;
626 611
627 LOCK (reqlock); 612 X_LOCK (reqlock);
628 613
629 for (;;) 614 for (;;)
630 { 615 {
631 self->req = req = reqq_shift (&req_queue); 616 self->req = req = reqq_shift (&req_queue);
632 617
633 if (req) 618 if (req)
634 break; 619 break;
635 620
636 ++idle; 621 ++idle;
637 622
638 if (pthread_cond_timedwait (&reqwait, &reqlock, &ts) 623 if (X_COND_TIMEDWAIT (reqwait, reqlock, ts)
639 == ETIMEDOUT) 624 == ETIMEDOUT)
640 { 625 {
641 if (idle > max_idle) 626 if (idle > max_idle)
642 { 627 {
643 --idle; 628 --idle;
644 UNLOCK (reqlock); 629 X_UNLOCK (reqlock);
645 LOCK (wrklock); 630 X_LOCK (wrklock);
646 --started; 631 --started;
647 UNLOCK (wrklock); 632 X_UNLOCK (wrklock);
648 goto quit; 633 goto quit;
649 } 634 }
650 635
651 /* we are allowed to idle, so do so without any timeout */ 636 /* we are allowed to idle, so do so without any timeout */
652 pthread_cond_wait (&reqwait, &reqlock); 637 X_COND_WAIT (reqwait, reqlock);
653 ts.tv_sec = time (0) + IDLE_TIMEOUT; 638 ts.tv_sec = time (0) + IDLE_TIMEOUT;
654 } 639 }
655 640
656 --idle; 641 --idle;
657 } 642 }
658 643
659 --nready; 644 --nready;
660 645
661 UNLOCK (reqlock); 646 X_UNLOCK (reqlock);
662 647
663 switch (req->type) 648 switch (req->type)
664 { 649 {
665 case REQ_QUIT: 650 case REQ_QUIT:
666 goto quit; 651 goto quit;
780 default: 765 default:
781 req->result = ENOSYS; 766 req->result = ENOSYS;
782 break; 767 break;
783 } 768 }
784 769
785 LOCK (reslock); 770 X_LOCK (reslock);
786 771
787 ++npending; 772 ++npending;
788 773
789 if (!reqq_push (&res_queue, req)) 774 if (!reqq_push (&res_queue, req))
790 /* write a dummy byte to the pipe so fh becomes ready */ 775 /* write a dummy byte to the pipe so fh becomes ready */
791 write (respipe [1], &respipe, 1); 776 respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1);
792 777
793 self->req = 0; 778 self->req = 0;
794 worker_clear (self); 779 worker_clear (self);
795 780
796 UNLOCK (reslock); 781 X_UNLOCK (reslock);
797 } 782 }
798 783
799quit: 784quit:
800 LOCK (wrklock); 785 X_LOCK (wrklock);
801 worker_free (self); 786 worker_free (self);
802 UNLOCK (wrklock); 787 X_UNLOCK (wrklock);
803 788
804 return 0; 789 return 0;
805} 790}
806 791
807/*****************************************************************************/ 792/*****************************************************************************/
808 793
809static void atfork_prepare (void) 794static void atfork_prepare (void)
810{ 795{
811 LOCK (wrklock); 796 X_LOCK (wrklock);
812 LOCK (reqlock); 797 X_LOCK (reqlock);
813 LOCK (reslock); 798 X_LOCK (reslock);
814} 799}
815 800
816static void atfork_parent (void) 801static void atfork_parent (void)
817{ 802{
818 UNLOCK (reslock); 803 X_UNLOCK (reslock);
819 UNLOCK (reqlock); 804 X_UNLOCK (reqlock);
820 UNLOCK (wrklock); 805 X_UNLOCK (wrklock);
821} 806}
822 807
823static void atfork_child (void) 808static void atfork_child (void)
824{ 809{
825 aio_req prv; 810 aio_req prv;
845 idle = 0; 830 idle = 0;
846 nreqs = 0; 831 nreqs = 0;
847 nready = 0; 832 nready = 0;
848 npending = 0; 833 npending = 0;
849 834
850 close (respipe [0]); 835 respipe_close (respipe [0]);
851 close (respipe [1]); 836 respipe_close (respipe [1]);
837
852 create_pipe (); 838 create_pipe (respipe);
853 839
854 atfork_parent (); 840 atfork_parent ();
855} 841}
856 842
857#define dREQ(reqtype) \ 843#define dREQ(reqtype) \
936 const_iv (DSYNC_DB) 922 const_iv (DSYNC_DB)
937 const_iv (DSYNC_LOG) 923 const_iv (DSYNC_LOG)
938 const_iv (LOG_AUTOREMOVE) 924 const_iv (LOG_AUTOREMOVE)
939 const_iv (LOG_INMEMORY) 925 const_iv (LOG_INMEMORY)
940 const_iv (NOLOCKING) 926 const_iv (NOLOCKING)
941 const_iv (MULTIVERSION)
942 const_iv (NOMMAP) 927 const_iv (NOMMAP)
943 const_iv (NOPANIC) 928 const_iv (NOPANIC)
944 const_iv (OVERWRITE) 929 const_iv (OVERWRITE)
945 const_iv (PANIC_ENVIRONMENT) 930 const_iv (PANIC_ENVIRONMENT)
946 const_iv (REGION_INIT) 931 const_iv (REGION_INIT)
947 const_iv (TIME_NOTGRANTED) 932 const_iv (TIME_NOTGRANTED)
948 const_iv (TXN_NOSYNC) 933 const_iv (TXN_NOSYNC)
949 const_iv (TXN_SNAPSHOT)
950 const_iv (TXN_WRITE_NOSYNC) 934 const_iv (TXN_WRITE_NOSYNC)
951 const_iv (WRITECURSOR) 935 const_iv (WRITECURSOR)
952 const_iv (YIELDCPU) 936 const_iv (YIELDCPU)
953 const_iv (ENCRYPT_AES) 937 const_iv (ENCRYPT_AES)
954 const_iv (XA_CREATE) 938 const_iv (XA_CREATE)
997 const_iv (APPEND) 981 const_iv (APPEND)
998 const_iv (NODUPDATA) 982 const_iv (NODUPDATA)
999 const_iv (NOOVERWRITE) 983 const_iv (NOOVERWRITE)
1000 984
1001 const_iv (TXN_NOWAIT) 985 const_iv (TXN_NOWAIT)
1002 const_iv (TXN_SNAPSHOT)
1003 const_iv (TXN_SYNC) 986 const_iv (TXN_SYNC)
1004 987
1005 const_iv (SET_LOCK_TIMEOUT) 988 const_iv (SET_LOCK_TIMEOUT)
1006 const_iv (SET_TXN_TIMEOUT) 989 const_iv (SET_TXN_TIMEOUT)
1007 990
1035 const_iv (LOCK_YOUNGEST) 1018 const_iv (LOCK_YOUNGEST)
1036 1019
1037 const_iv (SEQ_DEC) 1020 const_iv (SEQ_DEC)
1038 const_iv (SEQ_INC) 1021 const_iv (SEQ_INC)
1039 const_iv (SEQ_WRAP) 1022 const_iv (SEQ_WRAP)
1023#if DB_VERSION_MINOR >= 5
1024 const_iv (MULTIVERSION)
1025 const_iv (TXN_SNAPSHOT)
1026#endif
1040 }; 1027 };
1041 1028
1042 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1029 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1043 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1030 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
1044 1031
1045 create_pipe (); 1032 create_pipe (respipe);
1033
1046 pthread_atfork (atfork_prepare, atfork_parent, atfork_child); 1034 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child);
1035#ifdef _WIN32
1036 X_MUTEX_CHECK (wrklock);
1037 X_MUTEX_CHECK (reslock);
1038 X_MUTEX_CHECK (reqlock);
1039
1040 X_COND_CHECK (reqwait);
1041#endif
1047} 1042}
1048 1043
1049void 1044void
1050max_poll_reqs (int nreqs) 1045max_poll_reqs (int nreqs)
1051 PROTOTYPE: $ 1046 PROTOTYPE: $
1170 1165
1171int 1166int
1172nthreads () 1167nthreads ()
1173 PROTOTYPE: 1168 PROTOTYPE:
1174 CODE: 1169 CODE:
1175 if (WORDACCESS_UNSAFE) LOCK (wrklock); 1170 if (WORDACCESS_UNSAFE) X_LOCK (wrklock);
1176 RETVAL = started; 1171 RETVAL = started;
1177 if (WORDACCESS_UNSAFE) UNLOCK (wrklock); 1172 if (WORDACCESS_UNSAFE) X_UNLOCK (wrklock);
1178 OUTPUT: 1173 OUTPUT:
1179 RETVAL 1174 RETVAL
1180 1175
1181void 1176void
1182set_sync_prepare (SV *cb) 1177set_sync_prepare (SV *cb)
1199 1194
1200void 1195void
1201db_env_open (DB_ENV *env, octetstring db_home, U32 open_flags, int mode, SV *callback = &PL_sv_undef) 1196db_env_open (DB_ENV *env, octetstring db_home, U32 open_flags, int mode, SV *callback = &PL_sv_undef)
1202 CODE: 1197 CODE:
1203{ 1198{
1199 dREQ (REQ_ENV_OPEN);
1200
1204 env->set_thread_count (env, get_nthreads ()); 1201 env->set_thread_count (env, get_nthreads ());
1205 1202
1206 dREQ (REQ_ENV_OPEN);
1207 req->env = env; 1203 req->env = env;
1208 req->uint1 = open_flags | DB_THREAD; 1204 req->uint1 = open_flags | DB_THREAD;
1209 req->int1 = mode; 1205 req->int1 = mode;
1210 req->buf1 = strdup_ornull (db_home); 1206 req->buf1 = strdup_ornull (db_home);
1211 REQ_SEND; 1207 REQ_SEND;
1633 CODE: 1629 CODE:
1634 RETVAL = env->set_mp_mmapsize (env, ((size_t)mmapsize_mb) << 20); 1630 RETVAL = env->set_mp_mmapsize (env, ((size_t)mmapsize_mb) << 20);
1635 OUTPUT: 1631 OUTPUT:
1636 RETVAL 1632 RETVAL
1637 1633
1638int set_lk_detect (DB_ENV *env, U32 detect) 1634int set_lk_detect (DB_ENV *env, U32 detect = DB_LOCK_DEFAULT)
1639 CODE: 1635 CODE:
1640 RETVAL = env->set_lk_detect (env, detect); 1636 RETVAL = env->set_lk_detect (env, detect);
1641 OUTPUT: 1637 OUTPUT:
1642 RETVAL 1638 RETVAL
1643 1639

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines