From c55eac5217d2d60b056b24e52174c95df53bf2f3 Mon Sep 17 00:00:00 2001 From: Harald Judt Date: Thu, 20 Dec 2018 10:39:18 +0100 Subject: [PATCH 1/2] Make dbd-oracle threadsafe (at least in sbcl) Initialize OCIEnv in threadsafe mode and protect the *foreign-resource-hash* by declaring it as synchronized (this might only be possible in sbcl). --- src/dbd-oracle.lisp | 4 ++-- src/foreign-resources.lisp | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/dbd-oracle.lisp b/src/dbd-oracle.lisp index 6d87539..7ca455f 100644 --- a/src/dbd-oracle.lisp +++ b/src/dbd-oracle.lisp @@ -260,12 +260,12 @@ the length of that format.") (setf (deref-vp envhp) +null-void-pointer+) (progn - (oci-initialize +oci-object+ +null-void-pointer+ +null-void-pointer+ + (oci-initialize +oci-threaded+ +null-void-pointer+ +null-void-pointer+ +null-void-pointer+ +null-void-pointer-pointer+) (ignore-errors (oci-handle-alloc +null-void-pointer+ envhp +oci-htype-env+ 0 +null-void-pointer-pointer+)) ;no testing return - (oci-env-init envhp +oci-default+ 0 +null-void-pointer-pointer+)) + (oci-env-init envhp +oci-threaded+ 0 +null-void-pointer-pointer+)) (oci-handle-alloc (deref-vp envhp) errhp +oci-htype-error+ 0 +null-void-pointer-pointer+) diff --git a/src/foreign-resources.lisp b/src/foreign-resources.lisp index 2dc910f..0d0fcb7 100644 --- a/src/foreign-resources.lisp +++ b/src/foreign-resources.lisp @@ -11,7 +11,8 @@ (in-package #:dbd.oracle) -(defparameter *foreign-resource-hash* (make-hash-table :test #'equal)) +(defparameter *foreign-resource-hash* + (make-hash-table :test #'equal :synchronized t)) (defstruct (foreign-resource) (type (error "Missing TYPE.") From 464d6dd091200d6b6ce10fb8fa00af956a8dda24 Mon Sep 17 00:00:00 2001 From: Harald Judt Date: Fri, 28 Dec 2018 11:16:34 +0100 Subject: [PATCH 2/2] Load foreign library when loading the system Loading the foreign library in make-connection isn't thread-safe either and would need to be protected by a lock. As a work-around, load it when loading the system. dbd-oracle won't work anyway when it can't load the foreign library. --- src/dbd-oracle-dbi.lisp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/dbd-oracle-dbi.lisp b/src/dbd-oracle-dbi.lisp index c4d35ce..2739473 100644 --- a/src/dbd-oracle-dbi.lisp +++ b/src/dbd-oracle-dbi.lisp @@ -6,6 +6,9 @@ (cl-syntax:use-syntax :annot) +(unless *oracle-library-loaded* + (oracle-load-foreign)) + @export (defclass () ()) @@ -85,8 +88,6 @@ string conversion functions. Example of DATABASE-NAME: 127.0.0.1:1521/orcl " - (unless *oracle-library-loaded* - (oracle-load-foreign)) (make-instance ' :database-name database-name :auto-commit nil