aboutsummaryrefslogtreecommitdiffhomepage
path: root/win32/PlatWin.cxx
diff options
context:
space:
mode:
authornyamatongwe <devnull@localhost>2002-02-12 10:33:20 +0000
committernyamatongwe <devnull@localhost>2002-02-12 10:33:20 +0000
commitfd6a4772446bae01aaaf5a9cb896bf4580c3c433 (patch)
tree8455e42c856dae4a5f0e25da08235c2738e92144 /win32/PlatWin.cxx
parentb69cc17d081f60e53b1f09d9ba012e8233afe0de (diff)
downloadscintilla-mirror-fd6a4772446bae01aaaf5a9cb896bf4580c3c433.tar.gz
Made font cache thread safe by using a critical section.
Diffstat (limited to 'win32/PlatWin.cxx')
-rw-r--r--win32/PlatWin.cxx38
1 files changed, 27 insertions, 11 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);
+}