Skip to content

Commit 68b8cd3

Browse files
Pushed locking through to Window drawing thread on MacOSX. For #1790.
1 parent 7b7b63f commit 68b8cd3

File tree

7 files changed

+28
-17
lines changed

7 files changed

+28
-17
lines changed

RESTService/addon.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,11 @@ namespace minsky
276276

277277
void macOSXDrawNativeWindows()
278278
{
279-
const lock_guard<mutex> lock(minskyCmdMutex);
279+
// share the lock with all window redraw routines - when all windows redrawn, lock is released
280+
auto lock=make_shared<lock_guard<mutex>>(minskyCmdMutex);
280281
const Timer timer(timers["draw"]);
281282
for (auto i: nativeWindowsToRedraw)
282-
i->macOSXRedraw();
283+
macOSXRedraw(*i,lock);
283284
nativeWindowsToRedraw.clear();
284285
drawLaunched=false;
285286
}

RESTService/typescriptAPI.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ int main()
309309
cout << "class classdesc__RESTProcess_t {}\n";
310310
cout << "class classdesc__TCL_obj_t {}\n";
311311
cout << "class ecolab__cairo__Surface {}\n";
312+
cout << "class std__lock_guard {}\n";
312313
cout<<endl;
313314

314315
// these need to be declared in a specific order

gui-js/libs/shared/src/lib/backend/minsky.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class classdesc__pack_t {}
1616
class classdesc__RESTProcess_t {}
1717
class classdesc__TCL_obj_t {}
1818
class ecolab__cairo__Surface {}
19+
class std__lock_guard {}
1920

2021
export class EventInterface extends CppClass {
2122
item: Item;
@@ -172,7 +173,6 @@ export class RenderNativeWindow extends EventInterface {
172173
async frameArgs(): Promise<minsky__RenderNativeWindow__RenderFrameArgs> {return this.$callMethod('frameArgs');}
173174
async hasScrollBars(): Promise<boolean> {return this.$callMethod('hasScrollBars');}
174175
async init(): Promise<void> {return this.$callMethod('init');}
175-
async macOSXRedraw(): Promise<void> {return this.$callMethod('macOSXRedraw');}
176176
async registerImage(): Promise<void> {return this.$callMethod('registerImage');}
177177
async renderFrame(a1: minsky__RenderNativeWindow__RenderFrameArgs): Promise<void> {return this.$callMethod('renderFrame',a1);}
178178
async renderToEMF(a1: string): Promise<void> {return this.$callMethod('renderToEMF',a1);}
@@ -376,7 +376,6 @@ export class CSVDialog extends CppClass {
376376
async keyPress(a1: minsky__EventInterface__KeyPressArgs): Promise<boolean> {return this.$callMethod('keyPress',a1);}
377377
async loadFile(): Promise<void> {return this.$callMethod('loadFile');}
378378
async loadFileFromName(a1: string): Promise<void> {return this.$callMethod('loadFileFromName',a1);}
379-
async macOSXRedraw(): Promise<void> {return this.$callMethod('macOSXRedraw');}
380379
async mouseDown(a1: number,a2: number): Promise<void> {return this.$callMethod('mouseDown',a1,a2);}
381380
async mouseMove(a1: number,a2: number): Promise<void> {return this.$callMethod('mouseMove',a1,a2);}
382381
async mouseUp(a1: number,a2: number): Promise<void> {return this.$callMethod('mouseUp',a1,a2);}
@@ -470,7 +469,6 @@ export class Canvas extends RenderNativeWindow {
470469
async keyPress(a1: minsky__EventInterface__KeyPressArgs): Promise<boolean> {return this.$callMethod('keyPress',a1);}
471470
async lassoMode(...args: string[]): Promise<string> {return this.$callMethod('lassoMode',...args);}
472471
async lockRavelsInSelection(): Promise<void> {return this.$callMethod('lockRavelsInSelection');}
473-
async macOSXRedraw(): Promise<void> {return this.$callMethod('macOSXRedraw');}
474472
async mouseDown(a1: number,a2: number): Promise<void> {return this.$callMethod('mouseDown',a1,a2);}
475473
async mouseMove(a1: number,a2: number): Promise<void> {return this.$callMethod('mouseMove',a1,a2);}
476474
async mouseUp(a1: number,a2: number): Promise<void> {return this.$callMethod('mouseUp',a1,a2);}
@@ -641,7 +639,6 @@ export class EquationDisplay extends RenderNativeWindow {
641639
async init(): Promise<void> {return this.$callMethod('init');}
642640
async keyPress(a1: minsky__EventInterface__KeyPressArgs): Promise<boolean> {return this.$callMethod('keyPress',a1);}
643641
async m_zoomFactor(...args: number[]): Promise<number> {return this.$callMethod('m_zoomFactor',...args);}
644-
async macOSXRedraw(): Promise<void> {return this.$callMethod('macOSXRedraw');}
645642
async mouseDown(a1: number,a2: number): Promise<void> {return this.$callMethod('mouseDown',a1,a2);}
646643
async mouseMove(a1: number,a2: number): Promise<void> {return this.$callMethod('mouseMove',a1,a2);}
647644
async mouseUp(a1: number,a2: number): Promise<void> {return this.$callMethod('mouseUp',a1,a2);}
@@ -693,7 +690,6 @@ export class FontDisplay extends CppClass {
693690
async hasScrollBars(): Promise<boolean> {return this.$callMethod('hasScrollBars');}
694691
async init(): Promise<void> {return this.$callMethod('init');}
695692
async keyPress(a1: minsky__EventInterface__KeyPressArgs): Promise<boolean> {return this.$callMethod('keyPress',a1);}
696-
async macOSXRedraw(): Promise<void> {return this.$callMethod('macOSXRedraw');}
697693
async mouseDown(a1: number,a2: number): Promise<void> {return this.$callMethod('mouseDown',a1,a2);}
698694
async mouseMove(a1: number,a2: number): Promise<void> {return this.$callMethod('mouseMove',a1,a2);}
699695
async mouseUp(a1: number,a2: number): Promise<void> {return this.$callMethod('mouseUp',a1,a2);}
@@ -945,7 +941,6 @@ export class GodleyTableWindow extends CppClass {
945941
async insertIdx(...args: number[]): Promise<number> {return this.$callMethod('insertIdx',...args);}
946942
async keyPress(...args: any[]): Promise<boolean> {return this.$callMethod('keyPress',...args);}
947943
async leftTableOffset(...args: number[]): Promise<number> {return this.$callMethod('leftTableOffset',...args);}
948-
async macOSXRedraw(): Promise<void> {return this.$callMethod('macOSXRedraw');}
949944
async matchingTableColumns(a1: number): Promise<string[]> {return this.$callMethod('matchingTableColumns',a1);}
950945
async matchingTableColumnsByCol(a1: number): Promise<string[]> {return this.$callMethod('matchingTableColumnsByCol',a1);}
951946
async maxHistory(...args: number[]): Promise<number> {return this.$callMethod('maxHistory',...args);}
@@ -1487,7 +1482,6 @@ export class PhillipsDiagram extends RenderNativeWindow {
14871482
async hasScrollBars(): Promise<boolean> {return this.$callMethod('hasScrollBars');}
14881483
async init(): Promise<void> {return this.$callMethod('init');}
14891484
async keyPress(a1: minsky__EventInterface__KeyPressArgs): Promise<boolean> {return this.$callMethod('keyPress',a1);}
1490-
async macOSXRedraw(): Promise<void> {return this.$callMethod('macOSXRedraw');}
14911485
async mouseDown(a1: number,a2: number): Promise<void> {return this.$callMethod('mouseDown',a1,a2);}
14921486
async mouseMove(a1: number,a2: number): Promise<void> {return this.$callMethod('mouseMove',a1,a2);}
14931487
async mouseUp(a1: number,a2: number): Promise<void> {return this.$callMethod('mouseUp',a1,a2);}
@@ -1649,7 +1643,6 @@ export class PlotWidget extends Item {
16491643
async lh(a1: number,a2: number): Promise<number> {return this.$callMethod('lh',a1,a2);}
16501644
async logx(...args: boolean[]): Promise<boolean> {return this.$callMethod('logx',...args);}
16511645
async logy(...args: boolean[]): Promise<boolean> {return this.$callMethod('logy',...args);}
1652-
async macOSXRedraw(): Promise<void> {return this.$callMethod('macOSXRedraw');}
16531646
async makeDisplayPlot(): Promise<void> {return this.$callMethod('makeDisplayPlot');}
16541647
async maxx(...args: number[]): Promise<number> {return this.$callMethod('maxx',...args);}
16551648
async maxy(...args: number[]): Promise<number> {return this.$callMethod('maxy',...args);}
@@ -1894,7 +1887,6 @@ export class RavelPopup extends CppClass {
18941887
async hasScrollBars(): Promise<boolean> {return this.$callMethod('hasScrollBars');}
18951888
async init(): Promise<void> {return this.$callMethod('init');}
18961889
async keyPress(a1: minsky__EventInterface__KeyPressArgs): Promise<boolean> {return this.$callMethod('keyPress',a1);}
1897-
async macOSXRedraw(): Promise<void> {return this.$callMethod('macOSXRedraw');}
18981890
async mouseDown(a1: number,a2: number): Promise<void> {return this.$callMethod('mouseDown',a1,a2);}
18991891
async mouseLeave(): Promise<void> {return this.$callMethod('mouseLeave');}
19001892
async mouseMove(a1: number,a2: number): Promise<void> {return this.$callMethod('mouseMove',a1,a2);}
@@ -2222,7 +2214,6 @@ export class VariablePane extends CppClass {
22222214
async justification(a1: number): Promise<string> {return this.$callMethod('justification',a1);}
22232215
async keyPress(a1: minsky__EventInterface__KeyPressArgs): Promise<boolean> {return this.$callMethod('keyPress',a1);}
22242216
async m_zoomFactor(...args: number[]): Promise<number> {return this.$callMethod('m_zoomFactor',...args);}
2225-
async macOSXRedraw(): Promise<void> {return this.$callMethod('macOSXRedraw');}
22262217
async mouseDown(a1: number,a2: number): Promise<void> {return this.$callMethod('mouseDown',a1,a2);}
22272218
async mouseMove(a1: number,a2: number): Promise<void> {return this.$callMethod('mouseMove',a1,a2);}
22282219
async mouseUp(a1: number,a2: number): Promise<void> {return this.$callMethod('mouseUp',a1,a2);}

model/getContext.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ namespace minsky
116116
cairo_surface_set_device_offset(winfo->bufferSurface->surface(), 0, 20);
117117
winfo->draw();
118118
winfo->bufferSurface.reset();
119+
winfo->lock.reset(); // unlock any mutex attached to this window
119120
}
120121
- (NSView *) hitTest: (NSPoint) aPoint
121122
{

model/renderNativeWindow.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Please especially review the lifecycle (constructors, desctructors and copy cons
3535
#include "renderNativeWindow.xcd"
3636
#include "plot.rcd"
3737
#include "plot.xcd"
38+
3839
#include "minsky_epilogue.h"
3940

4041
#include <stdexcept>
@@ -91,19 +92,19 @@ namespace minsky
9192
winInfoPtr.reset();
9293
}
9394

94-
void RenderNativeWindow::macOSXRedraw()
95+
void macOSXRedraw(RenderNativeWindow& window,const std::shared_ptr<std::lock_guard<std::mutex>>& lock)
9596
{
9697
#ifdef MAC_OSX_TK
97-
if (!winInfoPtr.get()) return;
98-
winInfoPtr->requestRedraw();
98+
if (!window->winInfoPtr.get()) return;
99+
window->winInfoPtr->lock=macOSXDrawLock;
100+
window->winInfoPtr->requestRedraw();
99101
#endif
100102
}
101103

102104

103105
void RenderNativeWindow::requestRedraw()
104106
{
105107
if (!winInfoPtr.get()) return;
106-
macOSXRedraw();
107108
minsky().nativeWindowsToRedraw.insert(this);
108109
}
109110

model/renderNativeWindow.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@
2525
#include <cairoSurfaceImage.h>
2626
#include <plot.h>
2727

28+
#ifndef CLASSDESC_TYPENAME___std__lock_guard__mutex___
29+
#define CLASSDESC_TYPENAME___std__lock_guard__mutex___
30+
namespace classdesc
31+
{
32+
template <> struct tn<std::lock_guard<std::mutex>>
33+
{
34+
static string name() {return "std::lock_guard<std::mutex>";}
35+
};
36+
}
37+
#endif
38+
2839
namespace minsky
2940
{
3041
class WindowInformation;
@@ -53,7 +64,8 @@ namespace minsky
5364
void destroyFrame();
5465
void draw();
5566
void requestRedraw();
56-
void macOSXRedraw();
67+
// implemented as a free function to avoid Classdesc exposing this to Typescript
68+
friend void macOSXRedraw(RenderNativeWindow&,const std::shared_ptr<std::lock_guard<std::mutex>>&);
5769
// do not clobber winInfoPtr on load of model
5870
RenderNativeWindow& operator=(const RenderNativeWindow& x) {ecolab::CairoSurface::operator=(x); return *this;}
5971
RenderNativeWindow()=default;
@@ -75,6 +87,9 @@ namespace minsky
7587
};
7688
classdesc::Exclude<CopiableMutux> drawMutex;
7789
};
90+
91+
//void macOSXRedraw(RenderNativeWindow&,const std::shared_ptr<std::lock_guard<std::mutex>>&);
92+
7893
} // namespace minsky
7994

8095
#include "renderNativeWindow.cd"

model/windowInformation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ namespace minsky
5050
HANDLE hOld; //
5151
#elif defined(MAC_OSX_TK)
5252
NSContext nsContext;
53+
std::shared_ptr<std::lock_guard<std::mutex>> lock;
5354
Winfo(NSContext&& nsContext): nsContext(std::move(nsContext)) {}
5455
#elif defined(USE_X11)
5556
Window parentWindowId;

0 commit comments

Comments
 (0)