2004-06-03 23:29:43 +02:00
|
|
|
/* winbase.h
|
|
|
|
|
2012-06-03 18:32:00 +02:00
|
|
|
Copyright 2002, 2003, 2004, 2008, 2009, 2012 Red Hat, Inc.
|
2004-06-03 23:29:43 +02:00
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2001-11-28 01:06:35 +01:00
|
|
|
#include_next "winbase.h"
|
|
|
|
|
|
|
|
#ifndef _WINBASE2_H
|
|
|
|
#define _WINBASE2_H
|
|
|
|
|
2012-05-23 15:13:56 +02:00
|
|
|
/* For some unknown reason, InterlockedAdd is only supported on Itanium
|
|
|
|
when using the Windows headers. Fortunately we're not restricted to the
|
|
|
|
Windows headers :) */
|
2012-07-06 15:51:26 +02:00
|
|
|
extern __inline__ LONG
|
|
|
|
ilockadd (volatile LONG *m, LONG value)
|
2012-05-23 15:13:56 +02:00
|
|
|
{
|
2012-07-06 15:51:26 +02:00
|
|
|
register LONG __res;
|
2012-05-23 15:13:56 +02:00
|
|
|
__asm__ __volatile__ ("\n\
|
|
|
|
movl %3,%0\n\
|
|
|
|
lock xadd %0,%1\n\
|
|
|
|
addl %3,%0\n\
|
|
|
|
": "=&r" (__res), "=m" (*m): "m" (*m), "r" (value): "cc");
|
|
|
|
return __res;
|
|
|
|
}
|
|
|
|
|
2012-07-06 15:51:26 +02:00
|
|
|
extern __inline__ LONG
|
|
|
|
ilockincr (volatile LONG *m)
|
2001-11-28 01:06:35 +01:00
|
|
|
{
|
2012-07-06 15:51:26 +02:00
|
|
|
register LONG __res;
|
2001-11-28 01:06:35 +01:00
|
|
|
__asm__ __volatile__ ("\n\
|
|
|
|
movl $1,%0\n\
|
2004-06-03 23:29:43 +02:00
|
|
|
lock xadd %0,%1\n\
|
2001-11-28 01:06:35 +01:00
|
|
|
inc %0\n\
|
2005-06-07 21:31:42 +02:00
|
|
|
": "=&r" (__res), "=m" (*m): "m" (*m): "cc");
|
2001-11-28 01:06:35 +01:00
|
|
|
return __res;
|
|
|
|
}
|
2002-12-14 06:06:59 +01:00
|
|
|
|
2012-07-06 15:51:26 +02:00
|
|
|
extern __inline__ LONG
|
|
|
|
ilockdecr (volatile LONG *m)
|
2001-11-28 01:06:35 +01:00
|
|
|
{
|
2012-07-06 15:51:26 +02:00
|
|
|
register LONG __res;
|
2001-11-28 01:06:35 +01:00
|
|
|
__asm__ __volatile__ ("\n\
|
|
|
|
movl $0xffffffff,%0\n\
|
2004-06-03 23:29:43 +02:00
|
|
|
lock xadd %0,%1\n\
|
2001-11-28 01:06:35 +01:00
|
|
|
dec %0\n\
|
2005-06-07 21:31:42 +02:00
|
|
|
": "=&r" (__res), "=m" (*m): "m" (*m): "cc");
|
2001-11-28 01:06:35 +01:00
|
|
|
return __res;
|
|
|
|
}
|
2002-12-14 06:06:59 +01:00
|
|
|
|
2012-07-06 15:51:26 +02:00
|
|
|
extern __inline__ LONG
|
|
|
|
ilockexch (volatile LONG *t, long v)
|
2001-11-28 01:06:35 +01:00
|
|
|
{
|
2009-06-05 15:53:01 +02:00
|
|
|
return
|
|
|
|
({
|
2012-07-06 15:51:26 +02:00
|
|
|
register LONG ret __asm ("%eax");
|
2009-06-05 15:53:01 +02:00
|
|
|
__asm __volatile ("\n"
|
|
|
|
"1: lock cmpxchgl %2, %1\n"
|
|
|
|
" jne 1b\n"
|
|
|
|
: "=a" (ret), "=m" (*t)
|
|
|
|
: "r" (v), "m" (*t), "0" (*t)
|
|
|
|
: "memory");
|
|
|
|
ret;
|
|
|
|
});
|
2002-12-14 06:06:59 +01:00
|
|
|
}
|
|
|
|
|
2012-07-06 15:51:26 +02:00
|
|
|
extern __inline__ LONG
|
|
|
|
ilockcmpexch (volatile LONG *t, LONG v, LONG c)
|
2002-12-14 06:06:59 +01:00
|
|
|
{
|
2009-06-05 15:53:01 +02:00
|
|
|
return
|
|
|
|
({
|
2012-07-06 15:51:26 +02:00
|
|
|
register LONG ret __asm ("%eax");
|
2009-06-05 15:53:01 +02:00
|
|
|
__asm __volatile ("lock cmpxchgl %2, %1"
|
|
|
|
: "=a" (ret), "=m" (*t)
|
|
|
|
: "r" (v), "m" (*t), "0" (c)
|
|
|
|
: "memory");
|
|
|
|
ret;
|
|
|
|
});
|
2001-11-28 01:06:35 +01:00
|
|
|
}
|
|
|
|
|
2012-05-23 15:13:56 +02:00
|
|
|
#undef InterlockedAdd
|
|
|
|
#define InterlockedAdd ilockadd
|
2001-11-28 01:06:35 +01:00
|
|
|
#undef InterlockedIncrement
|
|
|
|
#define InterlockedIncrement ilockincr
|
|
|
|
#undef InterlockedDecrement
|
|
|
|
#define InterlockedDecrement ilockdecr
|
|
|
|
#undef InterlockedExchange
|
|
|
|
#define InterlockedExchange ilockexch
|
2002-12-14 06:06:59 +01:00
|
|
|
#undef InterlockedCompareExchange
|
|
|
|
#define InterlockedCompareExchange ilockcmpexch
|
2012-07-06 15:51:26 +02:00
|
|
|
#undef InterlockedCompareExchangePointer
|
|
|
|
#ifndef __x86_64
|
|
|
|
#define InterlockedCompareExchangePointer(d,e,c) \
|
|
|
|
(PVOID)InterlockedCompareExchange((LONG volatile *)(d),(LONG)(e),(LONG)(c))
|
|
|
|
#endif /* !__x86_64 */
|
2001-11-28 01:06:35 +01:00
|
|
|
#endif /*_WINBASE2_H*/
|