// on SunOS 4.x, getrusage is stated in the man pages and exists, but
// is not declared in resource.h. declare it ourselves
#ifdef NO_HAVE_GETRUSAGE
-extern "C" {
+extern "C" {
int getrusage(int who, struct rusage* ru);
}
#endif
// another thread tries to do the same.
DEAL_II_NAMESPACE_OPEN
-namespace
+namespace
{
Threads::ThreadMutex log_lock;
Threads::ThreadMutex write_lock;
LogStream::~LogStream()
{
+ // if there was anything left in
+ // the stream that is current to
+ // this thread, make sure we flush
+ // it before it gets lost
+ {
+ const unsigned int id = Threads::this_thread_id();
+ if ((outstreams.find(id) != outstreams.end())
+ &&
+ (*outstreams[id] != 0)
+ &&
+ (outstreams[id]->str().length() > 0))
+ *this << std::endl;
+ }
+
if (old_cerr)
std::cerr.rdbuf(old_cerr);
// deliberate memory leak and
// instead destroying an empty
// object
-#ifdef DEAL_II_USE_TRILINOS
+#ifdef DEAL_II_USE_TRILINOS
if (this == &deallog)
(new stream_map_type())->swap (outstreams);
#endif
std::ostringstream& stream = get_stream();
if (prefixes.size() <= std_depth)
*std_out << stream.str();
-
+
if (file && (prefixes.size() <= file_depth))
*file << stream.str() << std::flush;
-
+
// Start a new string
stream.str("");
}
LogStream::get_stream()
{
Threads::ThreadMutex::ScopedLock lock(log_lock);
- unsigned int id = Threads::this_thread_id();
+ const unsigned int id = Threads::this_thread_id();
std_cxx1x::shared_ptr<std::ostringstream>& sptr = outstreams[id];
if (sptr == 0)
{
sptr = std_cxx1x::shared_ptr<std::ostringstream> (new std::ostringstream());
sptr->setf(std::ios::showpoint | std::ios::left);
- }
+ }
return *sptr;
}
* When we have more information about the kernel, this should be
* incorporated properly. Suggestions are welcome!
*/
-
+
#ifdef DEALII_MEMORY_DEBUG
static const pid_t id = getpid();
-
+
std::ostringstream statname;
statname << "/proc/" << id << "/stat";
dummy >> dummy >> dummy >> dummy >> dummy >> dummy >>
dummy >> dummy >> dummy >> dummy >> dummy >> size;
#endif
-
+
const std::string& head = get_prefix();
const unsigned int thread = Threads::this_thread_id();
-
+
if (prefixes.size() <= std_depth)
{
if (print_utime)
}
if (print_thread_id)
*std_out << '[' << thread << ']';
-
+
*std_out << head << ':';
}
-
+
if (file && (prefixes.size() <= file_depth))
{
if (print_utime)
*file << size << ':';
#endif
file->width(p);
- }
+ }
if (print_thread_id)
*file << '[' << thread << ']';
-
+
*file << head << ':';
}
}
mem += MemoryConsumption::memory_consumption (tmp.top());
tmp.pop ();
};
-
+
return mem;
}
--- /dev/null
+//---------------------------- logstream_end.cc ---------------------------
+// $Id$
+// Version: $Name$
+//
+// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2009 by the deal.II authors
+//
+// This file is subject to QPL and may not be distributed
+// without copyright and license information. Please refer
+// to the file deal.II/doc/license.html for the text and
+// further information on this license.
+//
+//---------------------------- logstream_end.cc ---------------------------
+
+
+// it used to happen that if we destroyed logstream (and presumably
+// all objects of the same type) that whatever we had put into with
+// operator<< after the last use of std::endl was lost. make sure that
+// that isn't the case anymore: logstream should flush whatever it has
+// left over when it is destroyed
+
+
+#include "../tests.h"
+#include <base/logstream.h>
+#include <fstream>
+#include <iomanip>
+#include <limits>
+
+
+int main()
+{
+ std::ofstream logfile("logstream_end/output");
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+ deallog.threshold_double(1.e-10);
+
+ {
+ LogStream log;
+
+ log.attach(logfile);
+ log.depth_console(0);
+ log.threshold_double(1.e-10);
+ log.log_thread_id (false);
+
+ log << "This should be printed!";
+ }
+// deallog << "OK" << std::endl;
+}