Use a better timeout value for the notification mem lock
This commit is contained in:
parent
052ddc718d
commit
f143a9aced
|
@ -65,7 +65,7 @@ NotifyWidget::NotifyWidget(int pos, const SnoreNotifier *parent) :
|
|||
m_mem.lock();
|
||||
SHARED_MEM_TYPE *data = (SHARED_MEM_TYPE *)m_mem.data();
|
||||
data->free = true;
|
||||
data->date = QTime::currentTime();
|
||||
data->date = QTime::currentTime().msecsSinceStartOfDay();
|
||||
m_mem.unlock();
|
||||
} else {
|
||||
if (!m_mem.attach()) {
|
||||
|
@ -73,8 +73,9 @@ NotifyWidget::NotifyWidget(int pos, const SnoreNotifier *parent) :
|
|||
} else {
|
||||
m_mem.lock();
|
||||
SHARED_MEM_TYPE *data = (SHARED_MEM_TYPE *)m_mem.data();
|
||||
m_mem.unlock();
|
||||
snoreDebug(SNORE_DEBUG) << "Status" << data->free << data->date.elapsed() / 1000;
|
||||
m_mem.unlock();
|
||||
int elapsed = (QTime::currentTime().msecsSinceStartOfDay() - data->date) / 1000;
|
||||
snoreDebug(SNORE_DEBUG) << m_id << "State:" << data->free << "Time:" << elapsed << "Timeout:" << data->timeout;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,7 +121,7 @@ void NotifyWidget::display(const Notification ¬ification)
|
|||
}
|
||||
}
|
||||
|
||||
bool NotifyWidget::acquire()
|
||||
bool NotifyWidget::acquire(int timeout)
|
||||
{
|
||||
if (!m_mem.isAttached()) {
|
||||
return true;
|
||||
|
@ -129,14 +130,16 @@ bool NotifyWidget::acquire()
|
|||
if (m_ready) {
|
||||
m_mem.lock();
|
||||
SHARED_MEM_TYPE *data = (SHARED_MEM_TYPE *)m_mem.data();
|
||||
snoreDebug(SNORE_DEBUG) << m_id << data->free << data->date.elapsed() / 1000;
|
||||
bool timedout = data->date.elapsed() / 1000 > 60;
|
||||
int elapsed = (QTime::currentTime().msecsSinceStartOfDay() - data->date) / 1000;
|
||||
snoreDebug(SNORE_DEBUG) << m_id << "State:" << data->free << "Time:" << elapsed << "Timeout:" << data->timeout;
|
||||
bool timedout = elapsed > data->timeout;
|
||||
if (data->free || timedout) {
|
||||
if (timedout) {
|
||||
snoreDebug(SNORE_DEBUG) << "Notification Lock timed out" << data->date.elapsed() / 1000;
|
||||
snoreDebug(SNORE_DEBUG) << "Notification Lock timed out" << elapsed;
|
||||
}
|
||||
data->free = false;
|
||||
data->date = QTime::currentTime();
|
||||
data->date = QTime::currentTime().msecsSinceStartOfDay();
|
||||
data->timeout = timedout;
|
||||
m_ready = false;
|
||||
out = true;
|
||||
}
|
||||
|
@ -154,7 +157,8 @@ bool NotifyWidget::release()
|
|||
if (!m_ready) {
|
||||
m_mem.lock();
|
||||
SHARED_MEM_TYPE *data = (SHARED_MEM_TYPE *)m_mem.data();
|
||||
snoreDebug(SNORE_DEBUG) << m_id << data->free << data->date.elapsed() / 1000 << m_notification.id();
|
||||
int elapsed = (QTime::currentTime().msecsSinceStartOfDay() - data->date) / 1000;
|
||||
snoreDebug(SNORE_DEBUG) << m_id << "State:" << data->free << "Time:" << elapsed << "Timeout:" << data->timeout;
|
||||
if (!data->free) {
|
||||
data->free = true;
|
||||
m_ready = true;
|
||||
|
|
|
@ -28,13 +28,14 @@ class SnoreNotifier;
|
|||
|
||||
typedef struct {
|
||||
bool free;
|
||||
QTime date;
|
||||
int date;
|
||||
int timeout;
|
||||
|
||||
} SHARED_MEM_TYPE;
|
||||
|
||||
inline int SHARED_MEM_TYPE_REV()
|
||||
{
|
||||
return 1;
|
||||
return 2;
|
||||
}
|
||||
|
||||
class NotifyWidget : public QQuickView
|
||||
|
@ -60,7 +61,7 @@ public:
|
|||
|
||||
void display(const Snore::Notification ¬ification);
|
||||
|
||||
bool acquire();
|
||||
bool acquire(int timeout);
|
||||
bool release();
|
||||
|
||||
Snore::Notification ¬ification();
|
||||
|
|
|
@ -54,7 +54,7 @@ SnoreNotifier::SnoreNotifier():
|
|||
m_timer->stop();
|
||||
} else {
|
||||
for (NotifyWidget *w : m_widgets) {
|
||||
if (w->acquire()) {
|
||||
if (w->acquire(m_queue.first().timeout())) {
|
||||
Notification notification = m_queue.takeFirst();
|
||||
w->display(notification);
|
||||
notification.hints().setPrivateValue(this, "id", w->id());
|
||||
|
@ -104,7 +104,7 @@ void SnoreNotifier::slotNotify(Snore::Notification notification)
|
|||
} else {
|
||||
if (m_queue.isEmpty()) {
|
||||
for (NotifyWidget *w : m_widgets) {
|
||||
if (w->acquire()) {
|
||||
if (w->acquire(notification.timeout())) {
|
||||
display(w, notification);
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue