From 57abf9e947fa3f7d69f7adb97023b299916ee63c Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Sun, 22 Mar 2009 19:00:05 +0000 Subject: libbb: make history saving/loading concurrent-safe * all history writers always append (not overwrite) history files * they reload history if they detect that file length has changed since last write * they trim history file only when it grows 4 times longer than MAXLINES * they do this atomically by creating new file and renaming it to old Unfortunately, this comes at a price: function old new delta load_history - 346 +346 read_line_input 3155 3358 +203 new_line_input_t 17 31 +14 ...irrelevant small jitter... ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 5/5 up/down: 573/-13) Total: 560 bytes --- include/libbb.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/libbb.h b/include/libbb.h index a2042fe..7bf9469 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1187,9 +1187,9 @@ unsigned long long bb_makedev(unsigned int major, unsigned int minor) FAST_FUNC; #if ENABLE_FEATURE_EDITING /* It's NOT just ENABLEd or disabled. It's a number: */ #ifdef CONFIG_FEATURE_EDITING_HISTORY -#define MAX_HISTORY (CONFIG_FEATURE_EDITING_HISTORY + 0) +# define MAX_HISTORY (CONFIG_FEATURE_EDITING_HISTORY + 0) #else -#define MAX_HISTORY 0 +# define MAX_HISTORY 0 #endif typedef struct line_input_t { int flags; @@ -1197,7 +1197,11 @@ typedef struct line_input_t { #if MAX_HISTORY int cnt_history; int cur_history; - USE_FEATURE_EDITING_SAVEHISTORY(const char *hist_file;) +#if ENABLE_FEATURE_EDITING_SAVEHISTORY + unsigned cnt_history_in_file; + off_t last_history_end; + const char *hist_file; +#endif char *history[MAX_HISTORY + 1]; #endif } line_input_t; -- cgit v1.1