aboutsummaryrefslogtreecommitdiffhomepage
path: root/reader.cpp
diff options
context:
space:
mode:
authorGravatar Jan Kanis <jan.code@jankanis.nl>2013-01-23 00:19:29 +0100
committerGravatar Jan Kanis <jan.code@jankanis.nl>2013-01-23 00:19:29 +0100
commit70a75dc88aad2beb9c0007eba4af5154ebe58c8d (patch)
treeaac6312e20df58a7715385238c5cc18f768c69ac /reader.cpp
parentb6bd6e399d97fb107bb05bc16df6ff32fb2f6877 (diff)
implement reader_cancel_thread using __thread thread-local storage
Diffstat (limited to 'reader.cpp')
-rw-r--r--reader.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/reader.cpp b/reader.cpp
index 07d58a31..8fe3a66d 100644
--- a/reader.cpp
+++ b/reader.cpp
@@ -181,7 +181,10 @@ 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. */
-static unsigned int s_generation_count;
+static volatile unsigned int s_generation_count;
+
+/* This threadlocal 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. */
+static __thread unsigned int thread_generation_count;
/* A color is an int */
typedef int color_t;
@@ -667,6 +670,12 @@ int reader_reading_interrupted()
return res;
}
+bool reader_cancel_thread()
+{
+ ASSERT_IS_BACKGROUND_THREAD();
+ return s_generation_count != thread_generation_count;
+}
+
void reader_write_title()
{
const wchar_t *title;
@@ -1225,6 +1234,8 @@ struct autosuggestion_context_t
return 0;
}
+ thread_generation_count = generation_count;
+
/* Let's make sure we aren't using the empty string */
if (search_string.empty())
{