This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Add BeOS support for libstdc++-v3
- To: gcc-patches at gcc dot gnu dot org, libstdc++ at gcc dot gnu dot org
- Subject: [PATCH] Add BeOS support for libstdc++-v3
- From: Daniel Berlin <dan at www dot cgsoftware dot com>
- Date: Tue, 21 Nov 2000 11:09:06 -0500 (EST)
This patch and new file add support for BeOS (including multithreaded
support) to libstdc++.
Unfortunately, the gen-num-limits patch is necessary, or else we go into
a 100% cpu loop due to some oddness in BeOS signal handling.
threads-beos.h goes in config.
I didn't include a regenerated configure in the patch.
--Dan
// thread support (beos case) -*- C++ -*-
// Copyright (C) 2000 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
// threads-beos.h - Defines for using beos threads.
#ifndef _CPP_THREADS_BEOS
#define _CPP_THREADS_BEOS
#include <bits/c++config.h>
//
// Includes
//
#include <bits/libc-lock.h>
//
// Defines
//
// Currently needed for stl/bits/stl_config.h
# define _BEOSTHREADS
// Currently libio expects this macro
#define _IO_MTSAFE_IO
// May be needed on solaris.
//#define PTHREAD_MUTEX_INITIALIZER {{{0},0},{{{0}}},{0}}
//
// Typedefs.
//
namespace std {
typedef __libc_sem_id __mutext_type;
} // std
//
// Condition variables.
//
//
// Mutexes.
//
//
// Thread creation and manipulation.
//
#endif // _CPP_THREADS_POSIX
? patches
? config/threads-beos.h
Index: acinclude.m4
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/acinclude.m4,v
retrieving revision 1.95
diff -c -3 -p -r1.95 acinclude.m4
*** acinclude.m4 2000/11/17 22:38:49 1.95
--- acinclude.m4 2000/11/18 15:31:42
*************** AC_DEFUN(GLIBCPP_ENABLE_THREADS, [
*** 1362,1369 ****
# default
target_thread_file='posix'
;;
! xdecosf1 | xirix | xmach | xos2 | xposix | xpthreads | xsingle | \
! xsolaris | xwin32 | xdce | xvxworks)
target_thread_file=$enable_threads_flag
;;
*)
--- 1362,1369 ----
# default
target_thread_file='posix'
;;
! xbeos | xdecosf1 | xirix | xmach | xos2 | xposix | xpthreads | \
! xsingle | xsolaris | xwin32 | xdce | xvxworks)
target_thread_file=$enable_threads_flag
;;
*)
*************** AC_DEFUN(GLIBCPP_ENABLE_THREADS, [
*** 1380,1385 ****
--- 1380,1388 ----
;;
posix | pthreads)
THREADH=threads-posix.h
+ ;;
+ beos )
+ THREADH=threads-beos.h
;;
decosf1 | irix | mach | os2 | solaris | win32 | dce | vxworks)
AC_MSG_ERROR(thread package $THREADS not yet supported)
Index: aclocal.m4
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/aclocal.m4,v
retrieving revision 1.96
diff -c -3 -p -r1.96 aclocal.m4
*** aclocal.m4 2000/11/17 22:38:49 1.96
--- aclocal.m4 2000/11/18 15:31:42
*************** AC_DEFUN(GLIBCPP_ENABLE_THREADS, [
*** 1374,1381 ****
# default
target_thread_file='posix'
;;
! xdecosf1 | xirix | xmach | xos2 | xposix | xpthreads | xsingle | \
! xsolaris | xwin32 | xdce | xvxworks)
target_thread_file=$enable_threads_flag
;;
*)
--- 1374,1381 ----
# default
target_thread_file='posix'
;;
! xbeos | xdecosf1 | xirix | xmach | xos2 | xposix | xpthreads | \
! xsingle | xsolaris | xwin32 | xdce | xvxworks)
target_thread_file=$enable_threads_flag
;;
*)
*************** AC_DEFUN(GLIBCPP_ENABLE_THREADS, [
*** 1392,1397 ****
--- 1392,1400 ----
;;
posix | pthreads)
THREADH=threads-posix.h
+ ;;
+ beos )
+ THREADH=threads-beos.h
;;
decosf1 | irix | mach | os2 | solaris | win32 | dce | vxworks)
AC_MSG_ERROR(thread package $THREADS not yet supported)
Index: configure.target
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/configure.target,v
retrieving revision 1.2
diff -c -3 -p -r1.2 configure.target
*** configure.target 2000/11/17 20:35:06 1.2
--- configure.target 2000/11/18 15:31:43
*************** case "${target_os}" in
*** 81,86 ****
--- 81,90 ----
aix*)
os_include_dir="config/os/aix"
;;
+ beos*)
+ enable_threads='beos'
+ os_include_dir="config/os/generic"
+ ;;
bsd* | freebsd*)
os_include_dir="config/os/bsd"
;;
*************** esac
*** 111,116 ****
--- 115,123 ----
case "${target}" in
*-*-aix*)
ATOMICITYH=$os_include_dir
+ ;;
+ *-*-beos*)
+ ATOMICITYH=$cpu_include_dir
;;
*-*-freebsd*)
ATOMICITYH=$cpu_include_dir
Index: mknumeric_limits
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/mknumeric_limits,v
retrieving revision 1.4
diff -c -3 -p -r1.4 mknumeric_limits
*** mknumeric_limits 2000/11/04 03:00:10 1.4
--- mknumeric_limits 2000/11/18 15:31:43
*************** case `uname` in
*** 21,26 ****
--- 21,28 ----
LDFLAGS='-nodefaultlibs -lgcc -lc' ;;
esac
;;
+ BeOS*)
+ LDFLAGS='-nodefaultlibs -lgcc -lroot' ;;
*)
LDFLAGS='-nodefaultlibs -lgcc -lc' ;;
esac
Index: include/bits/stl_config.h
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/include/bits/stl_config.h,v
retrieving revision 1.2
diff -c -3 -p -r1.2 stl_config.h
*** stl_config.h 2000/10/30 13:15:24 1.2
--- stl_config.h 2000/11/18 15:31:43
***************
*** 547,553 ****
#endif
#if defined(__STL_WIN32THREADS) || defined(__STL_SGI_THREADS) \
! || defined(__STL_PTHREADS) || defined(__STL_UITHREADS)
# define __STL_THREADS
# define __STL_VOLATILE volatile
#else
--- 547,554 ----
#endif
#if defined(__STL_WIN32THREADS) || defined(__STL_SGI_THREADS) \
! || defined(__STL_PTHREADS) || defined(__STL_UITHREADS) \
! || defined(__STL_BEOSTHREADS)
# define __STL_THREADS
# define __STL_VOLATILE volatile
#else
Index: include/bits/stl_threads.h
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/include/bits/stl_threads.h,v
retrieving revision 1.1
diff -c -3 -p -r1.1 stl_threads.h
*** stl_threads.h 2000/10/05 11:27:01 1.1
--- stl_threads.h 2000/11/18 15:31:43
***************
*** 34,39 ****
--- 34,41 ----
#include <synch.h>
#elif defined(__STL_WIN32THREADS)
#include <windows.h>
+ #elif defined(__STL_BEOSTHREADS)
+ #include <bits/libc-lock.h>
#endif
__STL_BEGIN_NAMESPACE
*************** struct _Refcount_Base
*** 56,61 ****
--- 58,65 ----
// The type _RC_t
# ifdef __STL_WIN32THREADS
typedef long _RC_t;
+ # elif __STL_BEOSTHREADS
+ typedef unsigned long _RC_t;
# else
typedef size_t _RC_t;
#endif
*************** struct _Refcount_Base
*** 107,112 ****
--- 111,124 ----
mutex_unlock(&_M_ref_count_lock);
return __tmp;
}
+ # elif defined(__STL_BEOSTHREADS)
+ void _M_incr() {
+ atomic_add(&_M_ref_count, 1);
+ }
+ _RC_t _M_decr() {
+ atomic_add(&_M_ref_count, -1);
+ return _M_ref_count;
+ }
# else /* No threads */
void _M_incr() { ++_M_ref_count; }
_RC_t _M_decr() { return --_M_ref_count; }
*************** struct _Refcount_Base
*** 129,134 ****
--- 141,159 ----
inline unsigned long _Atomic_swap(unsigned long * __p, unsigned long __q) {
return (unsigned long) InterlockedExchange((LPLONG)__p, (LONG)__q);
}
+ # elif defined(__STL_BEOSTHREADS)
+ inline unsigned long _Atomic_swap(unsigned long *p, unsigned long newval) {
+ {
+ unsigned long retval;
+ long int readval;
+ __asm__ ("lock");
+ retval = *p;
+
+ __asm__ __volatile__ ("lock; xchgl %3, %1; sete %0"
+ : "=q" (ret), "=m" (*p), "=a" (readval)
+ : "r" (newval), "m" (*p));
+ return retval;
+ }
# elif defined(__STL_PTHREADS)
// We use a template here only to get a unique initialized instance.
template<int __dummy>
*************** struct _STL_mutex_lock
*** 325,330 ****
--- 350,360 ----
void _M_initialize() { mutex_init(&_M_lock, USYNC_THREAD, 0); }
void _M_acquire_lock() { mutex_lock(&_M_lock); }
void _M_release_lock() { mutex_unlock(&_M_lock); }
+ #elif defined(__STL_BEOSTHREADS)
+ sem_id _M_lock;
+ void _M_initialize() { _M_lock = create_sem(1, "STL semaphore"); }
+ void _M_acquire_lock() { acquire_sem(_M_lock); }
+ void _M_release_lock() { release_sem(_M_lock); }
#else /* No threads */
void _M_initialize() {}
void _M_acquire_lock() {}
Index: libio/libioP.h
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/libio/libioP.h,v
retrieving revision 1.8
diff -c -3 -p -r1.8 libioP.h
*** libioP.h 2000/10/29 21:21:51 1.8
--- libioP.h 2000/11/18 15:31:43
***************
*** 30,35 ****
--- 30,37 ----
#endif
#if defined __GLIBC__ && __GLIBC__ >= 2
# include <bits/libc-lock.h>
+ #elif defined __BEOS__
+ # include <bits/libc-lock.h>
#else
/*# include <comthread.h>*/
#endif
Index: libmath/mathconf.h
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/libmath/mathconf.h,v
retrieving revision 1.1
diff -c -3 -p -r1.1 mathconf.h
*** mathconf.h 2000/10/07 01:01:45 1.1
--- mathconf.h 2000/11/18 15:31:43
*************** double nan (void);
*** 227,233 ****
extern "C" {
#endif
! #ifdef _GLIBCPP_HAVE_COMPLEX_H
# include <complex.h>
#else
# include "complex-stub.h"
--- 227,233 ----
extern "C" {
#endif
! #if defined(_GLIBCPP_HAVE_COMPLEX_H) && !defined(__BEOS__)
# include <complex.h>
#else
# include "complex-stub.h"
Index: src/gen-num-limits.cc
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/src/gen-num-limits.cc,v
retrieving revision 1.4
diff -c -3 -p -r1.4 gen-num-limits.cc
*** gen-num-limits.cc 2000/10/30 13:15:24 1.4
--- gen-num-limits.cc 2000/11/18 15:31:43
*************** template<typename T> struct underflow {}
*** 137,158 ****
// traps
template<typename T> void traps()
{
! signal(SIGFPE, signal_handler);
bool trap_flag = trapping(division_by_zero<T>());
signal(SIGFPE, signal_handler);
trap_flag = trap_flag && trapping(overflow<T>());
const char* p = bool_alpha[trap_flag];
printf("%s%s = %s;\n", tab2, "static const bool traps", p);
}
!
#define SPECIALIZE_TRAPPING(T) \
template<> void traps< T >() \
{ \
signal(SIGFPE, signal_handler); \
const char* p = bool_alpha[trapping(division_by_zero<T>())]; \
printf("%s%s = %s;\n", tab2, "static const bool traps", p); \
}
!
SPECIALIZE_TRAPPING(unsigned char);
SPECIALIZE_TRAPPING(unsigned short);
SPECIALIZE_TRAPPING(unsigned int);
--- 137,168 ----
// traps
template<typename T> void traps()
{
! #ifndef __BEOS__
! signal(SIGFPE, signal_handler);
bool trap_flag = trapping(division_by_zero<T>());
signal(SIGFPE, signal_handler);
trap_flag = trap_flag && trapping(overflow<T>());
const char* p = bool_alpha[trap_flag];
+ #else
+ const char *p = "false";
+ #endif
printf("%s%s = %s;\n", tab2, "static const bool traps", p);
}
! #ifndef __BEOS__
#define SPECIALIZE_TRAPPING(T) \
template<> void traps< T >() \
{ \
signal(SIGFPE, signal_handler); \
const char* p = bool_alpha[trapping(division_by_zero<T>())]; \
printf("%s%s = %s;\n", tab2, "static const bool traps", p); \
+ }
+ #else
+ #define SPECIALIZE_TRAPPING(T) \
+ template<> void traps< T >() \
+ { \
+ printf("%s%s = %s;\n", tab2, "static const bool traps", "false"); \
}
! #endif
SPECIALIZE_TRAPPING(unsigned char);
SPECIALIZE_TRAPPING(unsigned short);
SPECIALIZE_TRAPPING(unsigned int);