diff options
author | dormando <dormando@rydia.net> | 2015-11-19 15:26:13 -0800 |
---|---|---|
committer | dormando <dormando@rydia.net> | 2015-11-19 15:43:32 -0800 |
commit | b6bf6df77c7860c42ff35c4a4f6a6b79db472f82 (patch) | |
tree | dbac4176f36c1ab03cca87314ccbdb44e42b113e | |
parent | ec937e5ed1cdc3019f0ae5f2c362110ea54450d1 (diff) | |
download | memcached-b6bf6df77c7860c42ff35c4a4f6a6b79db472f82.tar.gz |
'lru_crawler enable' blocks until ready
single CPU VM builders could fail:
- spawn LRU crawler thread.
- signal LRU crawler.
- LRU crawler thread now waits on condition.
- Crawler thread misses condition, sits forever.
Might also want to move the "stats.lru_crawler_running" bit to be updated when
the crawler thread picks up the work to do, somehow.
-rw-r--r-- | items.c | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -1237,6 +1237,8 @@ static void *item_crawler_thread(void *arg) { int crawls_persleep = settings.crawls_persleep; pthread_mutex_lock(&lru_crawler_lock); + pthread_cond_signal(&lru_crawler_cond); + settings.lru_crawler = true; if (settings.verbose > 2) fprintf(stderr, "Starting LRU crawler background thread\n"); while (do_run_lru_crawler_thread) { @@ -1329,6 +1331,17 @@ int stop_item_crawler_thread(void) { return 0; } +/* Lock dance to "block" until thread is waiting on its condition: + * caller locks mtx. caller spawns thread. + * thread blocks on mutex. + * caller waits on condition, releases lock. + * thread gets lock, sends signal. + * caller can't wait, as thread has lock. + * thread waits on condition, releases lock + * caller wakes on condition, gets lock. + * caller immediately releases lock. + * thread is now safely waiting on condition before the caller returns. + */ int start_item_crawler_thread(void) { int ret; @@ -1336,7 +1349,6 @@ int start_item_crawler_thread(void) { return -1; pthread_mutex_lock(&lru_crawler_lock); do_run_lru_crawler_thread = 1; - settings.lru_crawler = true; if ((ret = pthread_create(&item_crawler_tid, NULL, item_crawler_thread, NULL)) != 0) { fprintf(stderr, "Can't create LRU crawler thread: %s\n", @@ -1344,6 +1356,8 @@ int start_item_crawler_thread(void) { pthread_mutex_unlock(&lru_crawler_lock); return -1; } + /* Avoid returning until the crawler has actually started */ + pthread_cond_wait(&lru_crawler_cond, &lru_crawler_lock); pthread_mutex_unlock(&lru_crawler_lock); return 0; |