Mailing-List: contact cygwin-developers-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-developers-owner AT cygwin DOT com Delivered-To: mailing list cygwin-developers AT cygwin DOT com From: "Gary R. Van Sickle" To: Subject: RE: quandary with pthreads Date: Thu, 12 Dec 2002 01:37:37 -0600 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0000_01C2A17F.0D25E120" X-Priority: 3 (Normal) X-MSMail-Priority: Normal In-Reply-To: <20021212060316.GA10952@redhat.com> Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 This is a multi-part message in MIME format. ------=_NextPart_000_0000_01C2A17F.0D25E120 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Ok, attached is what I'd try if I was set up to try it. I've found that you pretty much always need the "volatile" after the __asm__, or the newer gccs want to optimize your assembly away, even if they should be able to tell that you've got side-effects. -- Gary R. Van Sickle Brewer. Patriot. > -----Original Message----- > From: cygwin-developers-owner AT cygwin DOT com > [mailto:cygwin-developers-owner AT cygwin DOT com]On Behalf Of Christopher > Faylor > Sent: Thursday, December 12, 2002 12:03 AM > To: cygwin-developers AT cygwin DOT com > Subject: Re: quandary with pthreads > > > On Wed, Dec 11, 2002 at 11:53:03PM -0600, Gary R. Van Sickle wrote: > >>I have created assembler versions for the Interlocked functions that > >>work fine unless they are made inline (see attachment). Maybe someone > >>with a better understanding of gcc inline assembler might have a look > >>at it). > > > >I may have the painfully-acquired honor of fitting that description. > >How were you trying to inline them? Essentially as-is? If so, I just > >may be able to help. > > The routines in question are in winbase.h. I took inspiration for most > of them from linux. > > cgf ------=_NextPart_000_0000_01C2A17F.0D25E120 Content-Type: application/octet-stream; name="winbase.h" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="winbase.h" #include_next "winbase.h"=0A= =0A= #ifdef EXPCGF=0A= #define DECLARE_TLS_STORAGE char **tls[4096] __attribute__ ((unused))=0A= #else=0A= #define DECLARE_TLS_STORAGE do {} while (0)=0A= #define _WINBASE2_H=0A= #endif=0A= =0A= #if defined(__INSIDE_CYGWIN__) && !defined (__NO_INTERLOCKED__)=0A= =0A= #ifndef __INTERLOCKED_DEFINED__=0A= #define __INTERLOCKED_DEFINED__=0A= =0A= #ifdef __cplusplus=0A= extern "C" {=0A= #endif=0A= =0A= extern __inline__ long ilockincr (long *m)=0A= {=0A= int __res;=0A= __asm__ volatile ("\n\=0A= movl $1,%0\n\=0A= lock xadd %0,(%1)\n\=0A= inc %0\n"=0A= : "=3Da" (__res), "=3Dq" (m)=0A= : "1" (m)=0A= : "memory" );=0A= return __res;=0A= }=0A= =0A= extern __inline__ long ilockdecr (long *m)=0A= {=0A= int __res;=0A= __asm__ volatile ("\n\=0A= movl $0xffffffff,%0\n\=0A= lock xadd %0,(%1)\n\=0A= dec %0\n"=0A= : "=3Da" (__res), "=3Dq" (m)=0A= : "1" (m)=0A= : "memory" );=0A= return __res;=0A= }=0A= =0A= extern __inline__ long ilockexch (long *t, long v)=0A= {=0A= int __res;=0A= __asm__ volatile ("\n\=0A= 1: lock cmpxchgl %3,(%1)\n\=0A= jne 1b\n"=0A= : "=3Da" (__res), "=3Dq" (t)=0A= : "1" (t), "q" (v), "0" (*t)=0A= : "memory" );=0A= return __res;=0A= }=0A= =0A= extern __inline__ long ilockcmpexch (long *t, long v, long c)=0A= {=0A= int __res;=0A= __asm__ volatile ("\n\=0A= lock cmpxchgl %3,(%1)\n"=0A= : "=3Da" (__res), "=3Dq" (t)=0A= : "1" (t), "q" (v), "0" (c)=0A= : "memory" );=0A= return __res;=0A= }=0A= =0A= #ifdef __cplusplus=0A= }=0A= #endif=0A= =0A= #undef InterlockedIncrement=0A= #define InterlockedIncrement ilockincr=0A= #undef InterlockedDecrement=0A= #define InterlockedDecrement ilockdecr=0A= #undef InterlockedExchange=0A= #define InterlockedExchange ilockexch=0A= #undef InterlockedCompareExchange=0A= #define InterlockedCompareExchange ilockcmpexch=0A= =0A= #endif /*__INTERLOCKED_DEFINED__*/=0A= =0A= #endif /*defined(__INSIDE_CYGWIN__) && !defined (__NO_INTERLOCKED__)*/=0A= =0A= #ifndef _WINBASE2_H=0A= #define _WINBASE2_H=0A= =0A= extern long tls_ix;=0A= extern char * volatile *__stackbase __asm__ ("%fs:4");=0A= =0A= extern __inline__ DWORD=0A= my_tlsalloc ()=0A= {=0A= DWORD n =3D ilockdecr (&tls_ix);=0A= __stackbase[tls_ix] =3D NULL;=0A= return n;=0A= }=0A= =0A= extern __inline__ BOOL=0A= my_tlssetvalue (DWORD ix, void *val)=0A= {=0A= __stackbase[ix] =3D (char *) val;=0A= return 1;=0A= }=0A= =0A= extern __inline__ void *=0A= my_tlsgetvalue (DWORD ix)=0A= {=0A= return __stackbase[ix];=0A= }=0A= =0A= extern __inline__ BOOL=0A= my_tlsfree (DWORD ix)=0A= {=0A= /* nothing for now */=0A= return 1;=0A= }=0A= =0A= #undef TlsAlloc=0A= #define TlsAlloc my_tlsalloc=0A= #undef TlsGetValue=0A= #define TlsGetValue my_tlsgetvalue=0A= #undef TlsSetValue=0A= #define TlsSetValue my_tlssetvalue=0A= #undef TlsFree=0A= #define TlsFree my_tlsfree=0A= #endif /*_WINBASE2_H*/=0A= ------=_NextPart_000_0000_01C2A17F.0D25E120--