Re: [PATCH]: 2. Thread safe stdio update

2004-02-06 Thread Christopher Faylor
On Fri, Jan 23, 2004 at 12:03:09PM +0100, Thomas Pfaff wrote:
>Corinna Vinschen wrote:
>>On Jan 22 21:48, Thomas Pfaff wrote:
>>
>>>This is an update of my previous patch. It adds support for newlibs 
>>>__LOCK_INIT macro.
>>>
>>>Thomas
>>>
>>>2004-01-22 Thomas Pfaff <[EMAIL PROTECTED]>
>>>
>>> * include/sys/_types.h: New file.
>>
>>
>>I'm not quite sure if that's the way to go.  I'm wondering if we
>>shouldn't keep newlib's _types.h and change it like this:
>>
>>  #ifdef __CYGWIN__
>>  #include 
>>  #endif
>>
>>  #ifndef __CYGWIN__
>>  typedef int _flock_t;
>>  #endif
>>
>>Then we can create a cygwin/_types.h with the correct _flock_t definition.
>>IMHO that's cleaner than just overloading newlib's _types.h.
>
>You may be right.
>
>I just followed the way it was done in newlibs linux support where a 
>modified _types.h is in newlib/libc/sys/linux/sys (and it was the 
>easiest way for me to test it).

Btw, I agree with Corinna's assessment here.  That's one reason why I
didn't just drop this into the release.  I'd like to minimize the amount
of header duplication we have between cygwin and newlib.  And, wholesale
duplication with just one small change is always a bad idea.

cgf


Re: [PATCH]: 2. Thread safe stdio update

2004-01-23 Thread Christopher Faylor
On Fri, Jan 23, 2004 at 12:14:32PM +0100, Corinna Vinschen wrote:
>I think you should RFA it on newlib and apply the rest of the patch
>when Jeff applied.  But I'd like to hear from Chris first, if that
>patch should go into 1.5.7 or if it should wait for a while.

I haven't looked at the patch in any great depth.  It's not going into
1.5.7.  I'll get to it eventually.

cgf


Re: [PATCH]: 2. Thread safe stdio update

2004-01-23 Thread Corinna Vinschen
On Jan 23 12:03, Thomas Pfaff wrote:
> Corinna Vinschen wrote:
> >On Jan 22 21:48, Thomas Pfaff wrote:
> >>2004-01-22 Thomas Pfaff <[EMAIL PROTECTED]>
> >>
> >>* include/sys/_types.h: New file.
> >
> >
> >I'm not quite sure if that's the way to go.  I'm wondering if we
> >shouldn't keep newlib's _types.h and change it like this:
> >
> >  #ifdef __CYGWIN__
> >  #include 
> >  #endif
> >
> >  #ifndef __CYGWIN__
> >  typedef int _flock_t;
> >  #endif
> >
> >Then we can create a cygwin/_types.h with the correct _flock_t definition.
> >IMHO that's cleaner than just overloading newlib's _types.h.
> >
> 
> You may be right.
> 
> I just followed the way it was done in newlibs linux support where a 
> modified _types.h is in newlib/libc/sys/linux/sys (and it was the 
> easiest way for me to test it).
> 
> Will you make this change in newlibs _types.h ?

I think you should RFA it on newlib and apply the rest of the patch
when Jeff applied.  But I'd like to hear from Chris first, if that
patch should go into 1.5.7 or if it should wait for a while.

Corinna

-- 
Corinna Vinschen  Please, send mails regarding Cygwin to
Cygwin Developermailto:[EMAIL PROTECTED]
Red Hat, Inc.


Re: [PATCH]: 2. Thread safe stdio update

2004-01-23 Thread Thomas Pfaff
Corinna Vinschen wrote:
On Jan 22 21:48, Thomas Pfaff wrote:

This is an update of my previous patch. It adds support for newlibs 
__LOCK_INIT macro.

Thomas

2004-01-22 Thomas Pfaff <[EMAIL PROTECTED]>

	* include/sys/_types.h: New file.


I'm not quite sure if that's the way to go.  I'm wondering if we
shouldn't keep newlib's _types.h and change it like this:
  #ifdef __CYGWIN__
  #include 
  #endif
  #ifndef __CYGWIN__
  typedef int _flock_t;
  #endif
Then we can create a cygwin/_types.h with the correct _flock_t definition.
IMHO that's cleaner than just overloading newlib's _types.h.
You may be right.

I just followed the way it was done in newlibs linux support where a 
modified _types.h is in newlib/libc/sys/linux/sys (and it was the 
easiest way for me to test it).

Will you make this change in newlibs _types.h ?

Thomas


Re: [PATCH]: 2. Thread safe stdio update

2004-01-23 Thread Corinna Vinschen
On Jan 22 21:48, Thomas Pfaff wrote:
> This is an update of my previous patch. It adds support for newlibs 
> __LOCK_INIT macro.
> 
> Thomas
> 
> 2004-01-22 Thomas Pfaff <[EMAIL PROTECTED]>
> 
>   * include/sys/_types.h: New file.

I'm not quite sure if that's the way to go.  I'm wondering if we
shouldn't keep newlib's _types.h and change it like this:

  #ifdef __CYGWIN__
  #include 
  #endif

  #ifndef __CYGWIN__
  typedef int _flock_t;
  #endif

Then we can create a cygwin/_types.h with the correct _flock_t definition.
IMHO that's cleaner than just overloading newlib's _types.h.

Corinna

-- 
Corinna Vinschen  Please, send mails regarding Cygwin to
Cygwin Developermailto:[EMAIL PROTECTED]
Red Hat, Inc.


[PATCH]: 2. Thread safe stdio update

2004-01-22 Thread Thomas Pfaff
This is an update of my previous patch. It adds support for newlibs 
__LOCK_INIT macro.

Thomas

2004-01-22 Thomas Pfaff <[EMAIL PROTECTED]>

* include/sys/_types.h: New file.
* include/sys/lock.h: Ditto.
* include/sys/stdio.h: Ditto.
* thread.cc: Include sys/lock.h
(__cygwin_lock_init): New function.
(__cygwin_lock_init_recursive): Ditto.
(__cygwin_lock_fini): Ditto.
(__cygwin_lock_lock): Ditto.
(__cygwin_lock_unlock): Ditto.
diff -urpN cygwin.org/include/sys/_types.h cygwin/include/sys/_types.h
--- cygwin.org/include/sys/_types.h 1970-01-01 01:00:00.0 +0100
+++ cygwin/include/sys/_types.h 2004-01-12 08:02:01.775041600 +0100
@@ -0,0 +1,37 @@
+/* ANSI C namespace clean utility typedefs */
+
+/* This file defines various typedefs needed by the system calls that support
+   the C library.  Basically, they're just the POSIX versions with an '_'
+   prepended.  This file lives in the `sys' directory so targets can provide
+   their own if desired (or they can put target dependant conditionals here).
+*/
+
+#ifndef_SYS__TYPES_H
+#define _SYS__TYPES_H
+
+typedef long _off_t;
+__extension__ typedef long long _off64_t;
+
+#if defined(__INT_MAX__) && __INT_MAX__ == 2147483647
+typedef int _ssize_t;
+#else
+typedef long _ssize_t;
+#endif
+
+#define __need_wint_t
+#include 
+
+/* Conversion state information.  */
+typedef struct
+{
+  int __count;
+  union
+  {
+wint_t __wch;
+unsigned char __wchb[4];
+  } __value;   /* Value so far.  */
+} _mbstate_t;
+
+typedef void *_flock_t;
+
+#endif /* _SYS__TYPES_H */
diff -urpN cygwin.org/include/sys/lock.h cygwin/include/sys/lock.h
--- cygwin.org/include/sys/lock.h   1970-01-01 01:00:00.0 +0100
+++ cygwin/include/sys/lock.h   2004-01-21 14:34:30.341939200 +0100
@@ -0,0 +1,36 @@
+/* sys/lock.h
+
+   Copyright 2004 Red Hat, Inc.
+
+This file is part of Cygwin.
+
+This software is a copyrighted work licensed under the terms of the
+Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
+details. */
+
+#ifndef _SYS_LOCK_H_
+#define _SYS_LOCK_H_
+
+typedef void *_LOCK_T;
+#define _LOCK_RECURSIVE_T _LOCK_T
+
+/*
+ * This must match cygwins PTHREAD_MUTEX_INITIALIZER which is
+ * defined in 
+ */
+#define _LOCK_T_INITIALIZER ((_LOCK_T)20)
+
+#define __LOCK_INIT(CLASS,NAME) \
+  CLASS _LOCK_T NAME = _LOCK_T_INITIALIZER; 
+
+#define __lock_init(__lock) __cygwin_lock_init(&__lock)
+#define __lock_close(__lock) __cygwin_lock_fini(&__lock)
+#define __lock_acquire(__lock) __cygwin_lock_lock(&__lock)
+#define __lock_release(__lock) __cygwin_lock_unlock(&__lock)
+
+#define __lock_init_recursive(__lock) __cygwin_lock_init_recursive(&__lock)
+#define __lock_close_recursive(__lock) __cygwin_lock_fini(&__lock)
+#define __lock_acquire_recursive(__lock) __cygwin_lock_lock(&__lock)
+#define __lock_release_recursive(__lock) __cygwin_lock_unlock(&__lock)
+
+#endif
diff -urpN cygwin.org/include/sys/stdio.h cygwin/include/sys/stdio.h
--- cygwin.org/include/sys/stdio.h  1970-01-01 01:00:00.0 +0100
+++ cygwin/include/sys/stdio.h  2004-01-21 14:34:03.493332800 +0100
@@ -0,0 +1,25 @@
+/* sys/stdio.h
+
+   Copyright 2004 Red Hat, Inc.
+
+This file is part of Cygwin.
+
+This software is a copyrighted work licensed under the terms of the
+Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
+details. */
+
+#ifndef _SYS_STDIO_H_
+#define _SYS_STDIO_H_
+
+#include 
+
+#if !defined(__SINGLE_THREAD__)
+#  if !defined(_flockfile)
+#define _flockfile(fp) __cygwin_lock_lock ((_LOCK_T *)&(fp)->_lock)
+#  endif
+#  if !defined(_funlockfile)
+#define _funlockfile(fp) __cygwin_lock_unlock ((_LOCK_T *)&(fp)->_lock)
+#  endif
+#endif
+ 
+#endif
diff -urpN cygwin.org/thread.cc cygwin/thread.cc
--- cygwin.org/thread.cc2004-01-19 09:37:50.0 +0100
+++ cygwin/thread.cc2004-01-22 13:49:27.961144000 +0100
@@ -44,6 +44,7 @@ details. */
 #include 
 #include 
 #include 
+#include 
 
 extern int threadsafe;
 
@@ -54,6 +55,39 @@ __getreent ()
   return &_my_tls.local_clib;
 }
 
+extern "C" void
+__cygwin_lock_init (_LOCK_T *lock)
+{
+  *lock = NULL;
+  pthread_mutex_init ((pthread_mutex_t*) lock, NULL);
+}
+
+extern "C" void
+__cygwin_lock_init_recursive (_LOCK_T *lock)
+{
+  *lock = NULL;
+  if (!pthread_mutex_init ((pthread_mutex_t*) lock, NULL))
+(*(pthread_mutex_t*)lock)->type = PTHREAD_MUTEX_RECURSIVE;
+}
+
+extern "C" void
+__cygwin_lock_fini (_LOCK_T *lock)
+{
+  pthread_mutex_destroy ((pthread_mutex_t*) lock);
+}
+
+extern "C" void
+__cygwin_lock_lock (_LOCK_T *lock)
+{
+  pthread_mutex_lock ((pthread_mutex_t*) lock);
+}
+
+extern "C" void
+__cygwin_lock_unlock (_LOCK_T *lock)
+{
+  pthread_mutex_unlock ((pthread_mutex_t*) lock);
+}
+
 inline LPCRITICAL_SECTION
 ResourceLocks::Lock (int _resid)
 {