WIP: Unlock Notification

To do: unlock_notify_cb
This commit is contained in:
gwenn
2017-09-21 19:27:07 +02:00
parent 5d91fb088f
commit 455e7d4060
4 changed files with 104 additions and 52 deletions

View File

@@ -125,8 +125,7 @@ pub mod limits;
mod hooks;
#[cfg(feature = "hooks")]
pub use hooks::*;
#[cfg(feature = "unlock_notify")]
pub mod unlock_notify;
mod unlock_notify;
// Number of cached prepared statements we'll hold on to.
const STATEMENT_CACHE_DEFAULT_CAPACITY: usize = 16;
@@ -864,16 +863,40 @@ impl InnerConnection {
}
let mut c_stmt: *mut ffi::sqlite3_stmt = unsafe { mem::uninitialized() };
let c_sql = try!(str_to_cstring(sql));
let len_with_nul = (sql.len() + 1) as c_int;
let r = unsafe {
let len_with_nul = (sql.len() + 1) as c_int;
ffi::sqlite3_prepare_v2(self.db(),
c_sql.as_ptr(),
len_with_nul,
&mut c_stmt,
ptr::null_mut())
if cfg!(feature = "unlock_notify") {
let mut rc;
loop {
rc = ffi::sqlite3_prepare_v2(
self.db(),
c_sql.as_ptr(),
len_with_nul,
&mut c_stmt,
ptr::null_mut(),
);
if rc != ffi::SQLITE_LOCKED {
break;
}
rc = unlock_notify::wait_for_unlock_notify(self.db);
if rc != ffi::SQLITE_OK {
break;
}
}
rc
} else {
ffi::sqlite3_prepare_v2(
self.db(),
c_sql.as_ptr(),
len_with_nul,
&mut c_stmt,
ptr::null_mut(),
)
}
};
self.decode_result(r)
.map(|_| Statement::new(conn, RawStatement::new(c_stmt)))
self.decode_result(r).map(|_| {
Statement::new(conn, RawStatement::new(c_stmt, self.db()))
})
}
fn changes(&mut self) -> c_int {