mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
fix refcount implementation i2c block
This commit is contained in:
parent
8dd991b534
commit
0bd8a97f63
1 changed files with 3 additions and 4 deletions
|
|
@ -4,7 +4,7 @@ use num_traits::{ToPrimitive, FromPrimitive};
|
|||
use core::sync::atomic::{AtomicBool, AtomicU32, Ordering};
|
||||
use crate::api::*;
|
||||
|
||||
static I2C_REFCOUNT: AtomicU32 = AtomicU32::new(0);
|
||||
static REFCOUNT: AtomicU32 = AtomicU32::new(0);
|
||||
|
||||
// this hooks the response of the I2C bus
|
||||
static mut I2C_CB: Option<fn(I2cTransaction)> = None;
|
||||
|
|
@ -32,7 +32,7 @@ pub struct I2c {
|
|||
}
|
||||
impl I2c {
|
||||
pub fn new(xns: &xous_names::XousNames) -> Self {
|
||||
I2C_REFCOUNT.store(I2C_REFCOUNT.load(Ordering::Relaxed) + 1, Ordering::Relaxed);
|
||||
REFCOUNT.fetch_add(1, Ordering::Relaxed);
|
||||
let i2c_conn = xns.request_connection_blocking(SERVER_NAME_I2C).expect("Can't connect to I2C");
|
||||
I2c {
|
||||
i2c_sid: None,
|
||||
|
|
@ -202,8 +202,7 @@ impl Drop for I2c {
|
|||
if let Some(sid) = self.i2c_sid.take() {
|
||||
drop_conn(sid);
|
||||
}
|
||||
I2C_REFCOUNT.store(I2C_REFCOUNT.load(Ordering::Relaxed) - 1, Ordering::Relaxed);
|
||||
if I2C_REFCOUNT.load(Ordering::Relaxed) == 0 {
|
||||
if REFCOUNT.fetch_sub(1, Ordering::Relaxed) == 1 {
|
||||
unsafe{xous::disconnect(self.i2c_conn).unwrap();}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue