Wu Yongwei wrote:
> Danny Smith wrote:
>>>It is known
>>>that Critical Sections are more efficient. Some benchmarks can be
>>>found on the Internet. Could we use Critical Sections, as in GCC 2?
>>I thought that gcc-2.95 only used Critical Sections for allocator
>>node locks and used mutexes everywhere else. Anyway, if you have a
>>patch against GCC HEAD, I would be keen to look at it.
> Please have a look whether this is in the right direction. I have
> modified only the case when __GTHREAD_HIDE_WIN32API is 0. If it is OK,
> gcc/config/i386/gthr-win32.c, and probably the ObjC part of
> gcc/gthr-win32.h, need to be patched too. The test case really shows
> that successful mutex/critical section lock/unlock operations has a
> performance ratio of about 600/9 (instructions), as Microsoft indicates.
> The ugliest part is the definition of __gthread_mutex_t. But I have not
> found a good way without including <windows.h>.
> Best regards,
> Wu Yongwei
> static inline int
> @@ -560,7 +552,7 @@
> if (__gthread_active_p ())
> - if (WaitForSingleObject (*mutex, 0) == WAIT_OBJECT_0)
> + if (TryEnterCriticalSection ((PCRITICAL_SECTION) mutex) != 0)
WIN9x does not have TryEnterCriticalSection, therefore this will not run
I have added a mutex implementation that works similar to a Critical
Section to both pthreads_win32 and cygwin. It is based on a counter
modified by Interlocked[Increment|Decrement|CompareExchange] and a
semaphore. When the Interlocked funktions are replaced by inline
assembler routines it runs on every Windows version on a 486 or above.
If there is interest to add this to MINGW let me know. I do not think
that 9x Support should be dropped.