diff options
author | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2019-06-09 19:37:35 +0200 |
---|---|---|
committer | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2019-06-09 19:37:35 +0200 |
commit | bbc6de1cb86af16cda389c8e18e2d4d4c443b8c5 (patch) | |
tree | cce3948a12a32632dca9a18dd03651e27d695287 | |
parent | 4c9cf83a6673f03f4b39d826294e6ab77f8a44fb (diff) | |
download | embedlog-bbc6de1cb86af16cda389c8e18e2d4d4c443b8c5.tar.gz embedlog-bbc6de1cb86af16cda389c8e18e2d4d4c443b8c5.tar.bz2 embedlog-bbc6de1cb86af16cda389c8e18e2d4d4c443b8c5.zip |
src/el-file.c: don't flush when no data has been written
When no data has been written to file, there is not need to
perform fsync() syscall, which in this case will only eat
cycles for context switch without doing anything.
Signed-off-by: Michał Łyszczek <michal.lyszczek@bofc.pl>
-rw-r--r-- | src/el-file.c | 10 | ||||
-rw-r--r-- | tst/test-el-file.c | 24 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/el-file.c b/src/el-file.c index dd98392..34d2cbc 100644 --- a/src/el-file.c +++ b/src/el-file.c @@ -554,6 +554,16 @@ int el_file_flush VALID(EBADF, el->fcurrent_log); VALID(EBADF, el->fcurrent_log[0] != '\0'); + if (el->fwritten_after_sync == 0) + { + /* if now writes have been performed between consecutive + * flush, then don't flush - since there is nothing to + * flush anyway + */ + + return 0; + } + /* first flush data from stdio library buffers into kernel */ diff --git a/tst/test-el-file.c b/tst/test-el-file.c index cfd524f..ad98061 100644 --- a/tst/test-el-file.c +++ b/tst/test-el-file.c @@ -1552,6 +1552,29 @@ static void file_sync_via_flush_function(void) ========================================================================== */ +static void file_consecutive_sync_with_flush_function(void) +{ + el_option(EL_FSYNC_EVERY, 16); + mt_fok(el_puts(s8)); + mt_fail(file_synced == 0); + mt_fok(el_flush()); + mt_fail(file_synced == 1); + file_synced = 0; + mt_fok(el_flush()); + mt_fail(file_synced == 0); + mt_fok(el_flush()); + mt_fail(file_synced == 0); + mt_fok(el_puts(s8)); + mt_fail(file_synced == 0); + mt_fok(el_flush()); + mt_fail(file_synced == 1); +} + + +/* ========================================================================== + ========================================================================== */ + + static void file_sync_periodic(void) { el_option(EL_FSYNC_EVERY, 8); @@ -1889,6 +1912,7 @@ void el_file_test_group(void) mt_run(file_sync_periodic); mt_run(file_sync_level); mt_run(file_sync_via_flush_function); + mt_run(file_consecutive_sync_with_flush_function); rmdir(WORKDIR); #endif |