# globals_io.cc

    00001 // Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
    00002 //
    00003 // This file is part of the GNU ISO C++ Library.  This library is free
    00004 // software; you can redistribute it and/or modify it under the
    00005 // terms of the GNU General Public License as published by the
    00006 // Free Software Foundation; either version 2, or (at your option)
    00007 // any later version.
    00008
    00009 // This library is distributed in the hope that it will be useful,
    00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00012 // GNU General Public License for more details.
    00013
    00014 // You should have received a copy of the GNU General Public License along
    00015 // with this library; see the file COPYING.  If not, write to the Free
    00016 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
    00017 // USA.
    00018
    00019 // As a special exception, you may use this file as part of a free software
    00020 // library without restriction.  Specifically, if other files instantiate
    00021 // templates or use macros or inline functions from this file, or you compile
    00022 // this file and link it with other files to produce an executable, this
    00023 // file does not by itself cause the resulting executable to be covered by
    00024 // the GNU General Public License.  This exception does not however
    00025 // invalidate any other reasons why the executable file might be covered by
    00026 // the GNU General Public License.
    00027
    00028 #include "bits/c++config.h"
    00029 #include "bits/gthr.h"
    00030 #include <fstream>
    00031 #include <istream>
    00032 #include <ostream>
    00033 #include <ext/stdio_filebuf.h>
    00034 #include <ext/stdio_sync_filebuf.h>
    00035
    00036 // On AIX, and perhaps other systems, library initialization order is
    00037 // not guaranteed.  For example, the static initializers for the main
    00038 // program might run before the static initializers for this library.
    00039 // That means that we cannot rely on static initialization in the
    00040 // library; there is no guarantee that things will get initialized in
    00041 // time.  This file contains definitions of all global variables that
    00042 // require initialization as arrays of characters.
    00043
    00044 // NB: asm directives can rename these non-exported, namespace
    00045 // __gnu_cxx symbols into exported, namespace std symbols with the
    00046 // appropriate symbol version name.
    00047 // The rename syntax is
    00048 //   asm (".symver currentname,oldname@@GLIBCXX_3.2")
    00049 // In macro form:
    00050 // _GLIBCXX_ASM_SYMVER(currentname, oldname, GLIBCXX_3.2)
    00051
    00052 namespace std
    00053 {
    00054   // Standard stream objects.
    00055   // NB: Iff <iostream> is included, these definitions become wonky.
    00056   typedef char fake_istream[sizeof(istream)]
    00057   __attribute__ ((aligned(__alignof__(istream))));
    00058   typedef char fake_ostream[sizeof(ostream)]
    00059   __attribute__ ((aligned(__alignof__(ostream))));
    00060   fake_istream cin;
    00061   fake_ostream cout;
    00062   fake_ostream cerr;
    00063   fake_ostream clog;
    00064
    00065 #ifdef _GLIBCXX_USE_WCHAR_T
    00066   typedef char fake_wistream[sizeof(wistream)]
    00067   __attribute__ ((aligned(__alignof__(wistream))));
    00068   typedef char fake_wostream[sizeof(wostream)]
    00069   __attribute__ ((aligned(__alignof__(wostream))));
    00070   fake_wistream wcin;
    00071   fake_wostream wcout;
    00072   fake_wostream wcerr;
    00073   fake_wostream wclog;
    00074 #endif
    00075 } // namespace std
    00076
    00077 namespace __gnu_internal
    00078 {
    00079   using namespace std;
    00080   using namespace __gnu_cxx;
    00081
    00082   // We use different stream buffer types depending on whether
    00083   // ios_base::sync_with_stdio(false) has been called.
    00084   typedef char fake_stdiobuf[sizeof(stdio_sync_filebuf<char>)]
    00085   __attribute__ ((aligned(__alignof__(stdio_sync_filebuf<char>))));
    00086   fake_stdiobuf buf_cout_sync;
    00087   fake_stdiobuf buf_cin_sync;
    00088   fake_stdiobuf buf_cerr_sync;
    00089
    00090   typedef char fake_filebuf[sizeof(stdio_filebuf<char>)]
    00091   __attribute__ ((aligned(__alignof__(stdio_filebuf<char>))));
    00092   fake_filebuf buf_cout;
    00093   fake_filebuf buf_cin;
    00094   fake_filebuf buf_cerr;
    00095
    00096 #ifdef _GLIBCXX_USE_WCHAR_T
    00097   typedef char fake_wstdiobuf[sizeof(stdio_sync_filebuf<wchar_t>)]
    00098   __attribute__ ((aligned(__alignof__(stdio_sync_filebuf<wchar_t>))));
    00099   fake_wstdiobuf buf_wcout_sync;
    00100   fake_wstdiobuf buf_wcin_sync;
    00101   fake_wstdiobuf buf_wcerr_sync;
    00102
    00103   typedef char fake_wfilebuf[sizeof(stdio_filebuf<wchar_t>)]
    00104   __attribute__ ((aligned(__alignof__(stdio_filebuf<wchar_t>))));
    00105   fake_wfilebuf buf_wcout;
    00106   fake_wfilebuf buf_wcin;
    00107   fake_wfilebuf buf_wcerr;
    00108 #endif
    00109
    00110   // Globals for once-only runtime initialization of mutex objects.  This
    00111   // allows static initialization of these objects on systems that need a
    00112   // function call to initialize a mutex.  For example, see stl_threads.h.
    00113 #ifdef __GTHREAD_MUTEX_INIT
    00114 #elif defined(__GTHREAD_MUTEX_INIT_FUNCTION)
    00115   __gthread_once_t _GLIBCXX_once = __GTHREAD_ONCE_INIT;
    00116   __gthread_mutex_t _GLIBCXX_mutex;
    00117   __gthread_mutex_t *_GLIBCXX_mutex_address;
    00118
    00119   // Once-only initializer function for _GLIBCXX_mutex.
    00120   void
    00121   _GLIBCXX_mutex_init ()
    00122   { __GTHREAD_MUTEX_INIT_FUNCTION (&_GLIBCXX_mutex); }
    00123
    00124   // Once-only initializer function for _GLIBCXX_mutex_address.
    00125   void
    00126   _GLIBCXX_mutex_address_init ()
    00127   { __GTHREAD_MUTEX_INIT_FUNCTION (_GLIBCXX_mutex_address); }
    00128 #endif
    00129 } // namespace __gnu_internal