AmendHub

Download:

jcs

/

wallops

/

amendments

/

72

chatter: Sprinkle locking


jcs made amendment 72 about 1 month ago
--- chatter.c Sun Sep 8 21:51:58 2024 +++ chatter.c Mon Sep 9 16:18:36 2024 @@ -189,14 +189,18 @@ chatter_layout(struct chatter *chatter, bool init, Rec InsetRect(&inset_bounds, 3, 1); inset_bounds.right = win_bounds->right * 2; chatter->input_te = TENew(&inset_bounds, &bounds); + HLock(chatter->input_te); (*(chatter->input_te))->crOnly = -1; + HUnlock(chatter->input_te); TEAutoView(true, chatter->input_te); TEActivate(chatter->input_te); } else { + HLock(chatter->input_te); (*(chatter->input_te))->viewRect = bounds; InsetRect(&bounds, 3, 1); (*(chatter->input_te))->destRect = bounds; TECalText(chatter->input_te); + HUnlock(chatter->input_te); } if (init) { @@ -279,8 +283,10 @@ chatter_layout_tab(struct chatter *chatter, struct cha if (!tab->nick_list) panic("Can't create nick list"); LAddColumn(1, 0, tab->nick_list); + HLock(tab->nick_list); (*(tab->nick_list))->selFlags = lOnlyOne | lNoNilHilite; } else { + HLock(tab->nick_list); (*(tab->nick_list))->rView = bounds; LSize(bounds.right - bounds.left, bounds.bottom - bounds.top, tab->nick_list); @@ -299,6 +305,7 @@ chatter_layout_tab(struct chatter *chatter, struct cha tab->messages_scroller = NewControl(chatter->win, &bounds, "\p", true, 1, 1, 1, scrollBarProc, 0L); else { + HLock(tab->messages_scroller); MoveControl(tab->messages_scroller, bounds.left, bounds.top); SizeControl(tab->messages_scroller, bounds.right - bounds.left, bounds.bottom - bounds.top); @@ -319,10 +326,16 @@ chatter_layout_tab(struct chatter *chatter, struct cha chatter_autoscroll(chatter, tab->messages_te, tab->messages_scroller); } else { + HLock(tab->messages_te); (*(tab->messages_te))->viewRect = bounds; (*(tab->messages_te))->destRect = inset_bounds; TECalText(tab->messages_te); } + + HUnlock(tab->messages_te); + HUnlock(tab->messages_scroller); + if (tab->channel) + HUnlock(tab->nick_list); } void @@ -339,6 +352,8 @@ chatter_focus_tab(struct chatter *chatter, struct chat * Doing the HideControl takes out the top line of our tab bar, * so clip to just above it */ + HLock(chatter->current_tab->messages_scroller); + HLock(chatter->current_tab->nick_list); GetClip(clip = NewRgn()); r.left = 0; r.top = 0; @@ -349,6 +364,8 @@ chatter_focus_tab(struct chatter *chatter, struct chat else r.right = (*(chatter->current_tab->messages_scroller))->contrlRect.right; ClipRect(&r); + HUnlock(chatter->current_tab->nick_list); + HUnlock(chatter->current_tab->messages_scroller); EraseRect(&r); TEDeactivate(chatter->current_tab->messages_te); @@ -366,16 +383,24 @@ chatter_focus_tab(struct chatter *chatter, struct chat chatter->current_tab = tab; + HLock(tab->messages_te); EraseRect(&(*(tab->messages_te))->viewRect); TEActivate(tab->messages_te); TEUpdate(&(*(tab->messages_te))->viewRect, tab->messages_te); + HUnlock(tab->messages_te); ShowControl(tab->messages_scroller); if (tab->nick_list) { + HLock(tab->nick_list); EraseRect(&(*(tab->nick_list))->rView); LDoDraw(true, tab->nick_list); LUpdate(chatter->win->visRgn, tab->nick_list); + HUnlock(tab->nick_list); } + HLock(chatter->input_te); + TEUpdate(&(*(chatter->input_te))->viewRect, chatter->input_te); + HUnlock(chatter->input_te); + DrawControls(chatter->win); chatter_draw_tab_bar(chatter); @@ -514,22 +539,28 @@ chatter_update(struct focusable *focusable, EventRecor EraseRect(&chatter->win->portRect); if (tab->nick_list) { + HLock(tab->nick_list); r = (*(tab->nick_list))->rView; + HUnlock(tab->nick_list); LUpdate(chatter->win->visRgn, tab->nick_list); InsetRect(&r, -1, -1); FrameRect(&r); } + HLock(tab->messages_te); r = (*(tab->messages_te))->viewRect; InsetRect(&r, -1, -1); FrameRect(&r); TEUpdate(&(*(tab->messages_te))->viewRect, tab->messages_te); - + HUnlock(tab->messages_te); + + HLock(chatter->input_te); r = (*(chatter->input_te))->viewRect; InsetRect(&r, -1, -1); FrameRect(&r); TEUpdate(&(*(chatter->input_te))->viewRect, chatter->input_te); - + HUnlock(chatter->input_te); + DrawControls(chatter->win); chatter_draw_tab_bar(chatter); @@ -670,9 +701,11 @@ chatter_draw_tab_bar(struct chatter *chatter) SetPortBits(&cur_bits); + HLock(chatter->input_te); r = chatter->tab_bar.bounds; r.bottom = (*(chatter->input_te))->viewRect.top; r.top += r.bottom - TAB_BAR_HEIGHT; + HUnlock(chatter->input_te); SLIST_FOREACH(tab, &chatter->tabs_list, list) { tab->label_rect.top += r.top; @@ -768,6 +801,7 @@ chatter_mouse_down(struct focusable *focusable, EventR } } + HLock(tab->messages_te); r = (*(tab->messages_te))->viewRect; if (PtInRect(p, &r)) { TEClick(p, ((event->modifiers & shiftKey) != 0), tab->messages_te); @@ -778,7 +812,9 @@ chatter_mouse_down(struct focusable *focusable, EventR HUnlock(tab->messages_te); return; } + HUnlock(tab->messages_te); + HLock(chatter->input_te); r = (*(chatter->input_te))->viewRect; if (PtInRect(p, &r)) { TEClick(p, ((event->modifiers & shiftKey) != 0), @@ -790,6 +826,7 @@ chatter_mouse_down(struct focusable *focusable, EventR HUnlock(chatter->input_te); return; } + HUnlock(chatter->input_te); SLIST_FOREACH(ttab, &chatter->tabs_list, list) { if (PtInRect(p, &ttab->label_rect)) { @@ -863,7 +900,9 @@ chatter_resize(struct focusable *focusable, EventRecor continue; chatter_layout_tab(chatter, ttab, NULL, false); + HLock(ttab->messages_te); TEUpdate(&(*(ttab->messages_te))->viewRect, ttab->messages_te); + HUnlock(ttab->messages_te); TEPinScroll(0, INT_MAX, ttab->messages_te); /* this will scroll back down */ chatter_autoscroll(chatter, ttab->messages_te, @@ -872,8 +911,10 @@ chatter_resize(struct focusable *focusable, EventRecor /* update the current tab as-is */ chatter_layout(chatter, false, NULL); + HLock(chatter->current_tab->messages_te); TEUpdate(&(*(chatter->current_tab->messages_te))->viewRect, chatter->current_tab->messages_te); + HUnlock(chatter->current_tab->messages_te); TEPinScroll(0, INT_MAX, chatter->current_tab->messages_te); chatter_autoscroll(chatter, chatter->current_tab->messages_te, chatter->current_tab->messages_scroller); @@ -1035,6 +1076,7 @@ chatter_printf(struct chatter *chatter, struct irc_con had_activity = tab->have_activity; + HLock(tab->messages_te); if ((*(tab->messages_te))->teLength > 0) { buf[0] = '\r'; len++; @@ -1113,11 +1155,10 @@ chatter_printf(struct chatter *chatter, struct irc_con if (!buf_out_len) { HUnlock(scrp_rec_h); + HUnlock(tab->messages_te); return 0; } - HLock(tab->messages_te); - /* check for TE overflow */ /* too many lines */ @@ -1204,8 +1245,7 @@ chatter_clear_messages(struct chatter *chatter, struct GetClip(savergn); ClipRect(&zerorect); - TESetSelect(0, SHRT_MAX, tab->messages_te); - TEDelete(tab->messages_te); + TESetText(NULL, 0, tab->messages_te); /* scroll up, causing a repaint */ TEPinScroll(0, INT_MAX, tab->messages_te);