Add utils::flush_buffers()

This commit is contained in:
Richard Berger
2022-02-04 17:53:36 -05:00
parent ea0f31c997
commit 50a7d4e7fc
3 changed files with 18 additions and 5 deletions

View File

@ -5449,11 +5449,7 @@ to simplify capturing output from LAMMPS library calls.
* \param handle pointer to a previously created LAMMPS instance cast to ``void *``. * \param handle pointer to a previously created LAMMPS instance cast to ``void *``.
*/ */
void lammps_flush_buffers(void *handle) { void lammps_flush_buffers(void *handle) {
LAMMPS *lmp = (LAMMPS *) handle; utils::flush_buffers((LAMMPS *) handle);
if (lmp->screen) fflush(lmp->screen);
if (lmp->logfile) fflush(lmp->logfile);
if (lmp->universe->uscreen) fflush(lmp->universe->uscreen);
if (lmp->universe->ulogfile) fflush(lmp->universe->ulogfile);
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */

View File

@ -24,6 +24,7 @@
#include "text_file_reader.h" #include "text_file_reader.h"
#include "tokenizer.h" #include "tokenizer.h"
#include "update.h" #include "update.h"
#include "universe.h"
#include <algorithm> #include <algorithm>
#include <cctype> #include <cctype>
@ -138,6 +139,14 @@ void utils::fmtargs_logmesg(LAMMPS *lmp, fmt::string_view format, fmt::format_ar
} }
} }
void utils::flush_buffers(LAMMPS *lmp)
{
if (lmp->screen) fflush(lmp->screen);
if (lmp->logfile) fflush(lmp->logfile);
if (lmp->universe->uscreen) fflush(lmp->universe->uscreen);
if (lmp->universe->ulogfile) fflush(lmp->universe->ulogfile);
}
/* define this here, so we won't have to include the headers /* define this here, so we won't have to include the headers
everywhere and utils.h will more likely be included anyway. */ everywhere and utils.h will more likely be included anyway. */

View File

@ -74,6 +74,14 @@ namespace utils {
void logmesg(LAMMPS *lmp, const std::string &mesg); void logmesg(LAMMPS *lmp, const std::string &mesg);
/*! Flush output buffers
*
* This function calls fflush on screen and logfile FILE pointers
* if available
*/
void flush_buffers(LAMMPS *lmp);
/*! Return a string representing the current system error status /*! Return a string representing the current system error status
* *
* This is a wrapper around calling strerror(errno). * This is a wrapper around calling strerror(errno).