From eeef426b8399ad39dfc759352a6e7b0348a047d1 Mon Sep 17 00:00:00 2001 From: rpj Date: Fri, 5 Jan 2007 01:19:56 +0000 Subject: Added more Win64 support --- ChangeLog | 18 +++++++++- context.h | 70 ++++++++++++++++++++++++++++++++++++++ implement.h | 4 +++ pthread_cancel.c | 29 +--------------- pthread_win32_attach_detach_np.c | 11 ++++++ ptw32_InterlockedCompareExchange.c | 8 +++-- tests/ChangeLog | 5 +++ tests/context1.c | 6 ++-- tests/once3.c | 11 +++--- 9 files changed, 120 insertions(+), 42 deletions(-) create mode 100644 context.h diff --git a/ChangeLog b/ChangeLog index b85d9f9..d9feacc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,20 @@ -2006-12-20 Ross Johnson +2007-01-04 Ross Johnson + + * ptw32_InterlockedCompareExchange.c: Conditionally skip for + Win64 as not required. + * pthread_win32_attach_detach_np.c (pthread_win32_process_attach_np): + Test for InterlockedCompareExchange is not required for Win64. + * context.h: New file. Included by pthread_cancel.h and any tests + that need it (e.g. context1.c). + * pthread_cancel.c: Architecture-dependent context macros moved + to context.h. + +2007-01-04 Kip Streithorst + + * implement.h (PTW32_INTERLOCKED_COMPARE_EXCHANGE): Add Win64 + support. + +2006-12-20 Ross Johnson * sem_destroy.c: Fix the race involving invalidation of the sema; fix incorrect return of EBUSY resulting from the mutex trylock diff --git a/context.h b/context.h new file mode 100644 index 0000000..3a399ff --- /dev/null +++ b/context.h @@ -0,0 +1,70 @@ +/* + * context.h + * + * Description: + * POSIX thread macros related to thread cancellation. + * + * -------------------------------------------------------------------------- + * + * Pthreads-win32 - POSIX Threads Library for Win32 + * Copyright(C) 1998 John E. Bossom + * Copyright(C) 1999,2005 Pthreads-win32 contributors + * + * Contact Email: rpj@callisto.canberra.edu.au + * + * The current list of contributors is contained + * in the file CONTRIBUTORS included with the source + * code distribution. The list can also be seen at the + * following World Wide Web location: + * http://sources.redhat.com/pthreads-win32/contributors.html + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library in the file COPYING.LIB; + * if not, write to the Free Software Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef PTW32_CONTEXT_H +#define PTW32_CONTEXT_H + +#undef PTW32_PROGCTR + +#if defined(_M_IX86) || defined(_X86_) +#define PTW32_PROGCTR(Context) ((Context).Eip) +#endif + +#if defined (_M_IA64) || defined(_IA64) +#define PTW32_PROGCTR(Context) ((Context).StIIP) +#endif + +#if defined(_MIPS_) +#define PTW32_PROGCTR(Context) ((Context).Fir) +#endif + +#if defined(_ALPHA_) +#define PTW32_PROGCTR(Context) ((Context).Fir) +#endif + +#if defined(_PPC_) +#define PTW32_PROGCTR(Context) ((Context).Iar) +#endif + +#if defined(_AMD64_) || defined(__amd64__) +#define PTW32_PROGCTR(Context) ((Context).Rip) +#endif + +#if !defined(PTW32_PROGCTR) +#error Module contains CPU-specific code; modify and recompile. +#endif + +#endif diff --git a/implement.h b/implement.h index 3d96483..82a7a8f 100644 --- a/implement.h +++ b/implement.h @@ -667,8 +667,12 @@ extern "C" * See ptw32_InterlockedCompareExchange.c */ #ifndef PTW32_INTERLOCKED_COMPARE_EXCHANGE +#ifdef _WIN64 +#define PTW32_INTERLOCKED_COMPARE_EXCHANGE _InterlockedCompareExchange +#else #define PTW32_INTERLOCKED_COMPARE_EXCHANGE ptw32_interlocked_compare_exchange #endif +#endif #ifndef PTW32_INTERLOCKED_EXCHANGE #define PTW32_INTERLOCKED_EXCHANGE InterlockedExchange diff --git a/pthread_cancel.c b/pthread_cancel.c index 1118977..7d519ee 100644 --- a/pthread_cancel.c +++ b/pthread_cancel.c @@ -36,34 +36,7 @@ #include "pthread.h" #include "implement.h" - -#if defined(_M_IX86) || defined(_X86_) -#define PTW32_PROGCTR(Context) ((Context).Eip) -#endif - -#if defined (_M_IA64) -#define PTW32_PROGCTR(Context) ((Context).StIIP) -#endif - -#if defined(_MIPS_) -#define PTW32_PROGCTR(Context) ((Context).Fir) -#endif - -#if defined(_ALPHA_) -#define PTW32_PROGCTR(Context) ((Context).Fir) -#endif - -#if defined(_PPC_) -#define PTW32_PROGCTR(Context) ((Context).Iar) -#endif - -#if defined(_AMD64_) -#define PTW32_PROGCTR(Context) ((Context).Rip) -#endif - -#if !defined(PTW32_PROGCTR) -#error Module contains CPU-specific code; modify and recompile. -#endif +#include "context.h" static void ptw32_cancel_self (void) diff --git a/pthread_win32_attach_detach_np.c b/pthread_win32_attach_detach_np.c index 2f0bc37..7911fe1 100644 --- a/pthread_win32_attach_detach_np.c +++ b/pthread_win32_attach_detach_np.c @@ -91,6 +91,15 @@ pthread_win32_process_attach_np () #endif +#ifdef _WIN64 + +/* + * InterlockedCompareExchange routine in WIN64 is an intrinsic function. + * See PTW32_INTERLOCKED_COMPARE_EXCHANGE implement.h + */ + +#else + #ifdef WINCE /* @@ -144,6 +153,8 @@ pthread_win32_process_attach_np () ptw32_features |= PTW32_SYSTEM_INTERLOCKED_COMPARE_EXCHANGE; } +#endif + /* * Load QUSEREX.DLL and try to get address of QueueUserAPCEx */ diff --git a/ptw32_InterlockedCompareExchange.c b/ptw32_InterlockedCompareExchange.c index 0094635..be39cd4 100644 --- a/ptw32_InterlockedCompareExchange.c +++ b/ptw32_InterlockedCompareExchange.c @@ -35,6 +35,8 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ +#ifndef _WIN64 + #include "pthread.h" #include "implement.h" @@ -250,8 +252,8 @@ L1: MOV eax,dword ptr [ecx] * FIXME! Need memory barriers for the MOV+CMPXCHG combo? * * Tests show that this routine has almost identical timing - * to Win32's InterlockedExchange(), which is much faster than - * using the an inlined 'xchg' instruction, so it's probably + * to Win32's InterlockedExchange(), and is much faster than + * using an inlined 'xchg' instruction, so Win32 is probably * doing something similar to this (on UP systems). */ __asm__ __volatile__ @@ -301,3 +303,5 @@ L1: MOV eax,dword ptr [ecx] #endif #endif + +#endif diff --git a/tests/ChangeLog b/tests/ChangeLog index 6b2c742..30f6ccb 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,8 @@ +2007-01-04 Ross Johnson + + * context1.c: Include context.h from library sources and remove + x86 dependence in main(). + 2005-06-12 Ross Johnson * stress1.c (millisecondsFromNow): Remove limit 0 <= millisecs < 1000; diff --git a/tests/context1.c b/tests/context1.c index 090df9c..e63dbec 100644 --- a/tests/context1.c +++ b/tests/context1.c @@ -75,6 +75,7 @@ #include "test.h" #include "../implement.h" +#include "../context.h" static int washere = 0; @@ -122,10 +123,7 @@ main() context.ContextFlags = CONTEXT_CONTROL; GetThreadContext(hThread, &context); - /* - *_x86 only!!! - */ - context.Eip = (DWORD) anotherEnding; + PTW32_PROGCTR (context) = (DWORD_PTR) anotherEnding; SetThreadContext(hThread, &context); ResumeThread(hThread); } diff --git a/tests/once3.c b/tests/once3.c index 981bbf7..51d2daa 100644 --- a/tests/once3.c +++ b/tests/once3.c @@ -34,7 +34,7 @@ * -------------------------------------------------------------------------- * * Create several pthread_once objects and channel several threads - * through each. Make the init_routine cancelable and cancel them with + * through each. Make the init_routine cancelable and cancel them * waiters waiting. * * Depends on API functions: @@ -45,8 +45,6 @@ * pthread_once() */ -#define ASSERT_TRACE - #include "test.h" #define NUM_THREADS 100 /* Targeting each once control */ @@ -68,7 +66,6 @@ myfunc(void) { EnterCriticalSection(&numOnce.cs); numOnce.i++; - assert(numOnce.i > 0); LeaveCriticalSection(&numOnce.cs); /* Simulate slow once routine so that following threads pile up behind it */ Sleep(10); @@ -81,11 +78,11 @@ mythread(void * arg) { /* * Cancel every thread. These threads are deferred cancelable only, so - * only the thread performing the once routine (my_func) will see it (there are + * only the thread performing the init_routine will see it (there are * no other cancelation points here). The result will be that every thread - * eventually cancels only when it becomes the new once thread. + * eventually cancels only when it becomes the new initter. */ - assert(pthread_cancel(pthread_self()) == 0); + pthread_cancel(pthread_self()); assert(pthread_once(&once[(int) arg], myfunc) == 0); EnterCriticalSection(&numThreads.cs); numThreads.i++; -- cgit v1.2.3