Added Interlocked*Pointer functions.

Fixed InterlockedCompareExchange prototype.
This commit is contained in:
Alexandre Julliard 2001-08-09 21:21:13 +00:00
parent da920ee9b9
commit e994d5036e
7 changed files with 41 additions and 18 deletions

View File

@ -315,10 +315,10 @@ Main_DirectDrawSurface_ChangeUniquenessValue(LPDIRECTDRAWSURFACE7 iface)
if (old_uniqueness_value == 0) break; if (old_uniqueness_value == 0) break;
if (new_uniqueness_value == 0) new_uniqueness_value = 1; if (new_uniqueness_value == 0) new_uniqueness_value = 1;
if (InterlockedCompareExchange((PVOID*)&vThis->uniqueness_value, if (InterlockedCompareExchange((LONG*)&vThis->uniqueness_value,
(PVOID)old_uniqueness_value, old_uniqueness_value,
(PVOID)new_uniqueness_value) new_uniqueness_value)
== (PVOID)old_uniqueness_value) == old_uniqueness_value)
break; break;
} }

View File

@ -127,8 +127,8 @@ static inline HANDLE get_semaphore( RTL_CRITICAL_SECTION *crit )
{ {
HANDLE sem; HANDLE sem;
if (NtCreateSemaphore( &sem, SEMAPHORE_ALL_ACCESS, NULL, 0, 1 )) return 0; if (NtCreateSemaphore( &sem, SEMAPHORE_ALL_ACCESS, NULL, 0, 1 )) return 0;
if (!(ret = (HANDLE)InterlockedCompareExchange( (PVOID *)&crit->LockSemaphore, if (!(ret = (HANDLE)interlocked_cmpxchg( (PVOID *)&crit->LockSemaphore,
(PVOID)sem, 0 ))) (PVOID)sem, 0 )))
ret = sem; ret = sem;
else else
NtClose(sem); /* somebody beat us to it */ NtClose(sem); /* somebody beat us to it */

View File

@ -736,7 +736,7 @@ static void WSOCK32_async_accept(SOCKET s, SOCKET as)
int q; int q;
/* queue socket for WSAAsyncSelect */ /* queue socket for WSAAsyncSelect */
for (q=0; q<WS_ACCEPT_QUEUE; q++) for (q=0; q<WS_ACCEPT_QUEUE; q++)
if (InterlockedCompareExchange((PVOID*)&accept_old[q], (PVOID)s, (PVOID)0) == (PVOID)0) if (InterlockedCompareExchange((LONG *)&accept_old[q], s, 0) == 0)
break; break;
if (q<WS_ACCEPT_QUEUE) if (q<WS_ACCEPT_QUEUE)
accept_new[q] = as; accept_new[q] = as;

View File

@ -273,10 +273,10 @@ static void process_attach(void)
/* setup TSX11 locking */ /* setup TSX11 locking */
#ifdef NO_REENTRANT_X11 #ifdef NO_REENTRANT_X11
old_errno_location = (void *)InterlockedExchange( (PLONG)&wine_errno_location, old_errno_location = InterlockedExchangePointer( &wine_errno_location,
(LONG)x11_errno_location ); x11_errno_location );
old_h_errno_location = (void *)InterlockedExchange( (PLONG)&wine_h_errno_location, old_h_errno_location = InterlockedExchangePointer( &wine_h_errno_location,
(LONG)x11_h_errno_location ); x11_h_errno_location );
#endif /* NO_REENTRANT_X11 */ #endif /* NO_REENTRANT_X11 */
old_tsx11_lock = wine_tsx11_lock; old_tsx11_lock = wine_tsx11_lock;
old_tsx11_unlock = wine_tsx11_unlock; old_tsx11_unlock = wine_tsx11_unlock;

View File

@ -1933,10 +1933,10 @@ BOOL WINAPI wine_get_unix_file_name( LPCSTR dos, LPSTR buffer, DWORD len
#if defined(__i386__) && defined(__GNUC__) #if defined(__i386__) && defined(__GNUC__)
extern inline PVOID WINAPI InterlockedCompareExchange( PVOID *dest, PVOID xchg, PVOID compare ); extern inline LONG WINAPI InterlockedCompareExchange( PLONG dest, LONG xchg, LONG compare );
extern inline PVOID WINAPI InterlockedCompareExchange( PVOID *dest, PVOID xchg, PVOID compare ) extern inline LONG WINAPI InterlockedCompareExchange( PLONG dest, LONG xchg, LONG compare )
{ {
PVOID ret; LONG ret;
__asm__ __volatile__( "lock; cmpxchgl %2,(%1)" __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
: "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" ); : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
return ret; return ret;
@ -1951,6 +1951,24 @@ extern inline LONG WINAPI InterlockedExchange( PLONG dest, LONG val )
return ret; return ret;
} }
extern inline PVOID WINAPI InterlockedCompareExchangePointer( PVOID *dest, PVOID xchg, PVOID compare );
extern inline PVOID WINAPI InterlockedCompareExchangePointer( PVOID *dest, PVOID xchg, PVOID compare )
{
PVOID ret;
__asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
: "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
return ret;
}
extern inline PVOID WINAPI InterlockedExchangePointer( PVOID *dest, PVOID val );
extern inline PVOID WINAPI InterlockedExchangePointer( PVOID *dest, PVOID val )
{
PVOID ret;
__asm__ __volatile__( "lock; xchgl %0,(%1)"
: "=r" (ret) :"r" (dest), "0" (val) : "memory" );
return ret;
}
extern inline LONG WINAPI InterlockedExchangeAdd( PLONG dest, LONG incr ); extern inline LONG WINAPI InterlockedExchangeAdd( PLONG dest, LONG incr );
extern inline LONG WINAPI InterlockedExchangeAdd( PLONG dest, LONG incr ) extern inline LONG WINAPI InterlockedExchangeAdd( PLONG dest, LONG incr )
{ {
@ -2015,12 +2033,17 @@ DWORD WINAPI GetCurrentProcessId(void);
DWORD WINAPI GetCurrentThreadId(void); DWORD WINAPI GetCurrentThreadId(void);
DWORD WINAPI GetLastError(void); DWORD WINAPI GetLastError(void);
HANDLE WINAPI GetProcessHeap(void); HANDLE WINAPI GetProcessHeap(void);
PVOID WINAPI InterlockedCompareExchange(PVOID*,PVOID,PVOID); LONG WINAPI InterlockedCompareExchange(LONG*,LONG,LONG);
LONG WINAPI InterlockedDecrement(PLONG); LONG WINAPI InterlockedDecrement(PLONG);
LONG WINAPI InterlockedExchange(PLONG,LONG); LONG WINAPI InterlockedExchange(PLONG,LONG);
LONG WINAPI InterlockedExchangeAdd(PLONG,LONG); LONG WINAPI InterlockedExchangeAdd(PLONG,LONG);
LONG WINAPI InterlockedIncrement(PLONG); LONG WINAPI InterlockedIncrement(PLONG);
VOID WINAPI SetLastError(DWORD); VOID WINAPI SetLastError(DWORD);
/* FIXME: should handle platforms where sizeof(void*) != sizeof(long) */
#define InterlockedCompareExchangePointer(a,b,c) \
((PVOID)InterlockedCompareExchange((PLONG)(a),(LONG)(b),(LONG)(c)))
#define InterlockedExchangePointer(a,b) \
((PVOID)InterlockedExchange((PLONG)(a),(LONG)(b)))
#endif /* __i386__ && __GNUC__ */ #endif /* __i386__ && __GNUC__ */
#ifdef __WINE__ #ifdef __WINE__

View File

@ -153,7 +153,7 @@ static lwp_mutex_t interlocked_mutex = DEFAULTMUTEX;
/*********************************************************************** /***********************************************************************
* InterlockedCompareExchange (KERNEL32.@) * InterlockedCompareExchange (KERNEL32.@)
*/ */
PVOID WINAPI InterlockedCompareExchange( PVOID *dest, PVOID xchg, PVOID compare ) LONG WINAPI InterlockedCompareExchange( PLONG dest, LONG xchg, LONG compare )
{ {
_lwp_mutex_lock( &interlocked_mutex ); _lwp_mutex_lock( &interlocked_mutex );

View File

@ -104,7 +104,7 @@ int __pthread_once(pthread_once_t *once_control, void (*init_routine)(void))
static pthread_once_t the_once = PTHREAD_ONCE_INIT; static pthread_once_t the_once = PTHREAD_ONCE_INIT;
LONG once_now = *(LONG *)&the_once; LONG once_now = *(LONG *)&the_once;
if (InterlockedCompareExchange((PVOID*)once_control, (PVOID)(once_now+1), (PVOID)once_now) == (PVOID)once_now) if (InterlockedCompareExchange((LONG*)once_control, once_now+1, once_now) == once_now)
(*init_routine)(); (*init_routine)();
return 0; return 0;
} }
@ -188,7 +188,7 @@ static void mutex_real_init( pthread_mutex_t *mutex )
CRITICAL_SECTION *critsect = HeapAlloc(GetProcessHeap(), 0, sizeof(CRITICAL_SECTION)); CRITICAL_SECTION *critsect = HeapAlloc(GetProcessHeap(), 0, sizeof(CRITICAL_SECTION));
InitializeCriticalSection(critsect); InitializeCriticalSection(critsect);
if (InterlockedCompareExchange((PVOID*)&(((wine_mutex)mutex)->critsect),critsect,NULL) != NULL) { if (InterlockedCompareExchangePointer((void**)&(((wine_mutex)mutex)->critsect),critsect,NULL) != NULL) {
/* too late, some other thread already did it */ /* too late, some other thread already did it */
DeleteCriticalSection(critsect); DeleteCriticalSection(critsect);
HeapFree(GetProcessHeap(), 0, critsect); HeapFree(GetProcessHeap(), 0, critsect);