Initial commit

This commit is contained in:
Eagle517
2026-01-14 10:27:57 -06:00
commit c1576fee30
11290 changed files with 1552799 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
// Low-level functions for atomic operations: x86, x < 4 version -*- C++ -*-
// Copyright (C) 1999, 2000, 2001 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.
#ifndef _BITS_ATOMICITY_H
#define _BITS_ATOMICITY_H 1
typedef int _Atomic_word;
static inline _Atomic_word
__attribute__ ((__unused__))
__exchange_and_add (volatile _Atomic_word *__mem, int __val)
{
register _Atomic_word __result;
__asm__ __volatile__ ("lock; xaddl %0,%1"
: "=r" (__result), "+m" (*__mem)
: "0" (__val)
: "memory");
return __result;
}
static inline void
__attribute__ ((__unused__))
__atomic_add (volatile _Atomic_word* __mem, int __val)
{
__asm__ __volatile__ ("lock; addl %1,%0"
: "+m" (*__mem) : "ir" (__val) : "memory");
}
#endif /* atomicity.h */

View File

@@ -0,0 +1,114 @@
// Wrapper of C-language FILE struct -*- C++ -*-
// Copyright (C) 2000, 2001, 2002 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.
//
// ISO C++ 14882: 27.8 File-based streams
//
/** @file basic_file.h
* This is an internal header file, included by other library headers.
* You should not attempt to use it directly.
*/
#ifndef _CPP_BASIC_FILE
#define _CPP_BASIC_FILE 1
#pragma GCC system_header
#include <bits/c++config.h>
#include <ios>
namespace std
{
// Generic declaration.
template<typename _CharT>
class __basic_file;
// Specialization.
template<>
class __basic_file<char>
{
// Underlying data source/sink.
__c_file* _M_cfile;
// True iff we opened _M_cfile, and thus must close it ourselves.
bool _M_cfile_created;
public:
__basic_file(__c_lock* __lock = 0);
void
_M_open_mode(ios_base::openmode __mode, int& __p_mode, int& __rw_mode,
char* __c_mode);
__basic_file*
open(const char* __name, ios_base::openmode __mode, int __prot = 0664);
__basic_file*
sys_open(__c_file* __file, ios_base::openmode);
__basic_file*
sys_open(int __fd, ios_base::openmode __mode, bool __del);
int
sys_getc();
int
sys_ungetc(int);
__basic_file*
close();
bool
is_open() const;
int
fd();
~__basic_file();
streamsize
xsputn(const char* __s, streamsize __n);
streamsize
xsgetn(char* __s, streamsize __n);
streamoff
seekoff(streamoff __off, ios_base::seekdir __way,
ios_base::openmode __mode = ios_base::in | ios_base::out);
streamoff
seekpos(streamoff __pos,
ios_base::openmode __mode = ios_base::in | ios_base::out);
int
sync();
};
} // namespace std
#endif // _CPP_BASIC_FILE

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,93 @@
// underlying io library -*- C++ -*-
// Copyright (C) 2000, 2001, 2002 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.
// c_io_stdio.h - Defines for using "C" stdio.h
#ifndef _CPP_IO_STDIO_H
#define _CPP_IO_STDIO_H 1
#include <cstdio>
#include <cstddef>
#include <bits/gthr.h>
namespace std
{
// for fpos.h
typedef long streamoff;
typedef ptrdiff_t streamsize; // Signed integral type
#if _GLIBCPP_USE_WCHAR_T
typedef ptrdiff_t wstreamsize;
#endif
typedef fpos_t __c_streampos;
typedef __gthread_mutex_t __c_lock;
// for basic_file.h
typedef FILE __c_file;
// for ios_base.h
struct __ios_flags
{
typedef short __int_type;
static const __int_type _S_boolalpha = 0x0001;
static const __int_type _S_dec = 0x0002;
static const __int_type _S_fixed = 0x0004;
static const __int_type _S_hex = 0x0008;
static const __int_type _S_internal = 0x0010;
static const __int_type _S_left = 0x0020;
static const __int_type _S_oct = 0x0040;
static const __int_type _S_right = 0x0080;
static const __int_type _S_scientific = 0x0100;
static const __int_type _S_showbase = 0x0200;
static const __int_type _S_showpoint = 0x0400;
static const __int_type _S_showpos = 0x0800;
static const __int_type _S_skipws = 0x1000;
static const __int_type _S_unitbuf = 0x2000;
static const __int_type _S_uppercase = 0x4000;
static const __int_type _S_adjustfield = 0x0020 | 0x0080 | 0x0010;
static const __int_type _S_basefield = 0x0002 | 0x0040 | 0x0008;
static const __int_type _S_floatfield = 0x0100 | 0x0004;
// 27.4.2.1.3 Type ios_base::iostate
static const __int_type _S_badbit = 0x01;
static const __int_type _S_eofbit = 0x02;
static const __int_type _S_failbit = 0x04;
// 27.4.2.1.4 Type openmode
static const __int_type _S_app = 0x01;
static const __int_type _S_ate = 0x02;
static const __int_type _S_bin = 0x04;
static const __int_type _S_in = 0x08;
static const __int_type _S_out = 0x10;
static const __int_type _S_trunc = 0x20;
};
}
#endif // _CPP_IO_STDIO_H

View File

@@ -0,0 +1,71 @@
// Wrapper for underlying C-language localization -*- C++ -*-
// Copyright (C) 2001, 2002 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.
//
// ISO C++ 14882: 22.8 Standard locale categories.
//
// Written by Benjamin Kosnik <bkoz@redhat.com>
#include <clocale>
#define _GLIBCPP_NUM_CATEGORIES 0
namespace std
{
typedef int* __c_locale;
template<typename _Tv>
int
__convert_from_v(char* __out, const int __size, const char* __fmt,
_Tv __v, const __c_locale&, int __prec = -1)
{
char* __old = setlocale(LC_ALL, NULL);
char* __sav = static_cast<char*>(malloc(strlen(__old) + 1));
if (__sav)
strcpy(__sav, __old);
setlocale(LC_ALL, "C");
int __ret;
#ifdef _GLIBCPP_USE_C99
if (__prec >= 0)
__ret = snprintf(__out, __size, __fmt, __prec, __v);
else
__ret = snprintf(__out, __size, __fmt, __v);
#else
if (__prec >= 0)
__ret = sprintf(__out, __fmt, __prec, __v);
else
__ret = sprintf(__out, __fmt, __v);
#endif
setlocale(LC_ALL, __sav);
free(__sav);
return __ret;
}
}

View File

@@ -0,0 +1,38 @@
// Locale support (codecvt) -*- C++ -*-
// Copyright (C) 2000, 2001 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.
//
// ISO C++ 14882: 22.2.1.5 Template class codecvt
//
// Warning: this file is not meant for user inclusion. Use <locale>.
// Written by Benjamin Kosnik <bkoz@cygnus.com>
// XXX dummy file

View File

@@ -0,0 +1,198 @@
// Copyright (C) 2001 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.
#ifndef _GLIBCPP_CPU_LIMITS
#define _GLIBCPP_CPU_LIMITS 1
#define __glibcpp_long_double_bits 80
// These constants are selected to be consistent with native
// (msvcrt.dll) representation of NaNs
#define __FLOAT_INF_REP { 0, 0x7f80 }
#define __FLOAT_QNAN_REP { 0, 0xffc0 } // { 0, 0x7fc0 }
#define __FLOAT_SNAN_REP { 0, 0xff80 } // { 1, 0x7f80 }
#define __FLOAT_DENORM_REP {1,0}
#define __DOUBLE_INF_REP { 0, 0, 0, 0x7ff0 }
#define __DOUBLE_QNAN_REP { 0, 0, 0, 0xfff8 } // { 0, 0, 0, 0x7ff8 }
#define __DOUBLE_SNAN_REP { 0, 0, 0, 0xfff0 } // { 1, 0, 0, 0x7ff0 }
#define __DOUBLE_DENORM_REP {1, 0, 0, 0 }
/* This assumes no implicit (hidden) bit in extended mode */
#define __LONG_DOUBLE_INF_REP { 0, 0, 0, 0x8000, 0x7fff, 0 }
#define __LONG_DOUBLE_QNAN_REP { 0, 0, 0, 0xc000, 0xffff, 0 }
#define __LONG_DOUBLE_SNAN_REP { 0, 0, 0, 0x8000, 0xffff, 0 }
#define __LONG_DOUBLE_DENORM_REP {1, 0, 0, 0, 0, 0 }
template <class __dummy>
class _iec559_consts
{
public:
union _rep
{
unsigned short word[6];
float float_val;
double double_val;
long double ldouble_val;
} ;
static const union _rep _S_QNaNF;
static const union _rep _S_SNaNF;
static const union _rep _S_InfF;
static const union _rep _S_DenormF;
static const union _rep _S_QNaN;
static const union _rep _S_SNaN;
static const union _rep _S_Inf;
static const union _rep _S_Denorm;
static const union _rep _S_QNaNL;
static const union _rep _S_SNaNL;
static const union _rep _S_InfL;
static const union _rep _S_DenormL;
};
// Static const initialization
// float
template <class __dummy>
const typename _iec559_consts<__dummy>::_rep
_iec559_consts<__dummy>::_S_QNaNF = { __FLOAT_QNAN_REP };
template <class __dummy>
const typename _iec559_consts<__dummy>::_rep
_iec559_consts<__dummy>::_S_SNaNF = { __FLOAT_SNAN_REP };
template <class __dummy>
const typename _iec559_consts<__dummy>::_rep
_iec559_consts<__dummy>::_S_InfF = { __FLOAT_INF_REP };
template <class __dummy>
const typename _iec559_consts<__dummy>::_rep
_iec559_consts<__dummy>::_S_DenormF = { __FLOAT_DENORM_REP };
// double
template <class __dummy>
const typename _iec559_consts<__dummy>::_rep
_iec559_consts<__dummy>::_S_QNaN = { __DOUBLE_QNAN_REP };
template <class __dummy>
const typename _iec559_consts<__dummy>::_rep
_iec559_consts<__dummy>::_S_SNaN = { __DOUBLE_SNAN_REP };
template <class __dummy>
const typename _iec559_consts<__dummy>::_rep
_iec559_consts<__dummy>::_S_Inf = { __DOUBLE_INF_REP };
template <class __dummy>
const typename _iec559_consts<__dummy>::_rep
_iec559_consts<__dummy>::_S_Denorm = { __DOUBLE_DENORM_REP };
// long double
template <class __dummy>
const typename _iec559_consts<__dummy>::_rep
_iec559_consts<__dummy>::_S_QNaNL = { __LONG_DOUBLE_QNAN_REP };
template <class __dummy>
const typename _iec559_consts<__dummy>::_rep
_iec559_consts<__dummy>::_S_SNaNL = { __LONG_DOUBLE_SNAN_REP };
template <class __dummy>
const typename _iec559_consts<__dummy>::_rep
_iec559_consts<__dummy>::_S_InfL = { __LONG_DOUBLE_INF_REP };
template <class __dummy>
const typename _iec559_consts<__dummy>::_rep
_iec559_consts<__dummy>::_S_DenormL = { __LONG_DOUBLE_DENORM_REP };
// float
#define __glibcpp_float_has_infinity true
#define __glibcpp_float_has_quiet_NaN true
#define __glibcpp_float_has_signaling_NaN true
#define __glibcpp_float_has_denorm denorm_present
#define __glibcpp_float_has_denorm_loss true
#define __glibcpp_float_infinity \
_iec559_consts<bool>::_S_InfF.float_val
#define __glibcpp_float_quiet_NaN \
_iec559_consts<bool>::_S_QNaNF.float_val
#define __glibcpp_float_signaling_NaN \
_iec559_consts<bool>::_S_SNaNF.float_val
#define __glibcpp_float_denorm_min \
_iec559_consts<bool>::_S_DenormF.float_val
#define __glibcpp_float_is_iec559 true
#define __glibcpp_float_is_bounded true
#define __glibcpp_float_is_modulo false
#define __glibcpp_float_traps true
#define __glibcpp_float_tinyness_before true
#define __glibcpp_float_round_style round_to_nearest
// double
#define __glibcpp_double_has_infinity true
#define __glibcpp_double_has_quiet_NaN true
#define __glibcpp_double_has_signaling_NaN true
#define __glibcpp_double_has_denorm denorm_present
#define __glibcpp_double_has_denorm_loss true
#define __glibcpp_double_infinity \
_iec559_consts<bool>::_S_Inf.double_val
#define __glibcpp_double_quiet_NaN \
_iec559_consts<bool>::_S_QNaN.double_val
#define __glibcpp_double_signaling_NaN \
_iec559_consts<bool>::_S_SNaN.double_val
#define __glibcpp_double_denorm_min \
_iec559_consts<bool>::_S_Denorm.double_val
#define __glibcpp_double_is_iec559 true
#define __glibcpp_double_is_bounded true
#define __glibcpp_double_is_modulo false
#define __glibcpp_double_traps true
#define __glibcpp_double_tinyness_before true
#define __glibcpp_double_round_style round_to_nearest
// long double
#define __glibcpp_long_double_has_infinity true
#define __glibcpp_long_double_has_quiet_NaN true
#define __glibcpp_long_double_has_signaling_NaN true
#define __glibcpp_long_double_has_denorm denorm_present
#define __glibcpp_long_double_has_denorm_loss true
#define __glibcpp_long_double_infinity \
_iec559_consts<bool>::_S_InfL.ldouble_val
#define __glibcpp_long_double_quiet_NaN \
_iec559_consts<bool>::_S_QNaNL.ldouble_val
#define __glibcpp_long_double_signaling_NaN \
_iec559_consts<bool>::_S_SNaNL.ldouble_val
#define __glibcpp_long_double_denorm_min \
_iec559_consts<bool>::_S_DenormL.ldouble_val
#define __glibcpp_long_double_is_iec559 true
#define __glibcpp_long_double_is_bounded true
#define __glibcpp_long_double_is_modulo false
#define __glibcpp_long_double_traps true
#define __glibcpp_long_double_tinyness_before true
#define __glibcpp_long_double_round_style round_to_nearest
#endif

View File

@@ -0,0 +1,58 @@
// Locale support -*- C++ -*-
// Copyright (C) 1997, 1998, 1999 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.
//
// ISO C++ 14882: 22.1 Locales
//
// Information, as gleaned from /mingw32/include/ctype.h.
struct ctype_base
{
// Non-standard typedefs.
typedef const int* __to_type;
// NB: Offsets into ctype<char>::_M_table force a particular size
// on the mask type. Because of this, we don't use an enum.
typedef unsigned short mask;
static const mask upper = _UPPER;
static const mask lower = _LOWER;
static const mask alpha = _ALPHA;
static const mask digit = _DIGIT;
static const mask xdigit = _HEX;
static const mask space = _SPACE;
static const mask print = (_BLANK | _PUNCT| _ALPHA | _DIGIT);
static const mask graph = (_PUNCT | _ALPHA | _DIGIT);
static const mask cntrl = _CONTROL;
static const mask punct = _PUNCT;
static const mask alnum = (_ALPHA | _DIGIT);
};

View File

@@ -0,0 +1,71 @@
// Locale support -*- 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.
//
// ISO C++ 14882: 22.1 Locales
//
// ctype bits to be inlined go here. Non-inlinable (ie virtual do_*)
// functions go in ctype.cc
bool
ctype<char>::
is(mask __m, char __c) const
{
return (_M_table[static_cast<unsigned char>(__c) ] & __m);
}
const char*
ctype<char>::
is(const char* __low, const char* __high, mask* __vec) const
{
while (__low < __high)
*__vec++ = _M_table[static_cast<unsigned char>(*__low++)];
return __high;
}
const char*
ctype<char>::
scan_is(mask __m, const char* __low, const char* __high) const
{
while (__low < __high && !this->is(__m, *__low))
++__low;
return __low;
}
const char*
ctype<char>::
scan_not(mask __m, const char* __low, const char* __high) const
{
while (__low < __high && this->is(__m, *__low) != 0)
++__low;
return __low;
}

View File

@@ -0,0 +1,89 @@
// Locale support -*- C++ -*-
// Copyright (C) 1997, 1998, 1999, 2000, 2002 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.
//
// ISO C++ 14882: 22.1 Locales
//
// Information as gleaned from /mingw32/include/ctype.h.
// This should be in mingw's ctype.h but isn't in older versions
// Static classic C-locale table. _ctype[0] is EOF
extern "C" unsigned short __declspec(dllimport) _ctype[];
const ctype_base::mask*
ctype<char>::classic_table() throw()
{ return _ctype + 1; }
ctype<char>::ctype(__c_locale, const mask* __table, bool __del,
size_t __refs)
: __ctype_abstract_base<char>(__refs), _M_del(__table != 0 && __del),
_M_toupper(NULL), _M_tolower(NULL),
_M_table(__table ? __table : classic_table())
{ }
ctype<char>::ctype(const mask* __table, bool __del, size_t __refs)
: __ctype_abstract_base<char>(__refs), _M_del(__table != 0 && __del),
_M_toupper(NULL), _M_tolower(NULL),
_M_table(__table ? __table : classic_table())
{ }
char
ctype<char>::do_toupper(char __c) const
{ return (this->is(ctype_base::lower, __c) ? (__c - 'a' + 'A') : __c); }
const char*
ctype<char>::do_toupper(char* __low, const char* __high) const
{
while (__low < __high)
{
*__low = this->do_toupper(*__low);
++__low;
}
return __high;
}
char
ctype<char>::do_tolower(char __c) const
{ return (this->is(ctype_base::upper, __c) ? (__c - 'A' + 'a') : __c); }
const char*
ctype<char>::do_tolower(char* __low, const char* __high) const
{
while (__low < __high)
{
*__low = this->do_tolower(*__low);
++__low;
}
return __high;
}

View File

@@ -0,0 +1,611 @@
/* Threads compatibility routines for libgcc2 and libobjc. */
/* Compile this one with gcc. */
/* Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.
Contributed by Mumit Khan <khan@xraylith.wisc.edu>.
This file is part of GCC.
GCC 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.
GCC 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 GCC; 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, if you link this library with other files,
some of which are compiled with GCC, to produce an executable,
this library 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. */
#ifndef GCC_GTHR_WIN32_H
#define GCC_GTHR_WIN32_H
/* Windows32 threads specific definitions. The windows32 threading model
does not map well into pthread-inspired gcc's threading model, and so
there are caveats one needs to be aware of.
1. The destructor supplied to __gthread_key_create is ignored for
generic x86-win32 ports. This will certainly cause memory leaks
due to unreclaimed eh contexts (sizeof (eh_context) is at least
24 bytes for x86 currently).
This memory leak may be significant for long-running applications
that make heavy use of C++ EH.
However, Mingw runtime (version 0.3 or newer) provides a mechanism
to emulate pthreads key dtors; the runtime provides a special DLL,
linked in if -mthreads option is specified, that runs the dtors in
the reverse order of registration when each thread exits. If
-mthreads option is not given, a stub is linked in instead of the
DLL, which results in memory leak. Other x86-win32 ports can use
the same technique of course to avoid the leak.
2. The error codes returned are non-POSIX like, and cast into ints.
This may cause incorrect error return due to truncation values on
hw where sizeof (DWORD) > sizeof (int).
3. We might consider using Critical Sections instead of Windows32
mutexes for better performance, but emulating __gthread_mutex_trylock
interface becomes more complicated (Win9x does not support
TryEnterCriticalSectioni, while NT does).
The basic framework should work well enough. In the long term, GCC
needs to use Structured Exception Handling on Windows32. */
#define __GTHREADS 1
#include <errno.h>
#ifdef __MINGW32__
#include <_mingw.h>
#endif
#ifdef _LIBOBJC
/* This is necessary to prevent windef.h (included from windows.h) from
defining it's own BOOL as a typedef. */
#ifndef __OBJC__
#define __OBJC__
#endif
#include <windows.h>
/* Now undef the windows BOOL. */
#undef BOOL
/* Key structure for maintaining thread specific storage */
static DWORD __gthread_objc_data_tls = (DWORD)-1;
/* Backend initialization functions */
/* Initialize the threads subsystem. */
int
__gthread_objc_init_thread_system(void)
{
/* Initialize the thread storage key */
if ((__gthread_objc_data_tls = TlsAlloc()) != (DWORD)-1)
return 0;
else
return -1;
}
/* Close the threads subsystem. */
int
__gthread_objc_close_thread_system(void)
{
if (__gthread_objc_data_tls != (DWORD)-1)
TlsFree(__gthread_objc_data_tls);
return 0;
}
/* Backend thread functions */
/* Create a new thread of execution. */
objc_thread_t
__gthread_objc_thread_detach(void (*func)(void *arg), void *arg)
{
DWORD thread_id = 0;
HANDLE win32_handle;
if (!(win32_handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)func,
arg, 0, &thread_id)))
thread_id = 0;
return (objc_thread_t)thread_id;
}
/* Set the current thread's priority. */
int
__gthread_objc_thread_set_priority(int priority)
{
int sys_priority = 0;
switch (priority)
{
case OBJC_THREAD_INTERACTIVE_PRIORITY:
sys_priority = THREAD_PRIORITY_NORMAL;
break;
default:
case OBJC_THREAD_BACKGROUND_PRIORITY:
sys_priority = THREAD_PRIORITY_BELOW_NORMAL;
break;
case OBJC_THREAD_LOW_PRIORITY:
sys_priority = THREAD_PRIORITY_LOWEST;
break;
}
/* Change priority */
if (SetThreadPriority(GetCurrentThread(), sys_priority))
return 0;
else
return -1;
}
/* Return the current thread's priority. */
int
__gthread_objc_thread_get_priority(void)
{
int sys_priority;
sys_priority = GetThreadPriority(GetCurrentThread());
switch (sys_priority)
{
case THREAD_PRIORITY_HIGHEST:
case THREAD_PRIORITY_TIME_CRITICAL:
case THREAD_PRIORITY_ABOVE_NORMAL:
case THREAD_PRIORITY_NORMAL:
return OBJC_THREAD_INTERACTIVE_PRIORITY;
default:
case THREAD_PRIORITY_BELOW_NORMAL:
return OBJC_THREAD_BACKGROUND_PRIORITY;
case THREAD_PRIORITY_IDLE:
case THREAD_PRIORITY_LOWEST:
return OBJC_THREAD_LOW_PRIORITY;
}
/* Couldn't get priority. */
return -1;
}
/* Yield our process time to another thread. */
void
__gthread_objc_thread_yield(void)
{
Sleep(0);
}
/* Terminate the current thread. */
int
__gthread_objc_thread_exit(void)
{
/* exit the thread */
ExitThread(__objc_thread_exit_status);
/* Failed if we reached here */
return -1;
}
/* Returns an integer value which uniquely describes a thread. */
objc_thread_t
__gthread_objc_thread_id(void)
{
return (objc_thread_t)GetCurrentThreadId();
}
/* Sets the thread's local storage pointer. */
int
__gthread_objc_thread_set_data(void *value)
{
if (TlsSetValue(__gthread_objc_data_tls, value))
return 0;
else
return -1;
}
/* Returns the thread's local storage pointer. */
void *
__gthread_objc_thread_get_data(void)
{
DWORD lasterror;
void *ptr;
lasterror = GetLastError();
ptr = TlsGetValue(__gthread_objc_data_tls); /* Return thread data. */
SetLastError( lasterror );
return ptr;
}
/* Backend mutex functions */
/* Allocate a mutex. */
int
__gthread_objc_mutex_allocate(objc_mutex_t mutex)
{
if ((mutex->backend = (void *)CreateMutex(NULL, 0, NULL)) == NULL)
return -1;
else
return 0;
}
/* Deallocate a mutex. */
int
__gthread_objc_mutex_deallocate(objc_mutex_t mutex)
{
CloseHandle((HANDLE)(mutex->backend));
return 0;
}
/* Grab a lock on a mutex. */
int
__gthread_objc_mutex_lock(objc_mutex_t mutex)
{
int status;
status = WaitForSingleObject((HANDLE)(mutex->backend), INFINITE);
if (status != WAIT_OBJECT_0 && status != WAIT_ABANDONED)
return -1;
else
return 0;
}
/* Try to grab a lock on a mutex. */
int
__gthread_objc_mutex_trylock(objc_mutex_t mutex)
{
int status;
status = WaitForSingleObject((HANDLE)(mutex->backend), 0);
if (status != WAIT_OBJECT_0 && status != WAIT_ABANDONED)
return -1;
else
return 0;
}
/* Unlock the mutex */
int
__gthread_objc_mutex_unlock(objc_mutex_t mutex)
{
if (ReleaseMutex((HANDLE)(mutex->backend)) == 0)
return -1;
else
return 0;
}
/* Backend condition mutex functions */
/* Allocate a condition. */
int
__gthread_objc_condition_allocate(objc_condition_t condition)
{
/* Unimplemented. */
return -1;
}
/* Deallocate a condition. */
int
__gthread_objc_condition_deallocate(objc_condition_t condition)
{
/* Unimplemented. */
return -1;
}
/* Wait on the condition */
int
__gthread_objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex)
{
/* Unimplemented. */
return -1;
}
/* Wake up all threads waiting on this condition. */
int
__gthread_objc_condition_broadcast(objc_condition_t condition)
{
/* Unimplemented. */
return -1;
}
/* Wake up one thread waiting on this condition. */
int
__gthread_objc_condition_signal(objc_condition_t condition)
{
/* Unimplemented. */
return -1;
}
#else /* _LIBOBJC */
#ifdef __cplusplus
extern "C" {
#endif
typedef unsigned long __gthread_key_t;
typedef struct {
int done;
long started;
} __gthread_once_t;
typedef void* __gthread_mutex_t;
#define __GTHREAD_ONCE_INIT {0, -1}
#define __GTHREAD_MUTEX_INIT_FUNCTION __gthread_mutex_init_function
#define __GTHREAD_MUTEX_INIT_DEFAULT 0
#if __MINGW32_MAJOR_VERSION >= 1 || \
(__MINGW32_MAJOR_VERSION == 0 && __MINGW32_MINOR_VERSION > 2)
#define MINGW32_SUPPORTS_MT_EH 1
/* Mingw runtime >= v0.3 provides a magic variable that is set to non-zero
if -mthreads option was specified, or 0 otherwise. This is to get around
the lack of weak symbols in PE-COFF. */
extern int _CRT_MT;
extern int __mingwthr_key_dtor (unsigned long, void (*) (void *));
#endif /* __MINGW32__ version */
static inline int
__gthread_active_p (void)
{
#ifdef MINGW32_SUPPORTS_MT_EH
return _CRT_MT;
#else
return 1;
#endif
}
#ifdef __GTHREAD_HIDE_WIN32API
/* The implementations are in config/i386/gthr-win32.c in libgcc.a.
Only stubs are exposed to avoid polluting the C++ namespace with
windows api definitions. */
extern int __gthr_win32_once (__gthread_once_t *, void (*) (void));
extern int __gthr_win32_key_create (__gthread_key_t *, void (*) (void*));
extern int __gthr_win32_key_delete (__gthread_key_t);
extern void * __gthr_win32_getspecific (__gthread_key_t);
extern int __gthr_win32_setspecific (__gthread_key_t, const void *);
extern void __gthr_win32_mutex_init_function (__gthread_mutex_t *);
extern int __gthr_win32_mutex_lock (__gthread_mutex_t *);
extern int __gthr_win32_mutex_trylock (__gthread_mutex_t *);
extern int __gthr_win32_mutex_unlock (__gthread_mutex_t *);
static inline int
__gthread_once (__gthread_once_t *once, void (*func) (void))
{
if ( __gthread_active_p ())
return __gthr_win32_once (once, func);
else
return -1;
}
static inline int
__gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
{
return __gthr_win32_key_create (key, dtor);
}
static inline int
__gthread_key_dtor (__gthread_key_t key, void *ptr)
{
/* Just reset the key value to zero. */
if (ptr)
return __gthr_win32_setspecific(key, 0);
else
return 0; /* Nothing needed. */
}
static inline int
__gthread_key_delete (__gthread_key_t key)
{
return __gthr_win32_key_delete (key);
}
static inline void *
__gthread_getspecific (__gthread_key_t key)
{
return __gthr_win32_getspecific (key);
}
static inline int
__gthread_setspecific (__gthread_key_t key, const void *ptr)
{
return __gthr_win32_setspecific (key, ptr);
}
static inline void
__gthread_mutex_init_function (__gthread_mutex_t *mutex)
{
__gthr_win32_mutex_init_function (mutex);
}
static inline int
__gthread_mutex_lock (__gthread_mutex_t *mutex)
{
if (__gthread_active_p ())
return __gthr_win32_mutex_lock (mutex);
else
return 0;
}
static inline int
__gthread_mutex_trylock (__gthread_mutex_t *mutex)
{
if (__gthread_active_p ())
return __gthr_win32_mutex_trylock (mutex);
else
return 0;
}
static inline int
__gthread_mutex_unlock (__gthread_mutex_t *mutex)
{
if (__gthread_active_p ())
return __gthr_win32_mutex_unlock (mutex);
else
return 0;
}
#else /* ! __GTHREAD_HIDE_WIN32API */
#include <windows.h>
#include <errno.h>
static inline int
__gthread_once (__gthread_once_t *once, void (*func) (void))
{
if (! __gthread_active_p ())
return -1;
else if (once == NULL || func == NULL)
return EINVAL;
if (! once->done)
{
if (InterlockedIncrement (&(once->started)) == 0)
{
(*func) ();
once->done = TRUE;
}
else
{
/* Another thread is currently executing the code, so wait for it
to finish; yield the CPU in the meantime. If performance
does become an issue, the solution is to use an Event that
we wait on here (and set above), but that implies a place to
create the event before this routine is called. */
while (! once->done)
Sleep (0);
}
}
return 0;
}
/* Windows32 thread local keys don't support destructors; this leads to
leaks, especially in threaded applications making extensive use of
C++ EH. Mingw uses a thread-support DLL to work-around this problem. */
static inline int
__gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
{
int status = 0;
DWORD tls_index = TlsAlloc ();
if (tls_index != 0xFFFFFFFF)
{
*key = tls_index;
#ifdef MINGW32_SUPPORTS_MT_EH
/* Mingw runtime will run the dtors in reverse order for each thread
when the thread exits. */
status = __mingwthr_key_dtor (*key, dtor);
#endif
}
else
status = (int) GetLastError ();
return status;
}
static inline int
__gthread_setspecific (__gthread_key_t key, const void *ptr)
{
return (TlsSetValue (key, (void*) ptr) != 0) ? 0 : (int) GetLastError ();
}
/* Currently, this routine is called only for Mingw runtime, and if
-mthreads option is chosen to link in the thread support DLL. */
static inline int
__gthread_key_dtor (__gthread_key_t key, void *ptr)
{
/* Just reset the key value to zero. */
if (ptr)
return __gthread_setspecific(key, 0);
else
return 0; /* Nothing needed. */
return 0;
}
static inline int
__gthread_key_delete (__gthread_key_t key)
{
return (TlsFree (key) != 0) ? 0 : (int) GetLastError ();
}
static inline void *
__gthread_getspecific (__gthread_key_t key)
{
DWORD lasterror;
void *ptr;
lasterror = GetLastError();
ptr = TlsGetValue(key);
SetLastError( lasterror );
return ptr;
}
static inline void
__gthread_mutex_init_function (__gthread_mutex_t *mutex)
{
/* Create unnamed mutex with default security attr and no initial owner. */
*mutex = CreateMutex (NULL, 0, NULL);
}
static inline int
__gthread_mutex_lock (__gthread_mutex_t *mutex)
{
int status = 0;
if (__gthread_active_p ())
{
if (WaitForSingleObject (*mutex, INFINITE) == WAIT_OBJECT_0)
status = 0;
else
status = 1;
}
return status;
}
static inline int
__gthread_mutex_trylock (__gthread_mutex_t *mutex)
{
int status = 0;
if (__gthread_active_p ())
{
if (WaitForSingleObject (*mutex, 0) == WAIT_OBJECT_0)
status = 0;
else
status = 1;
}
return status;
}
static inline int
__gthread_mutex_unlock (__gthread_mutex_t *mutex)
{
if (__gthread_active_p ())
return (ReleaseMutex (*mutex) != 0) ? 0 : 1;
else
return 0;
}
#endif /* __GTHREAD_HIDE_WIN32API */
#ifdef __cplusplus
}
#endif
#endif /* _LIBOBJC */
#endif /* ! GCC_GTHR_WIN32_H */

View File

@@ -0,0 +1,509 @@
/* Threads compatibility routines for libgcc2 and libobjc. */
/* Compile this one with gcc. */
/* Copyright (C) 1997, 1999, 2000, 2001 Free Software Foundation, Inc.
This file is part of GCC.
GCC 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.
GCC 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 GCC; 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, if you link this library with other files,
some of which are compiled with GCC, to produce an executable,
this library 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. */
#ifndef _GLIBCPP_GCC_GTHR_POSIX_H
#define _GLIBCPP_GCC_GTHR_POSIX_H
/* POSIX threads specific definitions.
Easy, since the interface is just one-to-one mapping. */
#define __GTHREADS 1
#include <pthread.h>
typedef pthread_key_t __gthread_key_t;
typedef pthread_once_t __gthread_once_t;
typedef pthread_mutex_t __gthread_mutex_t;
#define __GTHREAD_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
#define __GTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
#if _GLIBCPP_SUPPORTS_WEAK && _GLIBCPP_GTHREAD_USE_WEAK
#pragma weak pthread_once
#pragma weak pthread_key_create
#pragma weak pthread_key_delete
#pragma weak pthread_getspecific
#pragma weak pthread_setspecific
#pragma weak pthread_create
#pragma weak pthread_mutex_lock
#pragma weak pthread_mutex_trylock
#pragma weak pthread_mutex_unlock
#ifdef _LIBOBJC
/* Objective C. */
#pragma weak pthread_cond_broadcast
#pragma weak pthread_cond_destroy
#pragma weak pthread_cond_init
#pragma weak pthread_cond_signal
#pragma weak pthread_cond_wait
#pragma weak pthread_exit
#pragma weak pthread_mutex_init
#pragma weak pthread_mutex_destroy
#pragma weak pthread_self
#pragma weak sched_get_priority_max
#pragma weak sched_get_priority_min
#pragma weak sched_yield
#pragma weak pthread_attr_destroy
#pragma weak pthread_attr_init
#pragma weak pthread_attr_setdetachstate
#pragma weak pthread_getschedparam
#pragma weak pthread_setschedparam
#endif
static inline int
__gthread_active_p (void)
{
static void *const __gthread_active_ptr = (void *) &pthread_create;
return __gthread_active_ptr != 0;
}
#else /* not _GLIBCPP_SUPPORTS_WEAK */
static inline int
__gthread_active_p (void)
{
return 1;
}
#endif /* _GLIBCPP_SUPPORTS_WEAK */
#ifdef _LIBOBJC
/* This is the config.h file in libobjc/ */
#include <config.h>
#ifdef HAVE_SCHED_H
# include <sched.h>
#endif
/* Key structure for maintaining thread specific storage */
static pthread_key_t _objc_thread_storage;
static pthread_attr_t _objc_thread_attribs;
/* Thread local storage for a single thread */
static void *thread_local_storage = NULL;
/* Backend initialization functions */
/* Initialize the threads subsystem. */
static inline int
__gthread_objc_init_thread_system(void)
{
if (__gthread_active_p ())
{
/* Initialize the thread storage key */
if (pthread_key_create(&_objc_thread_storage, NULL) == 0)
{
/* The normal default detach state for threads is
* PTHREAD_CREATE_JOINABLE which causes threads to not die
* when you think they should. */
if (pthread_attr_init(&_objc_thread_attribs) == 0
&& pthread_attr_setdetachstate(&_objc_thread_attribs,
PTHREAD_CREATE_DETACHED) == 0)
return 0;
}
}
return -1;
}
/* Close the threads subsystem. */
static inline int
__gthread_objc_close_thread_system(void)
{
if (__gthread_active_p ()
&& pthread_key_delete(_objc_thread_storage) == 0
&& pthread_attr_destroy(&_objc_thread_attribs) == 0)
return 0;
return -1;
}
/* Backend thread functions */
/* Create a new thread of execution. */
static inline objc_thread_t
__gthread_objc_thread_detach(void (*func)(void *), void *arg)
{
objc_thread_t thread_id;
pthread_t new_thread_handle;
if (!__gthread_active_p ())
return NULL;
if ( !(pthread_create(&new_thread_handle, NULL, (void *)func, arg)) )
thread_id = (objc_thread_t) new_thread_handle;
else
thread_id = NULL;
return thread_id;
}
/* Set the current thread's priority. */
static inline int
__gthread_objc_thread_set_priority(int priority)
{
if (!__gthread_active_p())
return -1;
else {
pthread_t thread_id = pthread_self();
int policy;
struct sched_param params;
int priority_min, priority_max;
if (pthread_getschedparam(thread_id, &policy, &params) == 0)
{
if ((priority_max = sched_get_priority_max(policy)) != 0)
return -1;
if ((priority_min = sched_get_priority_min(policy)) != 0)
return -1;
if (priority > priority_max)
priority = priority_max;
else if (priority < priority_min)
priority = priority_min;
params.sched_priority = priority;
/*
* The solaris 7 and several other man pages incorrectly state that
* this should be a pointer to policy but pthread.h is universally
* at odds with this.
*/
if (pthread_setschedparam(thread_id, policy, &params) == 0)
return 0;
}
return -1;
}
}
/* Return the current thread's priority. */
static inline int
__gthread_objc_thread_get_priority(void)
{
if (__gthread_active_p ())
{
int policy;
struct sched_param params;
if (pthread_getschedparam(pthread_self(), &policy, &params) == 0)
return params.sched_priority;
else
return -1;
}
else
return OBJC_THREAD_INTERACTIVE_PRIORITY;
}
/* Yield our process time to another thread. */
static inline void
__gthread_objc_thread_yield(void)
{
if (__gthread_active_p ())
sched_yield();
}
/* Terminate the current thread. */
static inline int
__gthread_objc_thread_exit(void)
{
if (__gthread_active_p ())
/* exit the thread */
pthread_exit(&__objc_thread_exit_status);
/* Failed if we reached here */
return -1;
}
/* Returns an integer value which uniquely describes a thread. */
static inline objc_thread_t
__gthread_objc_thread_id(void)
{
if (__gthread_active_p ())
return (objc_thread_t) pthread_self();
else
return (objc_thread_t) 1;
}
/* Sets the thread's local storage pointer. */
static inline int
__gthread_objc_thread_set_data(void *value)
{
if (__gthread_active_p ())
return pthread_setspecific(_objc_thread_storage, value);
else
{
thread_local_storage = value;
return 0;
}
}
/* Returns the thread's local storage pointer. */
static inline void *
__gthread_objc_thread_get_data(void)
{
if (__gthread_active_p ())
return pthread_getspecific(_objc_thread_storage);
else
return thread_local_storage;
}
/* Backend mutex functions */
/* Allocate a mutex. */
static inline int
__gthread_objc_mutex_allocate(objc_mutex_t mutex)
{
if (__gthread_active_p ())
{
mutex->backend = objc_malloc(sizeof(pthread_mutex_t));
if (pthread_mutex_init((pthread_mutex_t *)mutex->backend, NULL))
{
objc_free(mutex->backend);
mutex->backend = NULL;
return -1;
}
}
return 0;
}
/* Deallocate a mutex. */
static inline int
__gthread_objc_mutex_deallocate(objc_mutex_t mutex)
{
if (__gthread_active_p ())
{
int count;
/*
* Posix Threads specifically require that the thread be unlocked
* for pthread_mutex_destroy to work.
*/
do
{
count = pthread_mutex_unlock((pthread_mutex_t *)mutex->backend);
if (count < 0)
return -1;
}
while (count);
if (pthread_mutex_destroy((pthread_mutex_t *)mutex->backend))
return -1;
objc_free(mutex->backend);
mutex->backend = NULL;
}
return 0;
}
/* Grab a lock on a mutex. */
static inline int
__gthread_objc_mutex_lock(objc_mutex_t mutex)
{
if (__gthread_active_p ()
&& pthread_mutex_lock((pthread_mutex_t *)mutex->backend) != 0)
{
return -1;
}
return 0;
}
/* Try to grab a lock on a mutex. */
static inline int
__gthread_objc_mutex_trylock(objc_mutex_t mutex)
{
if (__gthread_active_p ()
&& pthread_mutex_trylock((pthread_mutex_t *)mutex->backend) != 0)
{
return -1;
}
return 0;
}
/* Unlock the mutex */
static inline int
__gthread_objc_mutex_unlock(objc_mutex_t mutex)
{
if (__gthread_active_p ()
&& pthread_mutex_unlock((pthread_mutex_t *)mutex->backend) != 0)
{
return -1;
}
return 0;
}
/* Backend condition mutex functions */
/* Allocate a condition. */
static inline int
__gthread_objc_condition_allocate(objc_condition_t condition)
{
if (__gthread_active_p ())
{
condition->backend = objc_malloc(sizeof(pthread_cond_t));
if (pthread_cond_init((pthread_cond_t *)condition->backend, NULL))
{
objc_free(condition->backend);
condition->backend = NULL;
return -1;
}
}
return 0;
}
/* Deallocate a condition. */
static inline int
__gthread_objc_condition_deallocate(objc_condition_t condition)
{
if (__gthread_active_p ())
{
if (pthread_cond_destroy((pthread_cond_t *)condition->backend))
return -1;
objc_free(condition->backend);
condition->backend = NULL;
}
return 0;
}
/* Wait on the condition */
static inline int
__gthread_objc_condition_wait(objc_condition_t condition, objc_mutex_t mutex)
{
if (__gthread_active_p ())
return pthread_cond_wait((pthread_cond_t *)condition->backend,
(pthread_mutex_t *)mutex->backend);
else
return 0;
}
/* Wake up all threads waiting on this condition. */
static inline int
__gthread_objc_condition_broadcast(objc_condition_t condition)
{
if (__gthread_active_p ())
return pthread_cond_broadcast((pthread_cond_t *)condition->backend);
else
return 0;
}
/* Wake up one thread waiting on this condition. */
static inline int
__gthread_objc_condition_signal(objc_condition_t condition)
{
if (__gthread_active_p ())
return pthread_cond_signal((pthread_cond_t *)condition->backend);
else
return 0;
}
#else /* _LIBOBJC */
static inline int
__gthread_once (__gthread_once_t *once, void (*func) (void))
{
if (__gthread_active_p ())
return pthread_once (once, func);
else
return -1;
}
static inline int
__gthread_key_create (__gthread_key_t *key, void (*dtor) (void *))
{
return pthread_key_create (key, dtor);
}
static inline int
__gthread_key_dtor (__gthread_key_t key, void *ptr)
{
/* Just reset the key value to zero. */
if (ptr)
return pthread_setspecific (key, 0);
else
return 0;
}
static inline int
__gthread_key_delete (__gthread_key_t key)
{
return pthread_key_delete (key);
}
static inline void *
__gthread_getspecific (__gthread_key_t key)
{
return pthread_getspecific (key);
}
static inline int
__gthread_setspecific (__gthread_key_t key, const void *ptr)
{
return pthread_setspecific (key, ptr);
}
static inline int
__gthread_mutex_lock (__gthread_mutex_t *mutex)
{
if (__gthread_active_p ())
return pthread_mutex_lock (mutex);
else
return 0;
}
static inline int
__gthread_mutex_trylock (__gthread_mutex_t *mutex)
{
if (__gthread_active_p ())
return pthread_mutex_trylock (mutex);
else
return 0;
}
static inline int
__gthread_mutex_unlock (__gthread_mutex_t *mutex)
{
if (__gthread_active_p ())
return pthread_mutex_unlock (mutex);
else
return 0;
}
#endif /* _LIBOBJC */
#endif /* ! _GLIBCPP_GCC_GTHR_POSIX_H */

View File

@@ -0,0 +1,239 @@
/* Threads compatibility routines for libgcc2 and libobjc. */
/* Compile this one with gcc. */
/* Copyright (C) 1997, 1999, 2000 Free Software Foundation, Inc.
This file is part of GCC.
GCC 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.
GCC 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 GCC; 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, if you link this library with other files,
some of which are compiled with GCC, to produce an executable,
this library 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. */
#ifndef _GLIBCPP_GCC_GTHR_SINGLE_H
#define _GLIBCPP_GCC_GTHR_SINGLE_H
/* Just provide compatibility for mutex handling. */
typedef int __gthread_mutex_t;
#define __GTHREAD_MUTEX_INIT 0
#ifdef __cplusplus
#define _GLIBCPP_UNUSED(x)
#else
#define _GLIBCPP_UNUSED(x) x __attribute__((unused))
#endif
#ifdef _LIBOBJC
/* Thread local storage for a single thread */
static void *thread_local_storage = NULL;
/* Backend initialization functions */
/* Initialize the threads subsystem. */
static inline int
__gthread_objc_init_thread_system(void)
{
/* No thread support available */
return -1;
}
/* Close the threads subsystem. */
static inline int
__gthread_objc_close_thread_system(void)
{
/* No thread support available */
return -1;
}
/* Backend thread functions */
/* Create a new thread of execution. */
static inline objc_thread_t
__gthread_objc_thread_detach(void (* func)(void *), void * _GLIBCPP_UNUSED(arg))
{
/* No thread support available */
return NULL;
}
/* Set the current thread's priority. */
static inline int
__gthread_objc_thread_set_priority(int _GLIBCPP_UNUSED(priority))
{
/* No thread support available */
return -1;
}
/* Return the current thread's priority. */
static inline int
__gthread_objc_thread_get_priority(void)
{
return OBJC_THREAD_INTERACTIVE_PRIORITY;
}
/* Yield our process time to another thread. */
static inline void
__gthread_objc_thread_yield(void)
{
return;
}
/* Terminate the current thread. */
static inline int
__gthread_objc_thread_exit(void)
{
/* No thread support available */
/* Should we really exit the program */
/* exit(&__objc_thread_exit_status); */
return -1;
}
/* Returns an integer value which uniquely describes a thread. */
static inline objc_thread_t
__gthread_objc_thread_id(void)
{
/* No thread support, use 1. */
return (objc_thread_t)1;
}
/* Sets the thread's local storage pointer. */
static inline int
__gthread_objc_thread_set_data(void *value)
{
thread_local_storage = value;
return 0;
}
/* Returns the thread's local storage pointer. */
static inline void *
__gthread_objc_thread_get_data(void)
{
return thread_local_storage;
}
/* Backend mutex functions */
/* Allocate a mutex. */
static inline int
__gthread_objc_mutex_allocate(objc_mutex_t _GLIBCPP_UNUSED(mutex))
{
return 0;
}
/* Deallocate a mutex. */
static inline int
__gthread_objc_mutex_deallocate(objc_mutex_t _GLIBCPP_UNUSED(mutex))
{
return 0;
}
/* Grab a lock on a mutex. */
static inline int
__gthread_objc_mutex_lock(objc_mutex_t _GLIBCPP_UNUSED(mutex))
{
/* There can only be one thread, so we always get the lock */
return 0;
}
/* Try to grab a lock on a mutex. */
static inline int
__gthread_objc_mutex_trylock(objc_mutex_t _GLIBCPP_UNUSED(mutex))
{
/* There can only be one thread, so we always get the lock */
return 0;
}
/* Unlock the mutex */
static inline int
__gthread_objc_mutex_unlock(objc_mutex_t _GLIBCPP_UNUSED(mutex))
{
return 0;
}
/* Backend condition mutex functions */
/* Allocate a condition. */
static inline int
__gthread_objc_condition_allocate(objc_condition_t _GLIBCPP_UNUSED(condition))
{
return 0;
}
/* Deallocate a condition. */
static inline int
__gthread_objc_condition_deallocate(objc_condition_t _GLIBCPP_UNUSED(condition))
{
return 0;
}
/* Wait on the condition */
static inline int
__gthread_objc_condition_wait(objc_condition_t _GLIBCPP_UNUSED(condition),
objc_mutex_t _GLIBCPP_UNUSED(mutex))
{
return 0;
}
/* Wake up all threads waiting on this condition. */
static inline int
__gthread_objc_condition_broadcast(objc_condition_t _GLIBCPP_UNUSED(condition))
{
return 0;
}
/* Wake up one thread waiting on this condition. */
static inline int
__gthread_objc_condition_signal(objc_condition_t _GLIBCPP_UNUSED(condition))
{
return 0;
}
#else /* _LIBOBJC */
static inline int
__gthread_active_p (void)
{
return 0;
}
static inline int
__gthread_mutex_lock (__gthread_mutex_t * _GLIBCPP_UNUSED(mutex))
{
return 0;
}
static inline int
__gthread_mutex_trylock (__gthread_mutex_t * _GLIBCPP_UNUSED(mutex))
{
return 0;
}
static inline int
__gthread_mutex_unlock (__gthread_mutex_t * _GLIBCPP_UNUSED(mutex))
{
return 0;
}
#endif /* _LIBOBJC */
#undef _GLIBCPP_UNUSED
#endif /* ! _GLIBCPP_GCC_GTHR_SINGLE_H */

View File

@@ -0,0 +1,105 @@
/* Threads compatibility routines for libgcc2. */
/* Compile this one with gcc. */
/* Copyright (C) 1997, 1998 Free Software Foundation, Inc.
This file is part of GCC.
GCC 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.
GCC 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 GCC; 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, if you link this library with other files,
some of which are compiled with GCC, to produce an executable,
this library 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. */
#ifndef _GLIBCPP_GCC_GTHR_H
#define _GLIBCPP_GCC_GTHR_H
/* If this file is compiled with threads support, it must
#define __GTHREADS 1
to indicate that threads support is present. Also it has define
function
int __gthread_active_p ()
that returns 1 if thread system is active, 0 if not.
The threads interface must define the following types:
__gthread_key_t
__gthread_once_t
__gthread_mutex_t
The threads interface must define the following macros:
__GTHREAD_ONCE_INIT
to initialize __gthread_once_t
__GTHREAD_MUTEX_INIT
to initialize __gthread_mutex_t to get a fast
non-recursive mutex.
__GTHREAD_MUTEX_INIT_FUNCTION
some systems can't initialize a mutex without a
function call. On such systems, define this to a
function which looks like this:
void __GTHREAD_MUTEX_INIT_FUNCTION (__gthread_mutex_t *)
Don't define __GTHREAD_MUTEX_INIT in this case
The threads interface must define the following static functions:
int __gthread_once (__gthread_once_t *once, void (*func) ())
int __gthread_key_create (__gthread_key_t *keyp, void (*dtor) (void *))
int __gthread_key_delete (__gthread_key_t key)
int __gthread_key_dtor (__gthread_key_t key, void *ptr)
void *__gthread_getspecific (__gthread_key_t key)
int __gthread_setspecific (__gthread_key_t key, const void *ptr)
int __gthread_mutex_lock (__gthread_mutex_t *mutex);
int __gthread_mutex_trylock (__gthread_mutex_t *mutex);
int __gthread_mutex_unlock (__gthread_mutex_t *mutex);
All functions returning int should return zero on success or the error
number. If the operation is not supported, -1 is returned.
Currently supported threads packages are
POSIX threads with -D_PTHREADS
DCE threads with -D_DCE_THREADS
Solaris/UI threads with -D_SOLARIS_THREADS
*/
/* Check first for thread specific defines. */
#if _GLIBCPP__PTHREADS
#include <bits/gthr-posix.h>
#elif _GLIBCPP__DCE_THREADS
#include <bits/gthr-dce.h>
#elif _GLIBCPP__SOLARIS_THREADS
#include <bits/gthr-solaris.h>
/* Include GTHREAD_FILE if one is defined. */
#elif defined(_GLIBCPP_HAVE_GTHR_DEFAULT)
#if _GLIBCPP_SUPPORTS_WEAK
#ifndef _GLIBCPP_GTHREAD_USE_WEAK
#define _GLIBCPP_GTHREAD_USE_WEAK 1
#endif
#endif
#include <bits/gthr-default.h>
/* Fallback to single thread definitions. */
#else
#include <bits/gthr-single.h>
#endif
#endif /* ! _GLIBCPP_GCC_GTHR_H */

View File

@@ -0,0 +1,81 @@
// std::messages implementation details, generic version -*- C++ -*-
// Copyright (C) 2001, 2003 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.
//
// ISO C++ 14882: 22.2.7.1.2 messages virtual functions
//
// Written by Benjamin Kosnik <bkoz@redhat.com>
// Non-virtual member functions.
template<typename _CharT>
messages<_CharT>::messages(size_t __refs)
: locale::facet(__refs)
{ _M_c_locale_messages = _S_c_locale; }
template<typename _CharT>
messages<_CharT>::messages(__c_locale __cloc, const char*, size_t __refs)
: locale::facet(__refs)
{ _M_c_locale_messages = _S_c_locale; }
template<typename _CharT>
typename messages<_CharT>::catalog
messages<_CharT>::open(const basic_string<char>& __s, const locale& __loc,
const char*) const
{ return this->do_open(__s, __loc); }
// Virtual member functions.
template<typename _CharT>
messages<_CharT>::~messages()
{ _S_destroy_c_locale(_M_c_locale_messages); }
template<typename _CharT>
typename messages<_CharT>::catalog
messages<_CharT>::do_open(const basic_string<char>&, const locale&) const
{ return 0; }
template<typename _CharT>
typename messages<_CharT>::string_type
messages<_CharT>::do_get(catalog, int, int,
const string_type& __dfault) const
{ return __dfault; }
template<typename _CharT>
void
messages<_CharT>::do_close(catalog) const
{ }
// messages_byname
template<typename _CharT>
messages_byname<_CharT>::messages_byname(const char* __s, size_t __refs)
: messages<_CharT>(__refs)
{
_S_destroy_c_locale(_M_c_locale_messages);
_S_create_c_locale(_M_c_locale_messages, __s);
}

View File

@@ -0,0 +1,47 @@
// Specific definitions for generic platforms -*- 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.
#ifndef _GLIBCPP_OS_DEFINES
# define _GLIBCPP_OS_DEFINES
// System-specific #define, typedefs, corrections, etc, go here. This
// file will come before all others.
#define _GLIBCPP_NO_LONG_DOUBLE_IO 1
#if !(defined __GTHREAD_SHOW_WIN32API || defined __GTHREAD_HIDE_WIN32API)
# define __GTHREAD_HIDE_WIN32API 1
#endif
// Prevent w32api windef.h from defining min and max as macros.
#undef NOMINMAX
#define NOMINMAX 1
#endif

View File

@@ -0,0 +1,61 @@
// std::time_get, std::time_put implementation, generic version -*- C++ -*-
// Copyright (C) 2001, 2002, 2003 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.
//
// ISO C++ 14882: 22.2.5.1.2 - time_get functions
// ISO C++ 14882: 22.2.5.3.2 - time_put functions
//
// Written by Benjamin Kosnik <bkoz@redhat.com>
template<typename _CharT>
__timepunct<_CharT>::__timepunct(size_t __refs)
: locale::facet(__refs)
{
_M_name_timepunct = _S_c_name;
_M_initialize_timepunct();
}
template<typename _CharT>
__timepunct<_CharT>::__timepunct(__c_locale __cloc, const char* __s,
size_t __refs)
: locale::facet(__refs)
{
_M_name_timepunct = new char[strlen(__s) + 1];
strcpy(_M_name_timepunct, __s);
_M_initialize_timepunct(__cloc);
}
template<typename _CharT>
__timepunct<_CharT>::~__timepunct()
{
if (_S_c_name != _M_name_timepunct)
delete [] _M_name_timepunct;
_S_destroy_c_locale(_M_c_locale_timepunct);
}