OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / src / globals.cc
1 // Copyright (C) 2001 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library.  This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 2, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING.  If not, write to the Free
16 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 // USA.
18
19 // As a special exception, you may use this file as part of a free software
20 // library without restriction.  Specifically, if other files instantiate
21 // templates or use macros or inline functions from this file, or you compile
22 // this file and link it with other files to produce an executable, this
23 // file does not by itself cause the resulting executable to be covered by
24 // the GNU General Public License.  This exception does not however
25 // invalidate any other reasons why the executable file might be covered by
26 // the GNU General Public License.
27
28 #include "bits/c++config.h"
29 #include "bits/gthr.h"
30 #include <fstream>
31 #include <istream>
32 #include <ostream>
33
34 // On AIX, and perhaps other systems, library initialization order is
35 // not guaranteed.  For example, the static initializers for the main
36 // program might run before the static initializers for this library.
37 // That means that we cannot rely on static initialization in the
38 // library; there is no guarantee that things will get initialized in
39 // time.  This file contains definitions of all global variables that
40 // require initialization as arrays of characters.
41
42 // Because <iostream> declares the standard streams to be [io]stream
43 // types instead of say [io]fstream types, it is also necessary to
44 // allocate the actual file buffers in this file.
45 namespace std 
46 {
47   // Standard "C" locale.
48   typedef char fake_locale_Impl[sizeof(locale::_Impl)]
49   __attribute__ ((aligned(__alignof__(locale::_Impl))));
50   fake_locale_Impl locale_impl_c;
51
52   typedef char fake_locale[sizeof(locale)]
53   __attribute__ ((aligned(__alignof__(locale))));
54   fake_locale locale_c;
55   
56
57   // Standard stream objects.
58   typedef char fake_istream[sizeof(istream)]
59   __attribute__ ((aligned(__alignof__(istream))));
60   typedef char fake_ostream[sizeof(ostream)] 
61   __attribute__ ((aligned(__alignof__(ostream))));
62   fake_istream cin;
63   fake_ostream cout;
64   fake_ostream cerr;
65   fake_ostream clog;
66
67   typedef char fake_filebuf[sizeof(filebuf)]
68   __attribute__ ((aligned(__alignof__(filebuf))));
69   fake_filebuf buf_cout;
70   fake_filebuf buf_cin;
71   fake_filebuf buf_cerr;
72
73 #ifdef _GLIBCPP_USE_WCHAR_T
74   typedef char fake_wistream[sizeof(wistream)] 
75   __attribute__ ((aligned(__alignof__(wistream))));
76   typedef char fake_wostream[sizeof(wostream)] 
77   __attribute__ ((aligned(__alignof__(wostream))));
78   fake_wistream wcin;
79   fake_wostream wcout;
80   fake_wostream wcerr;
81   fake_wostream wclog;
82
83   typedef char fake_wfilebuf[sizeof(wfilebuf)]
84   __attribute__ ((aligned(__alignof__(wfilebuf))));
85   fake_wfilebuf buf_wcout;
86   fake_wfilebuf buf_wcin;
87   fake_wfilebuf buf_wcerr;
88 #endif
89
90
91   // Globals for once-only runtime initialization of mutex objects.  This
92   // allows static initialization of these objects on systems that need a
93   // function call to initialize a mutex.  For example, see stl_threads.h.
94 #ifdef __GTHREAD_MUTEX_INIT
95   // Need to provide explicit instantiations of static data for
96   // systems with broken weak linkage support.
97   template __gthread_mutex_t _Swap_lock_struct<0>::_S_swap_lock;
98 #elif defined(__GTHREAD_MUTEX_INIT_FUNCTION)
99   __gthread_once_t _GLIBCPP_once = __GTHREAD_ONCE_INIT;
100   __gthread_mutex_t _GLIBCPP_mutex;
101   __gthread_mutex_t *_GLIBCPP_mutex_address;
102   
103   // Once-only initializer function for _GLIBCPP_mutex.  
104   void
105   _GLIBCPP_mutex_init ()
106   { __GTHREAD_MUTEX_INIT_FUNCTION (&_GLIBCPP_mutex); }
107
108   // Once-only initializer function for _GLIBCPP_mutex_address.  
109   void
110   _GLIBCPP_mutex_address_init ()
111   { __GTHREAD_MUTEX_INIT_FUNCTION (_GLIBCPP_mutex_address); }
112 #endif
113 }