2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libstdc++-v3 / src / globals_io.cc
blob7be53f2f30d0e37d4a6740eec86c352e9804af3c
1 // Copyright (C) 2001, 2002, 2003 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.
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.
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.
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.
28 #include "bits/c++config.h"
29 #include "bits/gthr.h"
30 #include <fstream>
31 #include <istream>
32 #include <ostream>
33 #include <ext/stdio_filebuf.h>
34 #include <ext/stdio_sync_filebuf.h>
36 // On AIX, and perhaps other systems, library initialization order is
37 // not guaranteed. For example, the static initializers for the main
38 // program might run before the static initializers for this library.
39 // That means that we cannot rely on static initialization in the
40 // library; there is no guarantee that things will get initialized in
41 // time. This file contains definitions of all global variables that
42 // require initialization as arrays of characters.
44 // NB: asm directives can rename these non-exported, namespace
45 // __gnu_cxx symbols into exported, namespace std symbols with the
46 // appropriate symbol version name.
47 // The rename syntax is
48 // asm (".symver currentname,oldname@@GLIBCXX_3.2")
49 // In macro form:
50 // _GLIBCXX_ASM_SYMVER(currentname, oldname, GLIBCXX_3.2)
52 namespace std
54 // Standard stream objects.
55 // NB: Iff <iostream> is included, these definitions become wonky.
56 typedef char fake_istream[sizeof(istream)]
57 __attribute__ ((aligned(__alignof__(istream))));
58 typedef char fake_ostream[sizeof(ostream)]
59 __attribute__ ((aligned(__alignof__(ostream))));
60 fake_istream cin;
61 fake_ostream cout;
62 fake_ostream cerr;
63 fake_ostream clog;
65 #ifdef _GLIBCXX_USE_WCHAR_T
66 typedef char fake_wistream[sizeof(wistream)]
67 __attribute__ ((aligned(__alignof__(wistream))));
68 typedef char fake_wostream[sizeof(wostream)]
69 __attribute__ ((aligned(__alignof__(wostream))));
70 fake_wistream wcin;
71 fake_wostream wcout;
72 fake_wostream wcerr;
73 fake_wostream wclog;
74 #endif
75 } // namespace std
77 namespace __gnu_cxx
79 using namespace std;
81 // We use different stream buffer types depending on whether
82 // ios_base::sync_with_stdio(false) has been called.
83 typedef char fake_stdiobuf[sizeof(stdio_sync_filebuf<char>)]
84 __attribute__ ((aligned(__alignof__(stdio_sync_filebuf<char>))));
85 fake_stdiobuf buf_cout_sync;
86 fake_stdiobuf buf_cin_sync;
87 fake_stdiobuf buf_cerr_sync;
89 typedef char fake_filebuf[sizeof(stdio_filebuf<char>)]
90 __attribute__ ((aligned(__alignof__(stdio_filebuf<char>))));
91 fake_filebuf buf_cout;
92 fake_filebuf buf_cin;
93 fake_filebuf buf_cerr;
95 #ifdef _GLIBCXX_USE_WCHAR_T
96 typedef char fake_wstdiobuf[sizeof(stdio_sync_filebuf<wchar_t>)]
97 __attribute__ ((aligned(__alignof__(stdio_sync_filebuf<wchar_t>))));
98 fake_wstdiobuf buf_wcout_sync;
99 fake_wstdiobuf buf_wcin_sync;
100 fake_wstdiobuf buf_wcerr_sync;
102 typedef char fake_wfilebuf[sizeof(stdio_filebuf<wchar_t>)]
103 __attribute__ ((aligned(__alignof__(stdio_filebuf<wchar_t>))));
104 fake_wfilebuf buf_wcout;
105 fake_wfilebuf buf_wcin;
106 fake_wfilebuf buf_wcerr;
107 #endif
109 // Globals for once-only runtime initialization of mutex objects. This
110 // allows static initialization of these objects on systems that need a
111 // function call to initialize a mutex. For example, see stl_threads.h.
112 #ifdef __GTHREAD_MUTEX_INIT
113 #elif defined(__GTHREAD_MUTEX_INIT_FUNCTION)
114 __gthread_once_t _GLIBCXX_once = __GTHREAD_ONCE_INIT;
115 __gthread_mutex_t _GLIBCXX_mutex;
116 __gthread_mutex_t *_GLIBCXX_mutex_address;
118 // Once-only initializer function for _GLIBCXX_mutex.
119 void
120 _GLIBCXX_mutex_init ()
121 { __GTHREAD_MUTEX_INIT_FUNCTION (&_GLIBCXX_mutex); }
123 // Once-only initializer function for _GLIBCXX_mutex_address.
124 void
125 _GLIBCXX_mutex_address_init ()
126 { __GTHREAD_MUTEX_INIT_FUNCTION (_GLIBCXX_mutex_address); }
127 #endif
128 } // namespace __gnu_cxx