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