Commits

Tim van der Molen committed 04230c5

Prevent a potential mutex deadlock.

The deadlock occurs when screen_prompt_end() locks screen_curses_mtx and then
attempts to lock option_tree_mtx while at the same time player_print_status()
or player_print_track() attempts to lock them in reverse order.

The deadlock is reproducible by repeatedly opening and closing a prompt while
playing back a track until the timing is right. The best chance of success is
with Linux and the libao null driver.

It seems the best solution is to ensure the screen.c functions do not attempt
to hold these mutexes simultaneously.

Comments (0)

Files changed (1)

 	int	 attr;
 	chtype	 cattr;
 
-	XPTHREAD_MUTEX_LOCK(&screen_curses_mtx);
 	for (i = 0; i < NELEMENTS(screen_objects); i++) {
 		attr = option_get_attrib(screen_objects[i].option_attr);
 		cattr = A_NORMAL;
 			if (attr & screen_attribs[j].attrib)
 				cattr |= screen_attribs[j].curses_attrib;
 
+		XPTHREAD_MUTEX_LOCK(&screen_curses_mtx);
 		screen_objects[i].attr = cattr;
+		XPTHREAD_MUTEX_UNLOCK(&screen_curses_mtx);
 	}
-	XPTHREAD_MUTEX_UNLOCK(&screen_curses_mtx);
 }
 
 static void
 	if (!screen_have_colours)
 		return;
 
-	XPTHREAD_MUTEX_LOCK(&screen_curses_mtx);
 	for (i = 0; i < NELEMENTS(screen_objects); i++) {
 		bg = screen_get_colour(screen_objects[i].option_bg,
 		    COLOUR_BLACK);
 		fg = screen_get_colour(screen_objects[i].option_fg,
 		    COLOUR_WHITE);
 
+		XPTHREAD_MUTEX_LOCK(&screen_curses_mtx);
 		if (init_pair(screen_objects[i].colour_pair, fg, bg) == OK)
 			screen_objects[i].attr |=
 			    (chtype)COLOR_PAIR(screen_objects[i].colour_pair);
+		XPTHREAD_MUTEX_UNLOCK(&screen_curses_mtx);
 	}
-	XPTHREAD_MUTEX_UNLOCK(&screen_curses_mtx);
 }
 
 void
 screen_configure_cursor(void)
 {
+	int show;
+
+	show = option_get_boolean("show-cursor");
 	XPTHREAD_MUTEX_LOCK(&screen_curses_mtx);
-	if (option_get_boolean("show-cursor"))
-		(void)curs_set(1);
-	else
-		(void)curs_set(0);
-
+	(void)curs_set(show);
 #ifdef SCREEN_HAVE_NETBSD_CURSES_BUGS
 	/*
 	 * NetBSD's curs_set() does not let the cursor-visibility change take
 void
 screen_prompt_end(void)
 {
+	int show;
+
+	show = option_get_boolean("show-cursor");
 	screen_status_clear();
 	XPTHREAD_MUTEX_LOCK(&screen_curses_mtx);
-	if (!option_get_boolean("show-cursor"))
+	if (!show)
 		(void)curs_set(0);
 	(void)move(screen_view_selected_row, 0);
 	(void)refresh();
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.