OSDN Git Service

2006-07-20 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / src / globals_io.cc
1 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
2 // Free Software Foundation, Inc.
3 //
4 // This file is part of the GNU ISO C++ Library.  This library is free
5 // software; you can redistribute it and/or modify it under the
6 // terms of the GNU General Public License as published by the
7 // Free Software Foundation; either version 2, or (at your option)
8 // any later version.
9
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14
15 // You should have received a copy of the GNU General Public License along
16 // with this library; see the file COPYING.  If not, write to the Free
17 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
18 // USA.
19
20 // As a special exception, you may use this file as part of a free software
21 // library without restriction.  Specifically, if other files instantiate
22 // templates or use macros or inline functions from this file, or you compile
23 // this file and link it with other files to produce an executable, this
24 // file does not by itself cause the resulting executable to be covered by
25 // the GNU General Public License.  This exception does not however
26 // invalidate any other reasons why the executable file might be covered by
27 // the GNU General Public License.
28
29 #include "bits/c++config.h"
30 #include "bits/gthr.h"
31 #include <fstream>
32 #include <istream>
33 #include <ostream>
34 #include <ext/stdio_filebuf.h>
35 #include <ext/stdio_sync_filebuf.h>
36
37 // On AIX, and perhaps other systems, library initialization order is
38 // not guaranteed.  For example, the static initializers for the main
39 // program might run before the static initializers for this library.
40 // That means that we cannot rely on static initialization in the
41 // library; there is no guarantee that things will get initialized in
42 // time.  This file contains definitions of all global variables that
43 // require initialization as arrays of characters.
44
45 // NB: asm directives can rename these non-exported, namespace
46 // __gnu_cxx symbols into exported, namespace std symbols with the
47 // appropriate symbol version name.
48 // The rename syntax is 
49 //   asm (".symver currentname,oldname@@GLIBCXX_3.2")
50 // In macro form:
51 // _GLIBCXX_ASM_SYMVER(currentname, oldname, GLIBCXX_3.2)
52
53 _GLIBCXX_BEGIN_NAMESPACE(std)
54
55   // Standard stream objects.
56   // NB: Iff <iostream> is included, these definitions become wonky.
57   typedef char fake_istream[sizeof(istream)]
58   __attribute__ ((aligned(__alignof__(istream))));
59   typedef char fake_ostream[sizeof(ostream)] 
60   __attribute__ ((aligned(__alignof__(ostream))));
61   fake_istream cin;
62   fake_ostream cout;
63   fake_ostream cerr;
64   fake_ostream clog;
65
66 #ifdef _GLIBCXX_USE_WCHAR_T
67   typedef char fake_wistream[sizeof(wistream)] 
68   __attribute__ ((aligned(__alignof__(wistream))));
69   typedef char fake_wostream[sizeof(wostream)] 
70   __attribute__ ((aligned(__alignof__(wostream))));
71   fake_wistream wcin;
72   fake_wostream wcout;
73   fake_wostream wcerr;
74   fake_wostream wclog;
75 #endif
76
77 _GLIBCXX_END_NAMESPACE
78
79 namespace __gnu_internal _GLIBCXX_VISIBILITY(hidden)
80 {
81   using namespace std;
82   using namespace __gnu_cxx;
83
84   // We use different stream buffer types depending on whether
85   // ios_base::sync_with_stdio(false) has been called.
86   typedef char fake_stdiobuf[sizeof(stdio_sync_filebuf<char>)]
87   __attribute__ ((aligned(__alignof__(stdio_sync_filebuf<char>))));
88   fake_stdiobuf buf_cout_sync;
89   fake_stdiobuf buf_cin_sync;
90   fake_stdiobuf buf_cerr_sync;
91
92   typedef char fake_filebuf[sizeof(stdio_filebuf<char>)]
93   __attribute__ ((aligned(__alignof__(stdio_filebuf<char>))));
94   fake_filebuf buf_cout;
95   fake_filebuf buf_cin;
96   fake_filebuf buf_cerr;
97
98 #ifdef _GLIBCXX_USE_WCHAR_T
99   typedef char fake_wstdiobuf[sizeof(stdio_sync_filebuf<wchar_t>)]
100   __attribute__ ((aligned(__alignof__(stdio_sync_filebuf<wchar_t>))));
101   fake_wstdiobuf buf_wcout_sync;
102   fake_wstdiobuf buf_wcin_sync;
103   fake_wstdiobuf buf_wcerr_sync;
104
105   typedef char fake_wfilebuf[sizeof(stdio_filebuf<wchar_t>)]
106   __attribute__ ((aligned(__alignof__(stdio_filebuf<wchar_t>))));
107   fake_wfilebuf buf_wcout;
108   fake_wfilebuf buf_wcin;
109   fake_wfilebuf buf_wcerr;
110 #endif
111
112   // Globals for once-only runtime initialization of mutex objects.  This
113   // allows static initialization of these objects on systems that need a
114   // function call to initialize a mutex.  For example, see stl_threads.h.
115 #ifdef __GTHREAD_MUTEX_INIT
116 #elif defined(__GTHREAD_MUTEX_INIT_FUNCTION)
117   __gthread_once_t _GLIBCXX_once = __GTHREAD_ONCE_INIT;
118   __gthread_mutex_t _GLIBCXX_mutex;
119   __gthread_mutex_t *_GLIBCXX_mutex_address;
120   
121   // Once-only initializer function for _GLIBCXX_mutex.  
122   void
123   _GLIBCXX_mutex_init ()
124   { __GTHREAD_MUTEX_INIT_FUNCTION (&_GLIBCXX_mutex); }
125
126   // Once-only initializer function for _GLIBCXX_mutex_address.  
127   void
128   _GLIBCXX_mutex_address_init ()
129   { __GTHREAD_MUTEX_INIT_FUNCTION (_GLIBCXX_mutex_address); }
130 #endif
131 } // namespace __gnu_internal