summaryrefslogtreecommitdiff
path: root/apps/tagcache.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/tagcache.c')
-rw-r--r--apps/tagcache.c42
1 files changed, 27 insertions, 15 deletions
diff --git a/apps/tagcache.c b/apps/tagcache.c
index efa615675e..3d84b4ca89 100644
--- a/apps/tagcache.c
+++ b/apps/tagcache.c
@@ -81,6 +81,7 @@
81#include <ctype.h> 81#include <ctype.h>
82#define yield() do { } while(0) 82#define yield() do { } while(0)
83#define sim_sleep(timeout) do { } while(0) 83#define sim_sleep(timeout) do { } while(0)
84#define do_timed_yield() do { } while(0)
84#endif 85#endif
85 86
86 87
@@ -306,12 +307,26 @@ static int open_tag_fd(struct tagcache_header *hdr, int tag, bool write)
306 return fd; 307 return fd;
307} 308}
308 309
310#ifndef __PCTOOL__
311static bool do_timed_yield(void)
312{
313 /* Sorting can lock up for quite a while, so yield occasionally */
314 static long wakeup_tick = 0;
315 if (current_tick >= wakeup_tick)
316 {
317 wakeup_tick = current_tick + (HZ/4);
318 yield();
319 return true;
320 }
321 return false;
322}
323#endif
324
309#if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE) 325#if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE)
310static long find_entry_ram(const char *filename, 326static long find_entry_ram(const char *filename,
311 const struct dircache_entry *dc) 327 const struct dircache_entry *dc)
312{ 328{
313 static long last_pos = 0; 329 static long last_pos = 0;
314 int counter = 0;
315 int i; 330 int i;
316 331
317 /* Check if we tagcache is loaded into ram. */ 332 /* Check if we tagcache is loaded into ram. */
@@ -342,11 +357,7 @@ static long find_entry_ram(const char *filename,
342 return i; 357 return i;
343 } 358 }
344 359
345 if (++counter == 100) 360 do_timed_yield();
346 {
347 yield();
348 counter = 0;
349 }
350 } 361 }
351 362
352 if (last_pos > 0) 363 if (last_pos > 0)
@@ -1737,6 +1748,8 @@ static bool tempbuf_insert(char *str, int id, int idx_id, bool unique)
1737 1748
1738static int compare(const void *p1, const void *p2) 1749static int compare(const void *p1, const void *p2)
1739{ 1750{
1751 do_timed_yield();
1752
1740 struct tempbuf_searchidx *e1 = (struct tempbuf_searchidx *)p1; 1753 struct tempbuf_searchidx *e1 = (struct tempbuf_searchidx *)p1;
1741 struct tempbuf_searchidx *e2 = (struct tempbuf_searchidx *)p2; 1754 struct tempbuf_searchidx *e2 = (struct tempbuf_searchidx *)p2;
1742 1755
@@ -1790,6 +1803,8 @@ static int tempbuf_sort(int fd)
1790 idlist = idlist->next; 1803 idlist = idlist->next;
1791 idlist->id = i; 1804 idlist->id = i;
1792 idlist->next = NULL; 1805 idlist->next = NULL;
1806
1807 do_timed_yield();
1793 } 1808 }
1794 1809
1795 qsort(index, tempbufidx, sizeof(struct tempbuf_searchidx), compare); 1810 qsort(index, tempbufidx, sizeof(struct tempbuf_searchidx), compare);
@@ -2115,7 +2130,7 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd)
2115 close(fd); 2130 close(fd);
2116 return -3; 2131 return -3;
2117 } 2132 }
2118 yield(); 2133 do_timed_yield();
2119 } 2134 }
2120 logf("done"); 2135 logf("done");
2121 } 2136 }
@@ -2260,7 +2275,7 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd)
2260 /* Skip to next. */ 2275 /* Skip to next. */
2261 lseek(tmpfd, entry.data_length - entry.tag_offset[index_type] - 2276 lseek(tmpfd, entry.data_length - entry.tag_offset[index_type] -
2262 entry.tag_length[index_type], SEEK_CUR); 2277 entry.tag_length[index_type], SEEK_CUR);
2263 yield(); 2278 do_timed_yield();
2264 } 2279 }
2265 logf("done"); 2280 logf("done");
2266 2281
@@ -2312,7 +2327,7 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd)
2312 goto error_exit; 2327 goto error_exit;
2313 } 2328 }
2314 2329
2315 yield(); 2330 do_timed_yield();
2316 } 2331 }
2317 2332
2318 /* Write back the updated index. */ 2333 /* Write back the updated index. */
@@ -2431,7 +2446,7 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd)
2431 break ; 2446 break ;
2432 } 2447 }
2433 2448
2434 yield(); 2449 do_timed_yield();
2435 } 2450 }
2436 logf("done"); 2451 logf("done");
2437 2452
@@ -3016,7 +3031,7 @@ bool tagcache_create_changelog(struct tagcache_search *tcs)
3016 } 3031 }
3017 3032
3018 write(clfd, "\n", 1); 3033 write(clfd, "\n", 1);
3019 yield(); 3034 do_timed_yield();
3020 } 3035 }
3021 3036
3022 close(clfd); 3037 close(clfd);
@@ -3278,7 +3293,6 @@ static bool load_tagcache(void)
3278 int rc, fd; 3293 int rc, fd;
3279 char *p; 3294 char *p;
3280 int i, tag; 3295 int i, tag;
3281 int yield_count = 0;
3282 3296
3283# ifdef HAVE_DIRCACHE 3297# ifdef HAVE_DIRCACHE
3284 while (dircache_is_initializing()) 3298 while (dircache_is_initializing())
@@ -3355,13 +3369,11 @@ static bool load_tagcache(void)
3355 { 3369 {
3356 long pos; 3370 long pos;
3357 3371
3358 if (yield_count++ == 100) 3372 if (do_timed_yield())
3359 { 3373 {
3360 yield();
3361 /* Abort if we got a critical event in queue */ 3374 /* Abort if we got a critical event in queue */
3362 if (check_event_queue()) 3375 if (check_event_queue())
3363 return false; 3376 return false;
3364 yield_count = 0;
3365 } 3377 }
3366 3378
3367 fe = (struct tagfile_entry *)p; 3379 fe = (struct tagfile_entry *)p;