Use threads RLock to avoid crash on simultaneous refresh and resize.
fixes #2180
This commit is contained in:
parent
b9c6f08a79
commit
200019574d
2 changed files with 20 additions and 16 deletions
13
src/core.py
13
src/core.py
|
@ -45,6 +45,7 @@ from contact import Contact, Resource
|
||||||
from text_buffer import TextBuffer
|
from text_buffer import TextBuffer
|
||||||
from keyboard import read_char
|
from keyboard import read_char
|
||||||
from theming import get_theme
|
from theming import get_theme
|
||||||
|
from windows import g_lock
|
||||||
|
|
||||||
# http://xmpp.org/extensions/xep-0045.html#errorstatus
|
# http://xmpp.org/extensions/xep-0045.html#errorstatus
|
||||||
ERROR_AND_STATUS_CODES = {
|
ERROR_AND_STATUS_CODES = {
|
||||||
|
@ -67,8 +68,6 @@ possible_show = {'available':None,
|
||||||
'xa':'xa'
|
'xa':'xa'
|
||||||
}
|
}
|
||||||
|
|
||||||
resize_lock = threading.Lock()
|
|
||||||
|
|
||||||
Status = collections.namedtuple('Status', 'show message')
|
Status = collections.namedtuple('Status', 'show message')
|
||||||
|
|
||||||
class Core(object):
|
class Core(object):
|
||||||
|
@ -198,14 +197,16 @@ class Core(object):
|
||||||
"""
|
"""
|
||||||
Resize the global_information_win only once at each resize.
|
Resize the global_information_win only once at each resize.
|
||||||
"""
|
"""
|
||||||
self.information_win.resize(self.information_win_size, tabs.Tab.width,
|
with g_lock:
|
||||||
tabs.Tab.height - 2 - self.information_win_size, 0)
|
self.information_win.resize(self.information_win_size, tabs.Tab.width,
|
||||||
|
tabs.Tab.height - 2 - self.information_win_size, 0)
|
||||||
|
|
||||||
def resize_global_info_bar(self):
|
def resize_global_info_bar(self):
|
||||||
"""
|
"""
|
||||||
Resize the GlobalInfoBar only once at each resize
|
Resize the GlobalInfoBar only once at each resize
|
||||||
"""
|
"""
|
||||||
self.tab_win.resize(1, tabs.Tab.width, tabs.Tab.height - 2, 0)
|
with g_lock:
|
||||||
|
self.tab_win.resize(1, tabs.Tab.width, tabs.Tab.height - 2, 0)
|
||||||
|
|
||||||
def on_exception(self, typ, value, trace):
|
def on_exception(self, typ, value, trace):
|
||||||
"""
|
"""
|
||||||
|
@ -692,7 +693,7 @@ class Core(object):
|
||||||
tabs.Tab.resize(self.stdscr)
|
tabs.Tab.resize(self.stdscr)
|
||||||
self.resize_global_information_win()
|
self.resize_global_information_win()
|
||||||
self.resize_global_info_bar()
|
self.resize_global_info_bar()
|
||||||
with resize_lock:
|
with g_lock:
|
||||||
for tab in self.tabs:
|
for tab in self.tabs:
|
||||||
if config.get('lazy_resize', 'true') == 'true':
|
if config.get('lazy_resize', 'true') == 'true':
|
||||||
tab.need_resize = True
|
tab.need_resize = True
|
||||||
|
|
|
@ -24,7 +24,7 @@ import curses
|
||||||
import string
|
import string
|
||||||
from config import config
|
from config import config
|
||||||
|
|
||||||
from threading import Lock
|
from threading import RLock
|
||||||
|
|
||||||
from contact import Contact, Resource
|
from contact import Contact, Resource
|
||||||
from roster import RosterGroup, roster
|
from roster import RosterGroup, roster
|
||||||
|
@ -46,7 +46,7 @@ allowed_color_digits = ('0', '1', '2', '3', '4', '5', '6', '7')
|
||||||
# first is a bool telling if this is the first line of the message.
|
# first is a bool telling if this is the first line of the message.
|
||||||
Line = collections.namedtuple('Line', 'msg start_pos end_pos')
|
Line = collections.namedtuple('Line', 'msg start_pos end_pos')
|
||||||
|
|
||||||
g_lock = Lock()
|
g_lock = RLock()
|
||||||
|
|
||||||
LINES_NB_LIMIT = 4096
|
LINES_NB_LIMIT = 4096
|
||||||
|
|
||||||
|
@ -79,7 +79,8 @@ class Win(object):
|
||||||
"""
|
"""
|
||||||
Override if something has to be done on resize
|
Override if something has to be done on resize
|
||||||
"""
|
"""
|
||||||
self._resize(height, width, y, x)
|
with g_lock:
|
||||||
|
self._resize(height, width, y, x)
|
||||||
|
|
||||||
def _refresh(self):
|
def _refresh(self):
|
||||||
self._win.noutrefresh()
|
self._win.noutrefresh()
|
||||||
|
@ -255,10 +256,11 @@ class UserList(Win):
|
||||||
self._refresh()
|
self._refresh()
|
||||||
|
|
||||||
def resize(self, height, width, y, x):
|
def resize(self, height, width, y, x):
|
||||||
self._resize(height, width, y, x)
|
with g_lock:
|
||||||
self._win.attron(to_curses_attr(get_theme().COLOR_VERTICAL_SEPARATOR))
|
self._resize(height, width, y, x)
|
||||||
self._win.vline(0, 0, curses.ACS_VLINE, self.height)
|
self._win.attron(to_curses_attr(get_theme().COLOR_VERTICAL_SEPARATOR))
|
||||||
self._win.attroff(to_curses_attr(get_theme().COLOR_VERTICAL_SEPARATOR))
|
self._win.vline(0, 0, curses.ACS_VLINE, self.height)
|
||||||
|
self._win.attroff(to_curses_attr(get_theme().COLOR_VERTICAL_SEPARATOR))
|
||||||
|
|
||||||
class Topic(Win):
|
class Topic(Win):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -674,9 +676,10 @@ class TextWin(Win):
|
||||||
self.addstr(' ')
|
self.addstr(' ')
|
||||||
|
|
||||||
def resize(self, height, width, y, x, room=None):
|
def resize(self, height, width, y, x, room=None):
|
||||||
self._resize(height, width, y, x)
|
with g_lock:
|
||||||
if room:
|
self._resize(height, width, y, x)
|
||||||
self.rebuild_everything(room)
|
if room:
|
||||||
|
self.rebuild_everything(room)
|
||||||
|
|
||||||
def rebuild_everything(self, room):
|
def rebuild_everything(self, room):
|
||||||
self.built_lines = []
|
self.built_lines = []
|
||||||
|
|
Loading…
Reference in a new issue