Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove-commented code misc.rs #54

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 0 additions & 91 deletions src/interface/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,97 +313,6 @@ pub struct AdvisoryLock {
advisory_condvar: Condvar,
}

/*
* AdvisoryLock is used to implement advisory locking for files.
* Specifically, it is used by the flock syscall.
* If works as follows: The underying mutex has a guard value associated with it.
* A guard value of zero indicates that it is unlocked.
* In case an exclusive lock is held, the guard value is set to -1.
* In case a shared lock is held, the guard value is incremented by 1.
*/
// impl AdvisoryLock {
// pub fn new() -> Self {
// Self {
// advisory_lock: RustRfc::new(Mutex::new(0)),
// advisory_condvar: Condvar::new(),
// }
// }

// // lock_ex is used to acquire an exclusive lock
// // if the lock cannot be obtained, it waits
// pub fn lock_ex(&self) {
// let mut waitedguard = self.advisory_lock.lock();
// while *waitedguard != 0 {
// self.advisory_condvar.wait(&mut waitedguard);
// }
// *waitedguard = -1;
// }

// // lock_sh is used to acquire a shared lock
// // if the lock cannot be obtained, it waits
// pub fn lock_sh(&self) {
// let mut waitedguard = self.advisory_lock.lock();
// while *waitedguard < 0 {
// self.advisory_condvar.wait(&mut waitedguard);
// }
// *waitedguard += 1;
// }
// // try_lock_ex is used to try to acquire an exclusive lock
// // if the lock cannot be obtained, it returns false
// pub fn try_lock_ex(&self) -> bool {
// if let Some(mut guard) = self.advisory_lock.try_lock() {
// if *guard == 0 {
// *guard = -1;
// return true;
// }
// }
// false
// }
// // try_lock_sh is used to try to acquire a shared lock
// // if the lock cannot be obtained, it returns false
// pub fn try_lock_sh(&self) -> bool {
// if let Some(mut guard) = self.advisory_lock.try_lock() {
// if *guard >= 0 {
// *guard += 1;
// return true;
// }
// }
// false
// }

// /*
// * unlock is used to release a lock
// * If a shared lock was held(guard value > 0), it decrements the guard value by one
// * if no more shared locks are held (i.e. the guard value is now zero), then it notifies a waiting writer
// * If an exclusive lock was held, it sets the guard value to zero and notifies all waiting readers and writers
// */
// pub fn unlock(&self) -> bool {
// let mut guard = self.advisory_lock.lock();

// // check if a shared lock is held
// if *guard > 0 {
// // release one shared lock by decrementing the guard value
// *guard -= 1;

// // if no more shared locks are held, notify a waiting writer and return
// // only a writer could be waiting at this point
// if *guard == 0 {
// self.advisory_condvar.notify_one();
// }
// true
// } else if *guard == -1 {
// // check if an exclusive lock is held
// // release the exclusive lock by setting guard to 0
// *guard = 0;

// // notify any waiting reads or writers and return
// self.advisory_condvar.notify_all();
// true
// } else {
// false
// }
// }
// }

pub struct RawMutex {
inner: libc::pthread_mutex_t,
Expand Down
Loading