(declare (block) (standard-bindings) (extended-bindings))
(begin
  (define std/db/conpool#conpool::t
    (make-struct-type
     'std/db/conpool#conpool::t
     '#f
     '6
     'conpool
     '((final: . #t))
     ':init!
     '(e mx cv conns out max)))
  (define std/db/conpool#conpool?
    (make-struct-predicate std/db/conpool#conpool::t))
  (define std/db/conpool#make-conpool
    (lambda _$args820_
      (apply make-struct-instance std/db/conpool#conpool::t _$args820_)))
  (define std/db/conpool#conpool-e
    (make-struct-field-accessor std/db/conpool#conpool::t '0))
  (define std/db/conpool#conpool-mx
    (make-struct-field-accessor std/db/conpool#conpool::t '1))
  (define std/db/conpool#conpool-cv
    (make-struct-field-accessor std/db/conpool#conpool::t '2))
  (define std/db/conpool#conpool-conns
    (make-struct-field-accessor std/db/conpool#conpool::t '3))
  (define std/db/conpool#conpool-out
    (make-struct-field-accessor std/db/conpool#conpool::t '4))
  (define std/db/conpool#conpool-max
    (make-struct-field-accessor std/db/conpool#conpool::t '5))
  (define std/db/conpool#conpool-e-set!
    (make-struct-field-mutator std/db/conpool#conpool::t '0))
  (define std/db/conpool#conpool-mx-set!
    (make-struct-field-mutator std/db/conpool#conpool::t '1))
  (define std/db/conpool#conpool-cv-set!
    (make-struct-field-mutator std/db/conpool#conpool::t '2))
  (define std/db/conpool#conpool-conns-set!
    (make-struct-field-mutator std/db/conpool#conpool::t '3))
  (define std/db/conpool#conpool-out-set!
    (make-struct-field-mutator std/db/conpool#conpool::t '4))
  (define std/db/conpool#conpool-max-set!
    (make-struct-field-mutator std/db/conpool#conpool::t '5))
  (define std/db/conpool#conpool:::init!__%
    (lambda (_self804_ _connect805_ _max806_)
      (if (let ((__tmp4460
                 (let () (declare (not safe)) (##vector-length _self804_))))
            (declare (not safe))
            (##fx< '6 __tmp4460))
          (begin
            (let ()
              (declare (not safe))
              (##vector-set! _self804_ '1 _connect805_))
            (let ((__tmp4461 (make-mutex)))
              (declare (not safe))
              (##vector-set! _self804_ '2 __tmp4461))
            (let ((__tmp4462 (make-condition-variable)))
              (declare (not safe))
              (##vector-set! _self804_ '3 __tmp4462))
            (let () (declare (not safe)) (##vector-set! _self804_ '4 '()))
            (let () (declare (not safe)) (##vector-set! _self804_ '5 '()))
            (let ()
              (declare (not safe))
              (##vector-set! _self804_ '6 _max806_)))
          (error '"struct-instance-init!: too many arguments for struct"
                 _self804_))))
  (define std/db/conpool#conpool:::init!__0
    (lambda (_self811_ _connect812_)
      (let ((_max814_ '#f))
        (std/db/conpool#conpool:::init!__% _self811_ _connect812_ _max814_))))
  (define std/db/conpool#conpool:::init!
    (lambda _g4464_
      (let ((_g4463_ (let () (declare (not safe)) (##length _g4464_))))
        (cond ((let () (declare (not safe)) (##fx= _g4463_ 2))
               (apply std/db/conpool#conpool:::init!__0 _g4464_))
              ((let () (declare (not safe)) (##fx= _g4463_ 3))
               (apply std/db/conpool#conpool:::init!__% _g4464_))
              (else
               (##raise-wrong-number-of-arguments-exception
                std/db/conpool#conpool:::init!
                _g4464_))))))
  (bind-method!
   std/db/conpool#conpool::t
   ':init!
   std/db/conpool#conpool:::init!
   '#f)
  (define std/db/conpool#conpool-get__%
    (lambda (_cp562_ _timeo563_)
      (let* ((_cp564575_ _cp562_)
             (_E566579_ (lambda () (error '"No clause matching" _cp564575_)))
             (_K567638_
              (lambda (_max582_ _out583_ _cv584_ _mx585_ _connect586_)
                (let _lp588_ ()
                  (mutex-lock! _mx585_)
                  (let* ((_g590598_
                          (##direct-structure-ref
                           _cp562_
                           '4
                           std/db/conpool#conpool::t
                           '#f))
                         (_else592620_
                          (lambda ()
                            (if (or (not _max582_)
                                    (fx< (length _out583_) _max582_))
                                (let ((_conn616_
                                       (with-exception-catcher
                                        (lambda (_g608610_)
                                          (if '#t
                                              (let ((_e613_ _g608610_))
                                                (mutex-unlock! _mx585_)
                                                (raise _e613_))
                                              (raise _g608610_)))
                                        (lambda () (_connect586_)))))
                                  (##direct-structure-set!
                                   _cp562_
                                   (cons _conn616_ _out583_)
                                   '5
                                   std/db/conpool#conpool::t
                                   '#f)
                                  (mutex-unlock! _mx585_)
                                  _conn616_)
                                (let ((_res618_
                                       (mutex-unlock!
                                        _mx585_
                                        _cv584_
                                        _timeo563_)))
                                  (if _res618_
                                      (_lp588_)
                                      (std/error#raise-timeout
                                       'conpool-get
                                       '"Error getting connection; timeout"))))))
                         (_K594626_
                          (lambda (_rest623_ _conn624_)
                            (##direct-structure-set!
                             _cp562_
                             _rest623_
                             '4
                             std/db/conpool#conpool::t
                             '#f)
                            (##direct-structure-set!
                             _cp562_
                             (cons _conn624_ _out583_)
                             '5
                             std/db/conpool#conpool::t
                             '#f)
                            (mutex-unlock! _mx585_)
                            _conn624_)))
                    (if (let () (declare (not safe)) (##pair? _g590598_))
                        (let ((_hd595629_
                               (let () (declare (not safe)) (##car _g590598_)))
                              (_tl596631_
                               (let ()
                                 (declare (not safe))
                                 (##cdr _g590598_))))
                          (let* ((_conn634_ _hd595629_) (_rest636_ _tl596631_))
                            (_K594626_ _rest636_ _conn634_)))
                        (_else592620_)))))))
        (if (let ()
              (declare (not safe))
              (##structure-direct-instance-of?
               _cp564575_
               'std/db/conpool#conpool::t))
            (let* ((_e568641_
                    (let () (declare (not safe)) (##vector-ref _cp564575_ '1)))
                   (_connect644_ _e568641_)
                   (_e569646_
                    (let () (declare (not safe)) (##vector-ref _cp564575_ '2)))
                   (_mx649_ _e569646_)
                   (_e570651_
                    (let () (declare (not safe)) (##vector-ref _cp564575_ '3)))
                   (_cv654_ _e570651_)
                   (_e571656_
                    (let () (declare (not safe)) (##vector-ref _cp564575_ '4)))
                   (_e572659_
                    (let () (declare (not safe)) (##vector-ref _cp564575_ '5)))
                   (_out662_ _e572659_)
                   (_e573664_
                    (let () (declare (not safe)) (##vector-ref _cp564575_ '6)))
                   (_max667_ _e573664_))
              (_K567638_ _max667_ _out662_ _cv654_ _mx649_ _connect644_))
            (_E566579_)))))
  (define std/db/conpool#conpool-get__0
    (lambda (_cp672_)
      (let ((_timeo674_ absent-obj))
        (std/db/conpool#conpool-get__% _cp672_ _timeo674_))))
  (define std/db/conpool#conpool-get
    (lambda _g4466_
      (let ((_g4465_ (let () (declare (not safe)) (##length _g4466_))))
        (cond ((let () (declare (not safe)) (##fx= _g4465_ 1))
               (apply std/db/conpool#conpool-get__0 _g4466_))
              ((let () (declare (not safe)) (##fx= _g4465_ 2))
               (apply std/db/conpool#conpool-get__% _g4466_))
              (else
               (##raise-wrong-number-of-arguments-exception
                std/db/conpool#conpool-get
                _g4466_))))))
  (define std/db/conpool#conpool-put
    (lambda (_cp511_ _conn512_)
      (let* ((_cp513523_ _cp511_)
             (_E515527_ (lambda () (error '"No clause matching" _cp513523_)))
             (_K516535_
              (lambda (_out530_ _conns531_ _cv532_ _mx533_)
                (mutex-lock! _mx533_)
                (##direct-structure-set!
                 _cp511_
                 (cons _conn512_ _conns531_)
                 '4
                 std/db/conpool#conpool::t
                 '#f)
                (##direct-structure-set!
                 _cp511_
                 (remq _conn512_ _out530_)
                 '5
                 std/db/conpool#conpool::t
                 '#f)
                (condition-variable-signal! _cv532_)
                (mutex-unlock! _mx533_))))
        (if (let ()
              (declare (not safe))
              (##structure-direct-instance-of?
               _cp513523_
               'std/db/conpool#conpool::t))
            (let* ((_e517538_
                    (let () (declare (not safe)) (##vector-ref _cp513523_ '1)))
                   (_e518541_
                    (let () (declare (not safe)) (##vector-ref _cp513523_ '2)))
                   (_mx544_ _e518541_)
                   (_e519546_
                    (let () (declare (not safe)) (##vector-ref _cp513523_ '3)))
                   (_cv549_ _e519546_)
                   (_e520551_
                    (let () (declare (not safe)) (##vector-ref _cp513523_ '4)))
                   (_conns554_ _e520551_)
                   (_e521556_
                    (let () (declare (not safe)) (##vector-ref _cp513523_ '5)))
                   (_out559_ _e521556_))
              (_K516535_ _out559_ _conns554_ _cv549_ _mx544_))
            (_E515527_)))))
  (define std/db/conpool#conpool-release
    (lambda (_cp461_ _conn462_)
      (let* ((_cp463473_ _cp461_)
             (_E465477_ (lambda () (error '"No clause matching" _cp463473_)))
             (_K466485_
              (lambda (_out480_ _conns481_ _cv482_ _mx483_)
                (mutex-lock! _mx483_)
                (##direct-structure-set!
                 _cp461_
                 (remq _conn462_ _out480_)
                 '5
                 std/db/conpool#conpool::t
                 '#f)
                (mutex-unlock! _mx483_)
                (let ((__method4458 (method-ref _conn462_ 'destroy)))
                  (if __method4458
                      (__method4458 _conn462_)
                      (error '"Missing method" _conn462_ 'destroy))))))
        (if (let ()
              (declare (not safe))
              (##structure-direct-instance-of?
               _cp463473_
               'std/db/conpool#conpool::t))
            (let* ((_e467488_
                    (let () (declare (not safe)) (##vector-ref _cp463473_ '1)))
                   (_e468491_
                    (let () (declare (not safe)) (##vector-ref _cp463473_ '2)))
                   (_mx494_ _e468491_)
                   (_e469496_
                    (let () (declare (not safe)) (##vector-ref _cp463473_ '3)))
                   (_cv499_ _e469496_)
                   (_e470501_
                    (let () (declare (not safe)) (##vector-ref _cp463473_ '4)))
                   (_conns504_ _e470501_)
                   (_e471506_
                    (let () (declare (not safe)) (##vector-ref _cp463473_ '5)))
                   (_out509_ _e471506_))
              (_K466485_ _out509_ _conns504_ _cv499_ _mx494_))
            (_E465477_)))))
  (define std/db/conpool#conpool-close
    (lambda (_cp400_)
      (letrec ((_close402_
                (lambda (_conn452_)
                  (with-exception-catcher
                   (lambda (_g453455_)
                     (if '#t
                         (let ((_e458_ _g453455_))
                           (std/logger#log-error
                            '"error closing connection"
                            _e458_))
                         (raise _g453455_)))
                   (lambda ()
                     (let ((__method4459 (method-ref _conn452_ 'destroy)))
                       (if __method4459
                           (__method4459 _conn452_)
                           (error '"Missing method" _conn452_ 'destroy))))))))
        (let* ((_cp403413_ _cp400_)
               (_E405417_ (lambda () (error '"No clause matching" _cp403413_)))
               (_K406426_
                (lambda (_out420_ _conns421_ _cv422_ _mx423_)
                  (mutex-lock! _mx423_)
                  (for-each _close402_ _conns421_)
                  (for-each _close402_ _out420_)
                  (##direct-structure-set!
                   _cp400_
                   (lambda () (error '"Connection pool is closed"))
                   '1
                   std/db/conpool#conpool::t
                   '#f)
                  (##direct-structure-set!
                   _cp400_
                   '()
                   '4
                   std/db/conpool#conpool::t
                   '#f)
                  (##direct-structure-set!
                   _cp400_
                   '()
                   '5
                   std/db/conpool#conpool::t
                   '#f)
                  (mutex-unlock! _mx423_))))
          (if (let ()
                (declare (not safe))
                (##structure-direct-instance-of?
                 _cp403413_
                 'std/db/conpool#conpool::t))
              (let* ((_e407429_
                      (let ()
                        (declare (not safe))
                        (##vector-ref _cp403413_ '1)))
                     (_e408432_
                      (let ()
                        (declare (not safe))
                        (##vector-ref _cp403413_ '2)))
                     (_mx435_ _e408432_)
                     (_e409437_
                      (let ()
                        (declare (not safe))
                        (##vector-ref _cp403413_ '3)))
                     (_cv440_ _e409437_)
                     (_e410442_
                      (let ()
                        (declare (not safe))
                        (##vector-ref _cp403413_ '4)))
                     (_conns445_ _e410442_)
                     (_e411447_
                      (let ()
                        (declare (not safe))
                        (##vector-ref _cp403413_ '5)))
                     (_out450_ _e411447_))
                (_K406426_ _out450_ _conns445_ _cv440_ _mx435_))
              (_E405417_)))))))
