Skip to content

Commit 2ec2155

Browse files
committed
Factor out cleanup_stream_buffers()
1 parent 550d198 commit 2ec2155

1 file changed

Lines changed: 31 additions & 21 deletions

File tree

src/base/libmesh.C

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,36 @@ void uninstall_thread_buffered_sync()
278278
}
279279
}
280280

281+
282+
/**
283+
* Helper to do cleanup from both destructor and terminate
284+
*/
285+
void cleanup_stream_buffers()
286+
{
287+
// Before resetting the stream buffers, let's remove our thread wrappers
288+
if (!libMesh::on_command_line ("--disable-thread-safe-output"))
289+
uninstall_thread_buffered_sync();
290+
291+
if (libMesh::on_command_line ("--redirect-stdout") ||
292+
libMesh::on_command_line ("--redirect-output"))
293+
{
294+
// If stdout/stderr were redirected to files, reset them now.
295+
libMesh::out.rdbuf (out_buf);
296+
libMesh::err.rdbuf (err_buf);
297+
}
298+
299+
// If we built our own output streams, we want to clean them up.
300+
if (libMesh::on_command_line ("--separate-libmeshout"))
301+
{
302+
delete libMesh::out.get();
303+
delete libMesh::err.get();
304+
305+
libMesh::out.reset(std::cout);
306+
libMesh::err.reset(std::cerr);
307+
}
308+
}
309+
310+
281311
bool warned_about_auto_ptr(false);
282312

283313
PerfLog perflog ("libMesh",
@@ -854,27 +884,7 @@ LibMeshInit::~LibMeshInit()
854884
// Set the initialized() flag to false
855885
libMeshPrivateData::_is_initialized = false;
856886

857-
// Before resetting the stream buffers, let's remove our thread wrappers
858-
if (!libMesh::on_command_line ("--disable-thread-safe-output"))
859-
uninstall_thread_buffered_sync();
860-
861-
if (libMesh::on_command_line ("--redirect-stdout") ||
862-
libMesh::on_command_line ("--redirect-output"))
863-
{
864-
// If stdout/stderr were redirected to files, reset them now.
865-
libMesh::out.rdbuf (out_buf);
866-
libMesh::err.rdbuf (err_buf);
867-
}
868-
869-
// If we built our own output streams, we want to clean them up.
870-
if (libMesh::on_command_line ("--separate-libmeshout"))
871-
{
872-
delete libMesh::out.get();
873-
delete libMesh::err.get();
874-
875-
libMesh::out.reset(std::cout);
876-
libMesh::err.reset(std::cerr);
877-
}
887+
cleanup_stream_buffers();
878888

879889
#ifdef LIBMESH_ENABLE_EXCEPTIONS
880890
// Reset the old terminate handler; maybe the user code wants to

0 commit comments

Comments
 (0)