aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornyamatongwe <unknown>2002-02-12 10:33:20 +0000
committernyamatongwe <unknown>2002-02-12 10:33:20 +0000
commite1d512dbcda9c04693074c04f26d248d7d1aaaad (patch)
tree8455e42c856dae4a5f0e25da08235c2738e92144
parent1ec77111903af33c0fb4a553e5a26996cf7a636e (diff)
downloadscintilla-mirror-e1d512dbcda9c04693074c04f26d248d7d1aaaad.tar.gz
Made font cache thread safe by using a critical section.
-rw-r--r--win32/PlatWin.cxx38
-rw-r--r--win32/ScintillaWin.cxx17
2 files changed, 40 insertions, 15 deletions
diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx
index 1a1028e04..8cca64deb 100644
--- a/win32/PlatWin.cxx
+++ b/win32/PlatWin.cxx
@@ -21,6 +21,9 @@
#include "PlatformRes.h"
#include "UniConversion.h"
+static CRITICAL_SECTION crPlatformLock;
+static HINSTANCE hinstPlatformRes = 0;
+
Point Point::FromLong(long lpoint) {
return Point(static_cast<short>(LOWORD(lpoint)), static_cast<short>(HIWORD(lpoint)));
}
@@ -169,25 +172,30 @@ void FontCached::Release() {
}
FontID FontCached::FindOrCreate(const char *faceName_, int characterSet_, int size_, bool bold_, bool italic_) {
+ FontID ret = 0;
+ ::EnterCriticalSection(&crPlatformLock);
int hashFind = HashFont(faceName_, characterSet_, size_, bold_, italic_);
for (FontCached *cur=first; cur; cur=cur->next) {
if ((cur->hash == hashFind) &&
cur->SameAs(faceName_, characterSet_, size_, bold_, italic_)) {
cur->usage++;
- return cur->id;
+ ret = cur->id;
}
}
- FontCached *fc = new FontCached(faceName_, characterSet_, size_, bold_, italic_);
- if (fc) {
- fc->next = first;
- first = fc;
- return fc->id;
- } else {
- return 0;
+ if (ret == 0) {
+ FontCached *fc = new FontCached(faceName_, characterSet_, size_, bold_, italic_);
+ if (fc) {
+ fc->next = first;
+ first = fc;
+ ret = fc->id;
+ }
}
+ ::LeaveCriticalSection(&crPlatformLock);
+ return ret;
}
void FontCached::ReleaseId(FontID id_) {
+ ::EnterCriticalSection(&crPlatformLock);
FontCached **pcur=&first;
for (FontCached *cur=first; cur; cur=cur->next) {
if (cur->id == id_) {
@@ -198,10 +206,11 @@ void FontCached::ReleaseId(FontID id_) {
cur->next = 0;
delete cur;
}
- return;
+ break;
}
pcur=&cur->next;
}
+ ::LeaveCriticalSection(&crPlatformLock);
}
Font::Font() {
@@ -716,8 +725,6 @@ void Window::SetFont(Font &font) {
reinterpret_cast<WPARAM>(font.GetID()), 0);
}
-HINSTANCE hinstPlatformRes = 0;
-
void Window::SetCursor(Cursor curs) {
switch (curs) {
case cursorText:
@@ -1024,3 +1031,12 @@ int Platform::Clamp(int val, int minVal, int maxVal) {
val = minVal;
return val;
}
+
+void Platform_Initialise(void *hInstance) {
+ ::InitializeCriticalSection(&crPlatformLock);
+ hinstPlatformRes = reinterpret_cast<HINSTANCE>(hInstance);
+}
+
+void Platform_Finalise() {
+ ::DeleteCriticalSection(&crPlatformLock);
+}
diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx
index c65600ab4..ddcab290b 100644
--- a/win32/ScintillaWin.cxx
+++ b/win32/ScintillaWin.cxx
@@ -1916,12 +1916,19 @@ sptr_t PASCAL ScintillaWin::SWndProc(
}
}
-extern HINSTANCE hinstPlatformRes;
+extern void Platform_Initialise(void *hInstance);
+extern void Platform_Finalise();
-// This function is externally visible so it can be called from container when building statically
+// This function is externally visible so it can be called from container when building statically.
+// Must be called once only.
void Scintilla_RegisterClasses(void *hInstance) {
- hinstPlatformRes = reinterpret_cast<HINSTANCE>(hInstance);
- ScintillaWin::Register(hinstPlatformRes);
+ Platform_Initialise(hInstance);
+ ScintillaWin::Register(reinterpret_cast<HINSTANCE>(hInstance));
+}
+
+// This function is externally visible so it can be called from container when building statically.
+void Scintilla_ReleaseResources() {
+ Platform_Finalise();
}
#ifndef STATIC_BUILD
@@ -1929,6 +1936,8 @@ extern "C" int APIENTRY DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID) {
//Platform::DebugPrintf("Scintilla::DllMain %d %d\n", hInstance, dwReason);
if (dwReason == DLL_PROCESS_ATTACH) {
Scintilla_RegisterClasses(hInstance);
+ } else if (dwReason == DLL_PROCESS_DETACH) {
+ Scintilla_ReleaseResources();
}
return TRUE;
}