From 3f5c02bf926b238512f7275f3344944daf416229 Mon Sep 17 00:00:00 2001 From: Jan Kanis Date: Tue, 5 Feb 2013 21:18:22 +0100 Subject: [PATCH] rename reader_cancel_thread to reader_thread_job_is_stale, update comments --- reader.cpp | 4 ++-- reader.h | 4 +--- wildcard.cpp | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/reader.cpp b/reader.cpp index 2328cb522..385c5967a 100644 --- a/reader.cpp +++ b/reader.cpp @@ -181,7 +181,7 @@ commence. */ #define SEARCH_FORWARD 1 -/* Any time the contents of a buffer changes, we update the generation count. This allows for our background highlighting thread to notice it and skip doing work that it would otherwise have to do. */ +/* Any time the contents of a buffer changes, we update the generation count. This allows for our background highlighting thread to notice it and skip doing work that it would otherwise have to do. This variable should really be of some kind of interlocked or atomic type that guarantees we're not reading stale cache values. With C++11 we should use atomics, but until then volatile should work as well, at least on x86.*/ static volatile unsigned int s_generation_count; /* This pthreads generation count is set when an autosuggestion background thread starts up, so it can easily check if the work it is doing is no longer useful. */ @@ -671,7 +671,7 @@ int reader_reading_interrupted() return res; } -bool reader_cancel_thread() +bool reader_thread_job_is_stale() { ASSERT_IS_BACKGROUND_THREAD(); return (void*)(uintptr_t) s_generation_count != pthread_getspecific(generation_count_key); diff --git a/reader.h b/reader.h index f7cc7fdca..d0f878a30 100644 --- a/reader.h +++ b/reader.h @@ -137,10 +137,8 @@ int reader_reading_interrupted(); generation count the current thread was started with. Note 1: currently only valid for autocompletion threads! Other threads don't set the threadlocal generation count when they start up. - Note 2: This function uses conditional compilation for thread-local storage. - If the compiler doesn't support that this function always returns `false`. */ -bool reader_cancel_thread(); +bool reader_thread_job_is_stale(); /** Read one line of input. Before calling this function, reader_push() diff --git a/wildcard.cpp b/wildcard.cpp index b3d6e57aa..0673860b3 100644 --- a/wildcard.cpp +++ b/wildcard.cpp @@ -728,7 +728,7 @@ static int wildcard_expand_internal(const wchar_t *wc, // debug( 3, L"WILDCARD_EXPAND %ls in %ls", wc, base_dir ); - if (is_main_thread() ? reader_interrupted() : reader_cancel_thread()) + if (is_main_thread() ? reader_interrupted() : reader_thread_job_is_stale()) { return -1; }