mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-19 13:44:55 +01:00
Rename still_active to stale
This commit is contained in:
@@ -35,10 +35,13 @@ pub trait ResourceManager: Debug {
|
|||||||
/// The error the resource may return when creating a new instance
|
/// The error the resource may return when creating a new instance
|
||||||
type Error: Debug;
|
type Error: Debug;
|
||||||
|
|
||||||
/// Creates a new resource with a given config
|
/// Creates a new resource with a given config.
|
||||||
|
///
|
||||||
|
/// If `stale` is every set to TRUE it is assumed the resource is no longer valid and it will be
|
||||||
|
/// dropped.
|
||||||
fn new_resource(
|
fn new_resource(
|
||||||
config: &Self::Config,
|
config: &Self::Config,
|
||||||
still_valid: Arc<AtomicBool>,
|
stale: Arc<AtomicBool>,
|
||||||
timeout: Duration,
|
timeout: Duration,
|
||||||
) -> Result<Self::Resource, Error<Self::Error>>;
|
) -> Result<Self::Resource, Error<Self::Error>>;
|
||||||
|
|
||||||
@@ -139,13 +142,13 @@ where
|
|||||||
let mut resources = self.queue.lock().map_err(|_| Error::Poison)?;
|
let mut resources = self.queue.lock().map_err(|_| Error::Poison)?;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if let Some(resource) = resources.pop() {
|
if let Some((stale, resource)) = resources.pop() {
|
||||||
if resource.0.load(Ordering::SeqCst) {
|
if !stale.load(Ordering::SeqCst) {
|
||||||
drop(resources);
|
drop(resources);
|
||||||
self.in_use.fetch_add(1, Ordering::AcqRel);
|
self.in_use.fetch_add(1, Ordering::AcqRel);
|
||||||
|
|
||||||
return Ok(PooledResource {
|
return Ok(PooledResource {
|
||||||
resource: Some(resource),
|
resource: Some((stale, resource)),
|
||||||
pool: self.clone(),
|
pool: self.clone(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -154,12 +157,12 @@ where
|
|||||||
if self.in_use.load(Ordering::Relaxed) < self.max_size {
|
if self.in_use.load(Ordering::Relaxed) < self.max_size {
|
||||||
drop(resources);
|
drop(resources);
|
||||||
self.in_use.fetch_add(1, Ordering::AcqRel);
|
self.in_use.fetch_add(1, Ordering::AcqRel);
|
||||||
let still_valid: Arc<AtomicBool> = Arc::new(true.into());
|
let stale: Arc<AtomicBool> = Arc::new(false.into());
|
||||||
|
|
||||||
return Ok(PooledResource {
|
return Ok(PooledResource {
|
||||||
resource: Some((
|
resource: Some((
|
||||||
still_valid.clone(),
|
stale.clone(),
|
||||||
RM::new_resource(&self.config, still_valid, timeout)?,
|
RM::new_resource(&self.config, stale, timeout)?,
|
||||||
)),
|
)),
|
||||||
pool: self.clone(),
|
pool: self.clone(),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ impl ResourceManager for SqliteConnectionManager {
|
|||||||
|
|
||||||
fn new_resource(
|
fn new_resource(
|
||||||
config: &Self::Config,
|
config: &Self::Config,
|
||||||
_still_valid: Arc<AtomicBool>,
|
_stale: Arc<AtomicBool>,
|
||||||
_timeout: Duration,
|
_timeout: Duration,
|
||||||
) -> Result<Self::Resource, pool::Error<Self::Error>> {
|
) -> Result<Self::Resource, pool::Error<Self::Error>> {
|
||||||
let conn = if let Some(path) = config.path.as_ref() {
|
let conn = if let Some(path) = config.path.as_ref() {
|
||||||
|
|||||||
Reference in New Issue
Block a user