Re: AOO plugin for PD on SGI Irix
Wolfgang Gaggl via Pd-list <[email protected]>
| Newsgroups | gmane.comp.multimedia.puredata.general |
|---|---|
| Message-ID | <[email protected]> |
I would not expect #3 to follow from #1. #1 just means I have to try a few times due to system architecture, but a scoped_shared_lock is still a reader lock. So they should work simultaneously, you should not have to wait for a scoped_shared_lock to release the lock before the shared_lock(try_to_lock) can obtain a reader lock as long as there is no writer requesting a lock at the same time.
Whether it's a bug or not, it does not behave as I would expect it here.
write_guard (always non-blocking):
std::atomic<uint32_t> update_gen_{0}; // seqlock generation: even=idle, odd=write in progress
struct update_write_guard {
std::atomic<uint32_t>& gen_;
explicit update_write_guard(std::atomic<uint32_t>& g) : gen_(g) {
g.fetch_add(1, std::memory_order_release);
}
~update_write_guard() {
gen_.fetch_add(1, std::memory_order_release);
}
update_write_guard(const update_write_guard&) = delete;
update_write_guard& operator=(const update_write_guard&) = delete;
};
Before every write lock call for update_mutex_:
update_write_guard uwg(update_gen_);
scoped_lock lock(update_mutex_); // writer lock!
Replace reader lock try_to_lock in process() of source.cpp with this:
auto gen_before = update_gen_.load(std::memory_order_acquire);
if (gen_before & 1) {
// a write is currently in progress
LOG_DEBUG("AooSource: process blocked by active writer");
add_xrun(nsamples);
return kAooErrorIdle;
}
// we are good to go now!
// do processing stuff here....
// done with processing stuff.
// Verify no write occurred while audio was being processed.
if (update_gen_.load(std::memory_order_acquire) != gen_before) {
LOG_DEBUG("AooSource: write detected during audio processing, xrun");
add_xrun(nsamples);
return kAooErrorIdle;
}
return kAooOk;
Similar in sink.cpp.
This assumes that typically there's generally low probability of writer lock activity going on during process() execution.
Works well so far (at least for PD objects).
---
[email protected] - the Pure Data mailinglist
https://lists.iem.at/hyperkitty/list/[email protected]/message/BQSSH5QXUGFTNDVRY6NB7PSICXMVZ7OH/
To unsubscribe send an email to [email protected] mailing list
UNSUBSCRIBE and account-management -> https://lists.iem.at/