summaryrefslogtreecommitdiffstats
path: root/src/wins.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/wins.c')
-rw-r--r--src/wins.c66
1 files changed, 58 insertions, 8 deletions
diff --git a/src/wins.c b/src/wins.c
index 85666df..65b2d96 100644
--- a/src/wins.c
+++ b/src/wins.c
@@ -40,6 +40,14 @@
#include "calcurse.h"
+#define SCREEN_ACQUIRE \
+ pthread_cleanup_push(screen_cleanup, (void *)NULL); \
+ screen_acquire();
+
+#define SCREEN_RELEASE \
+ screen_release(); \
+ pthread_cleanup_pop(0);
+
/* Variables to handle calcurse windows. */
struct window win[NBWINS];
@@ -76,14 +84,54 @@ static void screen_release(void)
pthread_mutex_unlock(&screen_mutex);
}
+static void screen_cleanup(void *arg)
+{
+ screen_release();
+}
+
+/*
+ * FIXME: The following functions currently lock the whole screen. Use both
+ * window-level and screen-level mutexes (or use use_screen() and use_window(),
+ * see curs_threads(3)) to avoid locking too much.
+ */
+
+unsigned wins_nbar_lock(void)
+{
+ return screen_acquire();
+}
+
+void wins_nbar_unlock(void)
+{
+ screen_release();
+}
+
+void wins_nbar_cleanup(void *arg)
+{
+ wins_nbar_unlock();
+}
+
+unsigned wins_calendar_lock(void)
+{
+ return screen_acquire();
+}
+
+void wins_calendar_unlock(void)
+{
+ screen_release();
+}
+
+void wins_calendar_cleanup(void *arg)
+{
+ wins_calendar_unlock();
+}
+
int wins_refresh(void)
{
int rc;
- if (!screen_acquire())
- return ERR;
+ SCREEN_ACQUIRE;
rc = refresh();
- screen_release();
+ SCREEN_RELEASE;
return rc;
}
@@ -92,10 +140,11 @@ int wins_wrefresh(WINDOW * win)
{
int rc;
- if (!win || !screen_acquire())
+ if (!win)
return ERR;
+ SCREEN_ACQUIRE;
rc = wrefresh(win);
- screen_release();
+ SCREEN_RELEASE;
return rc;
}
@@ -104,10 +153,9 @@ int wins_doupdate(void)
{
int rc;
- if (!screen_acquire())
- return ERR;
+ SCREEN_ACQUIRE;
rc = doupdate();
- screen_release();
+ SCREEN_RELEASE;
return rc;
}
@@ -475,10 +523,12 @@ static void border_nocolor(WINDOW * window)
void wins_update_border(int flags)
{
if (flags & FLAG_CAL) {
+ WINS_CALENDAR_LOCK;
if (slctd_win == CAL)
border_color(win[CAL].p);
else
border_nocolor(win[CAL].p);
+ WINS_CALENDAR_UNLOCK;
}
if (flags & FLAG_APP) {
if (slctd_win == APP)