Last active
December 20, 2015 16:39
-
-
Save elwertk/6163092 to your computer and use it in GitHub Desktop.
[PATCH] limit filescanner concurrency based on available file descriptors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 9036ccc8df149916b395226ca141181eb6554144 Mon Sep 17 00:00:00 2001 | |
From: Kai Elwert <elwertk@googlemail.com> | |
Date: Tue, 6 Aug 2013 10:21:37 +0200 | |
Subject: [PATCH] limit filescanner concurrency based on available file | |
descriptors | |
--- | |
src/filescanner.c | 12 +++++++++++- | |
1 file changed, 11 insertions(+), 1 deletion(-) | |
diff --git a/src/filescanner.c b/src/filescanner.c | |
index cefecbd..615f533 100644 | |
--- a/src/filescanner.c | |
+++ b/src/filescanner.c | |
@@ -64,6 +64,7 @@ static dispatch_group_t scanner_grp; | |
static dispatch_queue_t deferred_pl_sq; | |
static int ino_fd; | |
static dispatch_source_t ino_src; | |
+static dispatch_semaphore_t semaphore; | |
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) | |
@@ -702,6 +703,7 @@ process_directory_async(char *path, int flags) | |
} | |
} | |
+ dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); | |
dispatch_group_async(scanner_grp, dispatch_get_current_queue(), | |
^{ | |
int ret; | |
@@ -725,6 +727,7 @@ process_directory_async(char *path, int flags) | |
free(my_path); | |
db_pool_release(); | |
+ dispatch_semaphore_signal(semaphore); | |
}); | |
} | |
@@ -1385,6 +1388,13 @@ filescanner_init(void) | |
goto source_fail; | |
} | |
+ semaphore = dispatch_semaphore_create(getdtablesize() / 4); | |
+ if (!semaphore) | |
+ { | |
+ DPRINTF(E_FATAL, L_SCAN, "Could not get global dispatch queue\n"); | |
+ | |
+ goto source_fail; | |
+ } | |
ino_src = dispatch_source_create(DISPATCH_SOURCE_TYPE_READ, ino_fd, 0, global_q); | |
if (!ino_src) | |
@@ -1457,9 +1467,9 @@ filescanner_deinit(void) | |
ret = dispatch_group_wait(scanner_grp, DISPATCH_TIME_FOREVER); | |
dispatch_release(scanner_grp); | |
+ dispatch_release(semaphore); | |
if (ret != 0) | |
DPRINTF(E_LOG, L_SCAN, "Error waiting for dispatch group\n"); | |
- | |
/* deferred_pl_sq resumed & released after completion of the bulk scan */ | |
} | |
-- | |
1.7.10.4 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment