Skip to content

Commit

Permalink
Added more Win64 support
Browse files Browse the repository at this point in the history
  • Loading branch information
rpj committed Jan 5, 2007
1 parent a7ed60c commit eeef426
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 42 deletions.
18 changes: 17 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
2006-12-20 Ross Johnson <[email protected]>
2007-01-04 Ross Johnson <ross.johnson at homemail dot com dot au>

* 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 <KSTREITH at ball dot com>

* implement.h (PTW32_INTERLOCKED_COMPARE_EXCHANGE): Add Win64
support.

2006-12-20 Ross Johnson <ross.johnson at homemail dot com dot au>

* sem_destroy.c: Fix the race involving invalidation of the sema;
fix incorrect return of EBUSY resulting from the mutex trylock
Expand Down
70 changes: 70 additions & 0 deletions context.h
Original file line number Diff line number Diff line change
@@ -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: [email protected]
*
* 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
4 changes: 4 additions & 0 deletions implement.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 1 addition & 28 deletions pthread_cancel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions pthread_win32_attach_detach_np.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

/*
Expand Down Expand Up @@ -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
*/
Expand Down
8 changes: 6 additions & 2 deletions ptw32_InterlockedCompareExchange.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/

#ifndef _WIN64

#include "pthread.h"
#include "implement.h"

Expand Down Expand Up @@ -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__
Expand Down Expand Up @@ -301,3 +303,5 @@ L1: MOV eax,dword ptr [ecx]
#endif

#endif

#endif
5 changes: 5 additions & 0 deletions tests/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2007-01-04 Ross Johnson <Ross dot Johnson at homemail dot com dot au>

* context1.c: Include context.h from library sources and remove
x86 dependence in main().

2005-06-12 Ross Johnson <[email protected]>

* stress1.c (millisecondsFromNow): Remove limit 0 <= millisecs < 1000;
Expand Down
6 changes: 2 additions & 4 deletions tests/context1.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@

#include "test.h"
#include "../implement.h"
#include "../context.h"

static int washere = 0;

Expand Down Expand Up @@ -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);
}
Expand Down
11 changes: 4 additions & 7 deletions tests/once3.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -45,8 +45,6 @@
* pthread_once()
*/

#define ASSERT_TRACE

#include "test.h"

#define NUM_THREADS 100 /* Targeting each once control */
Expand All @@ -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);
Expand All @@ -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++;
Expand Down

0 comments on commit eeef426

Please sign in to comment.