Bug 27344 - _cairo_atomic_mutex not initialized
Summary: _cairo_atomic_mutex not initialized
Status: RESOLVED MOVED
Alias: None
Product: cairo
Classification: Unclassified
Component: general (show other bugs)
Version: 1.9.6
Hardware: x86 (IA32) Windows (All)
: medium normal
Assignee: Carl Worth
QA Contact: cairo-bugs mailing list
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-27 08:50 UTC by gillen.christian
Modified: 2018-08-25 13:52 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments
Win32 atomic ops (885 bytes, patch)
2010-03-27 20:06 UTC, gillen.christian
Details | Splinter Review

Description gillen.christian 2010-03-27 08:50:09 UTC
Hi, 

I compiled a static build of cairo on Windows with MSVC9.
I'm using only the svg surface. If the the cairo_create call fails (because I set an invalid filename) _cairo_set_error is called which results in an access violation in the _cairo_atomic_int_cmpxchg function. The reason is that _cairo_atomic_mutex hasn't been initialized at that point. 

If I call CAIRO_MUTEX_INIT(_cairo_atomic_mutex) or CAIRO_MUTEX_INITIALIZE() before that point everything works as expected.
Comment 1 Chris Wilson 2010-03-27 09:55:42 UTC
Gillen, thanks for the report. I will try to remember to look over which pathways are missing the INITIALIZER.

However, do you mind investing why you need the atomic mutex in the first place? i.e. how we are not detecting or have chosen the correct atomics ops for windows. [There is a massive performance cost in using the mutex based fallbacks instead of atomic ops.]
Comment 2 gillen.christian 2010-03-27 11:22:03 UTC
Well I build cairo with my own build system, so I could have missed an important configuration step. But if I understand the code correctly there are only 2 implementations of atomic ops: The Intel atomic ops which don't work with the Microsoft compiler and the atomic_ops library which I currently don't have installed. Is there another one which I am missing?
Comment 3 Chris Wilson 2010-03-27 11:50:15 UTC
Oh well. I have memories of at least the Intel mmx/sse[123] intrinics being available for MSVC, or at least something approaching interoperability. For someone knowledgeable in the Win32 APIs I am sure that adding the equivalent wouldn't be too challenging. InterleavedLockExchange() and friends, IIRC.
Comment 4 gillen.christian 2010-03-27 20:06:31 UTC
Created attachment 34513 [details] [review]
Win32 atomic ops

Well here is a patch that implements the needed defines with winapi functions. It works for my very simple usecase, but I haven't tested it further. If you want to use atomic ops, cairo also needs the ffs function which doesn't exist in MSVC. The following code can replace it:

int ffs(int mask) 
{
	unsigned long index;
	if (_BitScanForward(&index, mask) == 0)
		return 0;
	else
		return index + 1;
}
Comment 5 GitLab Migration User 2018-08-25 13:52:57 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/cairo/cairo/issues/245.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.