2004-06-04 05:29:43 +08:00
|
|
|
/* winbase.h
|
|
|
|
|
2008-07-13 02:09:17 +08:00
|
|
|
Copyright 2002, 2003, 2004, 2008 Red Hat, Inc.
|
2004-06-04 05:29:43 +08: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 08:06:35 +08:00
|
|
|
#include_next "winbase.h"
|
|
|
|
|
|
|
|
#ifndef _WINBASE2_H
|
|
|
|
#define _WINBASE2_H
|
|
|
|
|
2002-12-14 13:06:59 +08:00
|
|
|
extern __inline__ long
|
2008-07-13 02:09:17 +08:00
|
|
|
ilockincr (volatile long *m)
|
2001-11-28 08:06:35 +08:00
|
|
|
{
|
|
|
|
register int __res;
|
|
|
|
__asm__ __volatile__ ("\n\
|
|
|
|
movl $1,%0\n\
|
2004-06-04 05:29:43 +08:00
|
|
|
lock xadd %0,%1\n\
|
2001-11-28 08:06:35 +08:00
|
|
|
inc %0\n\
|
2005-06-08 03:31:42 +08:00
|
|
|
": "=&r" (__res), "=m" (*m): "m" (*m): "cc");
|
2001-11-28 08:06:35 +08:00
|
|
|
return __res;
|
|
|
|
}
|
2002-12-14 13:06:59 +08:00
|
|
|
|
|
|
|
extern __inline__ long
|
2008-07-13 02:09:17 +08:00
|
|
|
ilockdecr (volatile long *m)
|
2001-11-28 08:06:35 +08:00
|
|
|
{
|
|
|
|
register int __res;
|
|
|
|
__asm__ __volatile__ ("\n\
|
|
|
|
movl $0xffffffff,%0\n\
|
2004-06-04 05:29:43 +08:00
|
|
|
lock xadd %0,%1\n\
|
2001-11-28 08:06:35 +08:00
|
|
|
dec %0\n\
|
2005-06-08 03:31:42 +08:00
|
|
|
": "=&r" (__res), "=m" (*m): "m" (*m): "cc");
|
2001-11-28 08:06:35 +08:00
|
|
|
return __res;
|
|
|
|
}
|
2002-12-14 13:06:59 +08:00
|
|
|
|
|
|
|
extern __inline__ long
|
2008-07-13 02:09:17 +08:00
|
|
|
ilockexch (volatile long *t, long v)
|
2001-11-28 08:06:35 +08:00
|
|
|
{
|
2009-06-05 21:53:01 +08:00
|
|
|
return
|
|
|
|
({
|
|
|
|
register __typeof (*t) ret __asm ("%eax");
|
|
|
|
__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 13:06:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
extern __inline__ long
|
2008-07-13 02:09:17 +08:00
|
|
|
ilockcmpexch (volatile long *t, long v, long c)
|
2002-12-14 13:06:59 +08:00
|
|
|
{
|
2009-06-05 21:53:01 +08:00
|
|
|
return
|
|
|
|
({
|
|
|
|
register __typeof (*t) ret __asm ("%eax");
|
|
|
|
__asm __volatile ("lock cmpxchgl %2, %1"
|
|
|
|
: "=a" (ret), "=m" (*t)
|
|
|
|
: "r" (v), "m" (*t), "0" (c)
|
|
|
|
: "memory");
|
|
|
|
ret;
|
|
|
|
});
|
2001-11-28 08:06:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#undef InterlockedIncrement
|
|
|
|
#define InterlockedIncrement ilockincr
|
|
|
|
#undef InterlockedDecrement
|
|
|
|
#define InterlockedDecrement ilockdecr
|
|
|
|
#undef InterlockedExchange
|
|
|
|
#define InterlockedExchange ilockexch
|
2002-12-14 13:06:59 +08:00
|
|
|
#undef InterlockedCompareExchange
|
|
|
|
#define InterlockedCompareExchange ilockcmpexch
|
2001-11-28 08:06:35 +08:00
|
|
|
#endif /*_WINBASE2_H*/
|