-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSHThread.cpp
More file actions
81 lines (65 loc) · 2.11 KB
/
SHThread.cpp
File metadata and controls
81 lines (65 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <iostream>
#include <cstring> // strcpy
#include <wx/event.h>
#include "GlobalVariables.hpp"
#include "UnsavedFiles.hpp"
#include "SHThread.hpp"
#include "Styles.hpp"
const wxEventType shEVT_HIGHLIGHT = wxNewEventType();
wxThread::ExitCode SHThread::Entry()
{
fprintf(stderr, "\tThread[%p]: started.\n", &editor);
UnsavedFiles uf;
// initialize
index = clang_createIndex(0, 0);
uf = UnsavedFiles::current;
uf.Print();
unit = uf.Parse(editor, index);
if (!unit)
return 0; // TODO: event
fprintf(stderr, "\tThread[%p]: data initialized.\n", &editor);
SHEvent evt(editor);
// initial highlight: notify GUI thread
uf.PrepareSHData(editor, unit, evt.styles, evt.diagnostics);
evt.version = uf.GetVersion(editor);
handler->AddPendingEvent(evt);
while (true)
{
Action action;
fprintf(stderr, "\tThread[%p]: going to sleep\n", &editor);
{
wxMutexLocker locker(sharedData.mutex);
while (sharedData.action == NONE)
sharedData.condition.Wait();
action = sharedData.action;
sharedData.action = NONE;
}
fprintf(stderr, "\tThread[%p]: resumed, action = %d.\n", &editor, action);
switch (action)
{
case NONE:
continue;
case EXIT:
fprintf(stderr, "\tThread[%p]: exiting.\n", &editor);
return 0;
case PARSE:
clang_disposeTranslationUnit(unit);
uf = UnsavedFiles::current;
unit = uf.Parse(editor, index);
if (!unit)
return 0; // TODO: event
uf.PrepareSHData(editor, unit, evt.styles, evt.diagnostics);
evt.version = uf.GetVersion(editor);
handler->AddPendingEvent(evt);
break;
case REPARSE:
uf = UnsavedFiles::current;
uf.Reparse(unit);
uf.PrepareSHData(editor, unit, evt.styles, evt.diagnostics);
evt.version = uf.GetVersion(editor);
handler->AddPendingEvent(evt);
break;
}
}
return 0;
}