… | |
… | |
4 | |
4 | |
5 | #include "EXTERN.h" |
5 | #include "EXTERN.h" |
6 | #include "perl.h" |
6 | #include "perl.h" |
7 | #include "XSUB.h" |
7 | #include "XSUB.h" |
8 | |
8 | |
|
|
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 |
|
|
17 | |
9 | #include <stddef.h> |
18 | #include <stddef.h> |
10 | #include <stdlib.h> |
19 | #include <stdlib.h> |
11 | #include <errno.h> |
20 | #include <errno.h> |
12 | #include <sys/time.h> |
|
|
13 | #include <sys/types.h> |
21 | #include <sys/types.h> |
14 | #include <limits.h> |
22 | #include <limits.h> |
15 | #include <unistd.h> |
|
|
16 | #include <fcntl.h> |
23 | #include <fcntl.h> |
17 | |
24 | |
|
|
25 | #ifndef _WIN32 |
|
|
26 | # include <sys/time.h> |
|
|
27 | # include <unistd.h> |
|
|
28 | #endif |
|
|
29 | |
18 | #include <db.h> |
30 | #include <db.h> |
19 | |
31 | |
20 | #if DB_VERSION_MAJOR < 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 5) |
32 | #if DB_VERSION_MAJOR < 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 4) |
21 | # error you need Berkeley DB 4.5 or newer installed |
33 | # error you need Berkeley DB 4.4 or newer installed |
22 | #endif |
34 | #endif |
23 | |
35 | |
24 | /* number of seconds after which idle threads exit */ |
36 | /* number of seconds after which idle threads exit */ |
25 | #define IDLE_TIMEOUT 10 |
37 | #define IDLE_TIMEOUT 10 |
26 | |
38 | |
… | |
… | |
33 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
45 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
34 | typedef char *octetstring; |
46 | typedef char *octetstring; |
35 | |
47 | |
36 | static SV *prepare_cb; |
48 | static SV *prepare_cb; |
37 | |
49 | |
38 | static inline char * |
50 | static char * |
39 | strdup_ornull (const char *s) |
51 | strdup_ornull (const char *s) |
40 | { |
52 | { |
41 | return s ? strdup (s) : 0; |
53 | return s ? strdup (s) : 0; |
42 | } |
54 | } |
43 | |
55 | |
44 | static inline void |
56 | static void |
45 | sv_to_dbt (DBT *dbt, SV *sv) |
57 | sv_to_dbt (DBT *dbt, SV *sv) |
46 | { |
58 | { |
47 | STRLEN len; |
59 | STRLEN len; |
48 | char *data = SvPVbyte (sv, len); |
60 | char *data = SvPVbyte (sv, len); |
49 | |
61 | |
… | |
… | |
51 | memcpy (dbt->data, data, len); |
63 | memcpy (dbt->data, data, len); |
52 | dbt->size = len; |
64 | dbt->size = len; |
53 | dbt->flags = DB_DBT_REALLOC; |
65 | dbt->flags = DB_DBT_REALLOC; |
54 | } |
66 | } |
55 | |
67 | |
56 | static inline void |
68 | static void |
57 | dbt_to_sv (SV *sv, DBT *dbt) |
69 | dbt_to_sv (SV *sv, DBT *dbt) |
58 | { |
70 | { |
59 | if (sv) |
71 | if (sv) |
60 | { |
72 | { |
61 | SvREADONLY_off (sv); |
73 | SvREADONLY_off (sv); |
… | |
… | |
126 | static int next_pri = DEFAULT_PRI + PRI_BIAS; |
138 | static int next_pri = DEFAULT_PRI + PRI_BIAS; |
127 | |
139 | |
128 | static unsigned int started, idle, wanted; |
140 | static unsigned int started, idle, wanted; |
129 | |
141 | |
130 | /* worker threads management */ |
142 | /* worker threads management */ |
131 | static mutex_t wrklock = MUTEX_INIT; |
143 | static mutex_t wrklock = X_MUTEX_INIT; |
132 | |
144 | |
133 | typedef struct worker { |
145 | typedef struct worker { |
134 | /* locked by wrklock */ |
146 | /* locked by wrklock */ |
135 | struct worker *prev, *next; |
147 | struct worker *prev, *next; |
136 | |
148 | |
… | |
… | |
157 | } |
169 | } |
158 | |
170 | |
159 | static volatile unsigned int nreqs, nready, npending; |
171 | static volatile unsigned int nreqs, nready, npending; |
160 | static volatile unsigned int max_idle = 4; |
172 | static volatile unsigned int max_idle = 4; |
161 | static volatile unsigned int max_outstanding = 0xffffffff; |
173 | static volatile unsigned int max_outstanding = 0xffffffff; |
162 | static int respipe [2]; |
174 | static int respipe [2], respipe_osf [2]; |
163 | |
175 | |
164 | static mutex_t reslock = MUTEX_INIT; |
176 | static mutex_t reslock = X_MUTEX_INIT; |
165 | static mutex_t reqlock = MUTEX_INIT; |
177 | static mutex_t reqlock = X_MUTEX_INIT; |
166 | static cond_t reqwait = COND_INIT; |
178 | static cond_t reqwait = X_COND_INIT; |
167 | |
179 | |
168 | #if WORDACCESS_UNSAFE |
180 | #if WORDACCESS_UNSAFE |
169 | |
181 | |
170 | static unsigned int get_nready () |
182 | static unsigned int get_nready () |
171 | { |
183 | { |
172 | unsigned int retval; |
184 | unsigned int retval; |
173 | |
185 | |
174 | LOCK (reqlock); |
186 | X_LOCK (reqlock); |
175 | retval = nready; |
187 | retval = nready; |
176 | UNLOCK (reqlock); |
188 | X_UNLOCK (reqlock); |
177 | |
189 | |
178 | return retval; |
190 | return retval; |
179 | } |
191 | } |
180 | |
192 | |
181 | static unsigned int get_npending () |
193 | static unsigned int get_npending () |
182 | { |
194 | { |
183 | unsigned int retval; |
195 | unsigned int retval; |
184 | |
196 | |
185 | LOCK (reslock); |
197 | X_LOCK (reslock); |
186 | retval = npending; |
198 | retval = npending; |
187 | UNLOCK (reslock); |
199 | X_UNLOCK (reslock); |
188 | |
200 | |
189 | return retval; |
201 | return retval; |
190 | } |
202 | } |
191 | |
203 | |
192 | static unsigned int get_nthreads () |
204 | static unsigned int get_nthreads () |
193 | { |
205 | { |
194 | unsigned int retval; |
206 | unsigned int retval; |
195 | |
207 | |
196 | LOCK (wrklock); |
208 | X_LOCK (wrklock); |
197 | retval = started; |
209 | retval = started; |
198 | UNLOCK (wrklock); |
210 | X_UNLOCK (wrklock); |
199 | |
211 | |
200 | return retval; |
212 | return retval; |
201 | } |
213 | } |
202 | |
214 | |
203 | #else |
215 | #else |
… | |
… | |
338 | free (req->buf1); |
350 | free (req->buf1); |
339 | free (req->buf2); |
351 | free (req->buf2); |
340 | Safefree (req); |
352 | Safefree (req); |
341 | } |
353 | } |
342 | |
354 | |
343 | static 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 | |
|
|
361 | static void |
|
|
362 | create_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 | |
|
|
380 | X_THREAD_PROC (bdb_proc); |
344 | |
381 | |
345 | static void start_thread (void) |
382 | static void start_thread (void) |
346 | { |
383 | { |
347 | worker *wrk = calloc (1, sizeof (worker)); |
384 | worker *wrk = calloc (1, sizeof (worker)); |
348 | |
385 | |
349 | if (!wrk) |
386 | if (!wrk) |
350 | croak ("unable to allocate worker thread data"); |
387 | croak ("unable to allocate worker thread data"); |
351 | |
388 | |
352 | LOCK (wrklock); |
389 | X_LOCK (wrklock); |
353 | if (thread_create (&wrk->tid, aio_proc, (void *)wrk)) |
390 | if (thread_create (&wrk->tid, bdb_proc, (void *)wrk)) |
354 | { |
391 | { |
355 | wrk->prev = &wrk_first; |
392 | wrk->prev = &wrk_first; |
356 | wrk->next = wrk_first.next; |
393 | wrk->next = wrk_first.next; |
357 | wrk_first.next->prev = wrk; |
394 | wrk_first.next->prev = wrk; |
358 | wrk_first.next = wrk; |
395 | wrk_first.next = wrk; |
359 | ++started; |
396 | ++started; |
360 | } |
397 | } |
361 | else |
398 | else |
362 | free (wrk); |
399 | free (wrk); |
363 | |
400 | |
364 | UNLOCK (wrklock); |
401 | X_UNLOCK (wrklock); |
365 | } |
402 | } |
366 | |
403 | |
367 | static void maybe_start_thread () |
404 | static void maybe_start_thread () |
368 | { |
405 | { |
369 | if (get_nthreads () >= wanted) |
406 | if (get_nthreads () >= wanted) |
… | |
… | |
381 | SV *wait_callback = 0; |
418 | SV *wait_callback = 0; |
382 | |
419 | |
383 | // synthesize callback if none given |
420 | // synthesize callback if none given |
384 | if (!SvOK (req->callback)) |
421 | if (!SvOK (req->callback)) |
385 | { |
422 | { |
|
|
423 | int count; |
|
|
424 | |
386 | dSP; |
425 | dSP; |
387 | PUSHMARK (SP); |
426 | PUSHMARK (SP); |
388 | PUTBACK; |
427 | PUTBACK; |
389 | int count = call_sv (prepare_cb, G_ARRAY); |
428 | count = call_sv (prepare_cb, G_ARRAY); |
390 | SPAGAIN; |
429 | SPAGAIN; |
391 | |
430 | |
392 | if (count != 2) |
431 | if (count != 2) |
393 | croak ("prepare callback must return exactly two values\n"); |
432 | croak ("prepare callback must return exactly two values\n"); |
394 | |
433 | |
… | |
… | |
397 | req->callback = SvREFCNT_inc (POPs); |
436 | req->callback = SvREFCNT_inc (POPs); |
398 | } |
437 | } |
399 | |
438 | |
400 | ++nreqs; |
439 | ++nreqs; |
401 | |
440 | |
402 | LOCK (reqlock); |
441 | X_LOCK (reqlock); |
403 | ++nready; |
442 | ++nready; |
404 | reqq_push (&req_queue, req); |
443 | reqq_push (&req_queue, req); |
405 | COND_SIGNAL (reqwait); |
444 | X_COND_SIGNAL (reqwait); |
406 | UNLOCK (reqlock); |
445 | X_UNLOCK (reqlock); |
407 | |
446 | |
408 | maybe_start_thread (); |
447 | maybe_start_thread (); |
409 | |
448 | |
410 | if (wait_callback) |
449 | if (wait_callback) |
411 | { |
450 | { |
… | |
… | |
424 | Newz (0, req, 1, aio_cb); |
463 | Newz (0, req, 1, aio_cb); |
425 | |
464 | |
426 | req->type = REQ_QUIT; |
465 | req->type = REQ_QUIT; |
427 | req->pri = PRI_MAX + PRI_BIAS; |
466 | req->pri = PRI_MAX + PRI_BIAS; |
428 | |
467 | |
429 | LOCK (reqlock); |
468 | X_LOCK (reqlock); |
430 | reqq_push (&req_queue, req); |
469 | reqq_push (&req_queue, req); |
431 | COND_SIGNAL (reqwait); |
470 | X_COND_SIGNAL (reqwait); |
432 | UNLOCK (reqlock); |
471 | X_UNLOCK (reqlock); |
433 | |
472 | |
434 | LOCK (wrklock); |
473 | X_LOCK (wrklock); |
435 | --started; |
474 | --started; |
436 | UNLOCK (wrklock); |
475 | X_UNLOCK (wrklock); |
437 | } |
476 | } |
438 | |
477 | |
439 | static void set_max_idle (int nthreads) |
478 | static void set_max_idle (int nthreads) |
440 | { |
479 | { |
441 | if (WORDACCESS_UNSAFE) LOCK (reqlock); |
480 | if (WORDACCESS_UNSAFE) X_LOCK (reqlock); |
442 | max_idle = nthreads <= 0 ? 1 : nthreads; |
481 | max_idle = nthreads <= 0 ? 1 : nthreads; |
443 | if (WORDACCESS_UNSAFE) UNLOCK (reqlock); |
482 | if (WORDACCESS_UNSAFE) X_UNLOCK (reqlock); |
444 | } |
483 | } |
445 | |
484 | |
446 | static void min_parallel (int nthreads) |
485 | static void min_parallel (int nthreads) |
447 | { |
486 | { |
448 | if (wanted < nthreads) |
487 | if (wanted < nthreads) |
… | |
… | |
463 | fd_set rfd; |
502 | fd_set rfd; |
464 | |
503 | |
465 | while (nreqs) |
504 | while (nreqs) |
466 | { |
505 | { |
467 | int size; |
506 | int size; |
468 | if (WORDACCESS_UNSAFE) LOCK (reslock); |
507 | if (WORDACCESS_UNSAFE) X_LOCK (reslock); |
469 | size = res_queue.size; |
508 | size = res_queue.size; |
470 | if (WORDACCESS_UNSAFE) UNLOCK (reslock); |
509 | if (WORDACCESS_UNSAFE) X_UNLOCK (reslock); |
471 | |
510 | |
472 | if (size) |
511 | if (size) |
473 | return; |
512 | return; |
474 | |
513 | |
475 | maybe_start_thread (); |
514 | maybe_start_thread (); |
476 | |
515 | |
477 | FD_ZERO(&rfd); |
516 | FD_ZERO (&rfd); |
478 | FD_SET(respipe [0], &rfd); |
517 | FD_SET (respipe [0], &rfd); |
479 | |
518 | |
480 | select (respipe [0] + 1, &rfd, 0, 0, 0); |
519 | PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); |
481 | } |
520 | } |
482 | } |
521 | } |
483 | |
522 | |
484 | static int poll_cb () |
523 | static int poll_cb () |
485 | { |
524 | { |
… | |
… | |
497 | { |
536 | { |
498 | for (;;) |
537 | for (;;) |
499 | { |
538 | { |
500 | maybe_start_thread (); |
539 | maybe_start_thread (); |
501 | |
540 | |
502 | LOCK (reslock); |
541 | X_LOCK (reslock); |
503 | req = reqq_shift (&res_queue); |
542 | req = reqq_shift (&res_queue); |
504 | |
543 | |
505 | if (req) |
544 | if (req) |
506 | { |
545 | { |
507 | --npending; |
546 | --npending; |
508 | |
547 | |
509 | if (!res_queue.size) |
548 | if (!res_queue.size) |
510 | { |
549 | { |
511 | /* read any signals sent by the worker threads */ |
550 | /* read any signals sent by the worker threads */ |
512 | char buf [4]; |
551 | char buf [4]; |
513 | while (read (respipe [0], buf, 4) == 4) |
552 | while (respipe_read (respipe [0], buf, 4) == 4) |
514 | ; |
553 | ; |
515 | } |
554 | } |
516 | } |
555 | } |
517 | |
556 | |
518 | UNLOCK (reslock); |
557 | X_UNLOCK (reslock); |
519 | |
558 | |
520 | if (!req) |
559 | if (!req) |
521 | break; |
560 | break; |
522 | |
561 | |
523 | --nreqs; |
562 | --nreqs; |
… | |
… | |
553 | } |
592 | } |
554 | |
593 | |
555 | return count; |
594 | return count; |
556 | } |
595 | } |
557 | |
596 | |
558 | static void create_pipe () |
|
|
559 | { |
|
|
560 | if (pipe (respipe)) |
|
|
561 | croak ("unable to initialize result pipe"); |
|
|
562 | |
|
|
563 | if (fcntl (respipe [0], F_SETFL, O_NONBLOCK)) |
|
|
564 | croak ("cannot set result pipe to nonblocking mode"); |
|
|
565 | |
|
|
566 | if (fcntl (respipe [1], F_SETFL, O_NONBLOCK)) |
|
|
567 | croak ("cannot set result pipe to nonblocking mode"); |
|
|
568 | } |
|
|
569 | |
|
|
570 | /*****************************************************************************/ |
597 | /*****************************************************************************/ |
571 | |
598 | |
572 | static void *aio_proc (void *thr_arg) |
599 | X_THREAD_PROC (bdb_proc) |
573 | { |
600 | { |
574 | aio_req req; |
601 | aio_req req; |
575 | struct timespec ts; |
602 | struct timespec ts; |
576 | worker *self = (worker *)thr_arg; |
603 | worker *self = (worker *)thr_arg; |
577 | |
604 | |
578 | /* try to distribute timeouts somewhat evenly */ |
605 | /* try to distribute timeouts somewhat evenly */ |
579 | ts.tv_nsec = (((unsigned long)self + (unsigned long)ts.tv_sec) & 1023UL) |
606 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
580 | * (1000000000UL / 1024UL); |
|
|
581 | |
607 | |
582 | for (;;) |
608 | for (;;) |
583 | { |
609 | { |
584 | ts.tv_sec = time (0) + IDLE_TIMEOUT; |
610 | ts.tv_sec = time (0) + IDLE_TIMEOUT; |
585 | |
611 | |
586 | LOCK (reqlock); |
612 | X_LOCK (reqlock); |
587 | |
613 | |
588 | for (;;) |
614 | for (;;) |
589 | { |
615 | { |
590 | self->req = req = reqq_shift (&req_queue); |
616 | self->req = req = reqq_shift (&req_queue); |
591 | |
617 | |
592 | if (req) |
618 | if (req) |
593 | break; |
619 | break; |
594 | |
620 | |
595 | ++idle; |
621 | ++idle; |
596 | |
622 | |
597 | if (COND_TIMEDWAIT (reqwait, reqlock, ts) |
623 | if (X_COND_TIMEDWAIT (reqwait, reqlock, ts) |
598 | == ETIMEDOUT) |
624 | == ETIMEDOUT) |
599 | { |
625 | { |
600 | if (idle > max_idle) |
626 | if (idle > max_idle) |
601 | { |
627 | { |
602 | --idle; |
628 | --idle; |
603 | UNLOCK (reqlock); |
629 | X_UNLOCK (reqlock); |
604 | LOCK (wrklock); |
630 | X_LOCK (wrklock); |
605 | --started; |
631 | --started; |
606 | UNLOCK (wrklock); |
632 | X_UNLOCK (wrklock); |
607 | goto quit; |
633 | goto quit; |
608 | } |
634 | } |
609 | |
635 | |
610 | /* we are allowed to idle, so do so without any timeout */ |
636 | /* we are allowed to idle, so do so without any timeout */ |
611 | COND_WAIT (reqwait, reqlock); |
637 | X_COND_WAIT (reqwait, reqlock); |
612 | ts.tv_sec = time (0) + IDLE_TIMEOUT; |
638 | ts.tv_sec = time (0) + IDLE_TIMEOUT; |
613 | } |
639 | } |
614 | |
640 | |
615 | --idle; |
641 | --idle; |
616 | } |
642 | } |
617 | |
643 | |
618 | --nready; |
644 | --nready; |
619 | |
645 | |
620 | UNLOCK (reqlock); |
646 | X_UNLOCK (reqlock); |
621 | |
647 | |
622 | switch (req->type) |
648 | switch (req->type) |
623 | { |
649 | { |
624 | case REQ_QUIT: |
650 | case REQ_QUIT: |
625 | goto quit; |
651 | goto quit; |
… | |
… | |
739 | default: |
765 | default: |
740 | req->result = ENOSYS; |
766 | req->result = ENOSYS; |
741 | break; |
767 | break; |
742 | } |
768 | } |
743 | |
769 | |
744 | LOCK (reslock); |
770 | X_LOCK (reslock); |
745 | |
771 | |
746 | ++npending; |
772 | ++npending; |
747 | |
773 | |
748 | if (!reqq_push (&res_queue, req)) |
774 | if (!reqq_push (&res_queue, req)) |
749 | /* write a dummy byte to the pipe so fh becomes ready */ |
775 | /* write a dummy byte to the pipe so fh becomes ready */ |
750 | write (respipe [1], &respipe, 1); |
776 | respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1); |
751 | |
777 | |
752 | self->req = 0; |
778 | self->req = 0; |
753 | worker_clear (self); |
779 | worker_clear (self); |
754 | |
780 | |
755 | UNLOCK (reslock); |
781 | X_UNLOCK (reslock); |
756 | } |
782 | } |
757 | |
783 | |
758 | quit: |
784 | quit: |
759 | LOCK (wrklock); |
785 | X_LOCK (wrklock); |
760 | worker_free (self); |
786 | worker_free (self); |
761 | UNLOCK (wrklock); |
787 | X_UNLOCK (wrklock); |
762 | |
788 | |
763 | return 0; |
789 | return 0; |
764 | } |
790 | } |
765 | |
791 | |
766 | /*****************************************************************************/ |
792 | /*****************************************************************************/ |
767 | |
793 | |
768 | static void atfork_prepare (void) |
794 | static void atfork_prepare (void) |
769 | { |
795 | { |
770 | LOCK (wrklock); |
796 | X_LOCK (wrklock); |
771 | LOCK (reqlock); |
797 | X_LOCK (reqlock); |
772 | LOCK (reslock); |
798 | X_LOCK (reslock); |
773 | } |
799 | } |
774 | |
800 | |
775 | static void atfork_parent (void) |
801 | static void atfork_parent (void) |
776 | { |
802 | { |
777 | UNLOCK (reslock); |
803 | X_UNLOCK (reslock); |
778 | UNLOCK (reqlock); |
804 | X_UNLOCK (reqlock); |
779 | UNLOCK (wrklock); |
805 | X_UNLOCK (wrklock); |
780 | } |
806 | } |
781 | |
807 | |
782 | static void atfork_child (void) |
808 | static void atfork_child (void) |
783 | { |
809 | { |
784 | aio_req prv; |
810 | aio_req prv; |
… | |
… | |
804 | idle = 0; |
830 | idle = 0; |
805 | nreqs = 0; |
831 | nreqs = 0; |
806 | nready = 0; |
832 | nready = 0; |
807 | npending = 0; |
833 | npending = 0; |
808 | |
834 | |
809 | close (respipe [0]); |
835 | respipe_close (respipe [0]); |
810 | close (respipe [1]); |
836 | respipe_close (respipe [1]); |
|
|
837 | |
811 | create_pipe (); |
838 | create_pipe (respipe); |
812 | |
839 | |
813 | atfork_parent (); |
840 | atfork_parent (); |
814 | } |
841 | } |
815 | |
842 | |
816 | #define dREQ(reqtype) \ |
843 | #define dREQ(reqtype) \ |
… | |
… | |
895 | const_iv (DSYNC_DB) |
922 | const_iv (DSYNC_DB) |
896 | const_iv (DSYNC_LOG) |
923 | const_iv (DSYNC_LOG) |
897 | const_iv (LOG_AUTOREMOVE) |
924 | const_iv (LOG_AUTOREMOVE) |
898 | const_iv (LOG_INMEMORY) |
925 | const_iv (LOG_INMEMORY) |
899 | const_iv (NOLOCKING) |
926 | const_iv (NOLOCKING) |
900 | const_iv (MULTIVERSION) |
|
|
901 | const_iv (NOMMAP) |
927 | const_iv (NOMMAP) |
902 | const_iv (NOPANIC) |
928 | const_iv (NOPANIC) |
903 | const_iv (OVERWRITE) |
929 | const_iv (OVERWRITE) |
904 | const_iv (PANIC_ENVIRONMENT) |
930 | const_iv (PANIC_ENVIRONMENT) |
905 | const_iv (REGION_INIT) |
931 | const_iv (REGION_INIT) |
906 | const_iv (TIME_NOTGRANTED) |
932 | const_iv (TIME_NOTGRANTED) |
907 | const_iv (TXN_NOSYNC) |
933 | const_iv (TXN_NOSYNC) |
908 | const_iv (TXN_SNAPSHOT) |
|
|
909 | const_iv (TXN_WRITE_NOSYNC) |
934 | const_iv (TXN_WRITE_NOSYNC) |
910 | const_iv (WRITECURSOR) |
935 | const_iv (WRITECURSOR) |
911 | const_iv (YIELDCPU) |
936 | const_iv (YIELDCPU) |
912 | const_iv (ENCRYPT_AES) |
937 | const_iv (ENCRYPT_AES) |
913 | const_iv (XA_CREATE) |
938 | const_iv (XA_CREATE) |
… | |
… | |
956 | const_iv (APPEND) |
981 | const_iv (APPEND) |
957 | const_iv (NODUPDATA) |
982 | const_iv (NODUPDATA) |
958 | const_iv (NOOVERWRITE) |
983 | const_iv (NOOVERWRITE) |
959 | |
984 | |
960 | const_iv (TXN_NOWAIT) |
985 | const_iv (TXN_NOWAIT) |
961 | const_iv (TXN_SNAPSHOT) |
|
|
962 | const_iv (TXN_SYNC) |
986 | const_iv (TXN_SYNC) |
963 | |
987 | |
964 | const_iv (SET_LOCK_TIMEOUT) |
988 | const_iv (SET_LOCK_TIMEOUT) |
965 | const_iv (SET_TXN_TIMEOUT) |
989 | const_iv (SET_TXN_TIMEOUT) |
966 | |
990 | |
… | |
… | |
994 | const_iv (LOCK_YOUNGEST) |
1018 | const_iv (LOCK_YOUNGEST) |
995 | |
1019 | |
996 | const_iv (SEQ_DEC) |
1020 | const_iv (SEQ_DEC) |
997 | const_iv (SEQ_INC) |
1021 | const_iv (SEQ_INC) |
998 | 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 |
999 | }; |
1027 | }; |
1000 | |
1028 | |
1001 | 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; ) |
1002 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1030 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1003 | |
1031 | |
1004 | create_pipe (); |
1032 | create_pipe (respipe); |
|
|
1033 | |
1005 | 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 |
1006 | } |
1042 | } |
1007 | |
1043 | |
1008 | void |
1044 | void |
1009 | max_poll_reqs (int nreqs) |
1045 | max_poll_reqs (int nreqs) |
1010 | PROTOTYPE: $ |
1046 | PROTOTYPE: $ |
… | |
… | |
1129 | |
1165 | |
1130 | int |
1166 | int |
1131 | nthreads () |
1167 | nthreads () |
1132 | PROTOTYPE: |
1168 | PROTOTYPE: |
1133 | CODE: |
1169 | CODE: |
1134 | if (WORDACCESS_UNSAFE) LOCK (wrklock); |
1170 | if (WORDACCESS_UNSAFE) X_LOCK (wrklock); |
1135 | RETVAL = started; |
1171 | RETVAL = started; |
1136 | if (WORDACCESS_UNSAFE) UNLOCK (wrklock); |
1172 | if (WORDACCESS_UNSAFE) X_UNLOCK (wrklock); |
1137 | OUTPUT: |
1173 | OUTPUT: |
1138 | RETVAL |
1174 | RETVAL |
1139 | |
1175 | |
1140 | void |
1176 | void |
1141 | set_sync_prepare (SV *cb) |
1177 | set_sync_prepare (SV *cb) |
… | |
… | |
1158 | |
1194 | |
1159 | void |
1195 | void |
1160 | db_env_open (DB_ENV *env, octetstring db_home, U32 open_flags, int mode, SV *callback = &PL_sv_undef) |
1196 | db_env_open (DB_ENV *env, octetstring db_home, U32 open_flags, int mode, SV *callback = &PL_sv_undef) |
1161 | CODE: |
1197 | CODE: |
1162 | { |
1198 | { |
|
|
1199 | dREQ (REQ_ENV_OPEN); |
|
|
1200 | |
1163 | env->set_thread_count (env, get_nthreads ()); |
1201 | env->set_thread_count (env, get_nthreads ()); |
1164 | |
1202 | |
1165 | dREQ (REQ_ENV_OPEN); |
|
|
1166 | req->env = env; |
1203 | req->env = env; |
1167 | req->uint1 = open_flags | DB_THREAD; |
1204 | req->uint1 = open_flags | DB_THREAD; |
1168 | req->int1 = mode; |
1205 | req->int1 = mode; |
1169 | req->buf1 = strdup_ornull (db_home); |
1206 | req->buf1 = strdup_ornull (db_home); |
1170 | REQ_SEND; |
1207 | REQ_SEND; |