Permalink
Browse files

Protect fontface cache with critical section

  • Loading branch information...
theli-ua committed Aug 4, 2017
1 parent 65a06fa commit 178104b59b0415fd24f48a14f921a30d03fcef3e
Showing with 14 additions and 0 deletions.
  1. +14 −0 dlls/dwrite/font.c
@@ -69,6 +69,15 @@ struct dwrite_font_propvec {
FLOAT weight;
};

static CRITICAL_SECTION fcached_cs;
static CRITICAL_SECTION_DEBUG critsect_debug =
{
0, 0, &fcached_cs,
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
0, 0, { (DWORD_PTR)(__FILE__ ": fcached_cs") }
};
static CRITICAL_SECTION fcached_cs = { &critsect_debug, -1, 0, 0, 0, 0 };

struct dwrite_font_data {
LONG ref;

@@ -482,6 +491,7 @@ static ULONG WINAPI dwritefontface_AddRef(IDWriteFontFace4 *iface)
static ULONG WINAPI dwritefontface_Release(IDWriteFontFace4 *iface)
{
struct dwrite_fontface *This = impl_from_IDWriteFontFace4(iface);
EnterCriticalSection(&fcached_cs);
ULONG ref = InterlockedDecrement(&This->ref);

TRACE("(%p)->(%d)\n", This, ref);
@@ -519,6 +529,7 @@ static ULONG WINAPI dwritefontface_Release(IDWriteFontFace4 *iface)
heap_free(This);
}

LeaveCriticalSection(&fcached_cs);
return ref;
}

@@ -1377,12 +1388,15 @@ static HRESULT get_fontface_from_font(struct dwrite_font *font, IDWriteFontFace4

*fontface = NULL;

EnterCriticalSection(&fcached_cs);
hr = factory_get_cached_fontface(font->family->collection->factory, &data->file, data->face_index,
font->data->simulations, (IDWriteFontFace **)fontface, &cached_list);
if (hr == S_OK) {
IDWriteFontFace4_AddRef(*fontface);
LeaveCriticalSection(&fcached_cs);
return hr;
}
LeaveCriticalSection(&fcached_cs);

desc.factory = font->family->collection->factory;
desc.face_type = data->face_type;

0 comments on commit 178104b

Please sign in to comment.