pull-local: Make multithreaded

We were blocking for easily 1/10 or 1/5 of a second in fdatasync(),
which drastically slows down the whole process.

This threading isn't quite as good as the ostree-pull command, but it
lets us avoid the dependency on libsoup everywhere, and it's simpler.
This commit is contained in:
Colin Walters committed 2012-11-19 12:08:41 -05:00
1 parent de1ce843f1
commit 05e7b6d596
3 files changed
+124 -43

No files matched your search

+22
View File
@@ -56,3 +56,25 @@ ot_spawn_sync_checked (const char *cwd,
out:
return ret;
}
/**
* ot_thread_pool_new_nproc:
*
* Like g_thread_pool_new (), but choose number of threads appropriate
* for CPU bound workers automatically. Also aborts on error.
*/
GThreadPool *
ot_thread_pool_new_nproc (GFunc func,
gpointer user_data)
{
long nproc_onln;
GThreadPool *ret;
GError *local_error = NULL;
nproc_onln = sysconf (_SC_NPROCESSORS_ONLN);
if (G_UNLIKELY (nproc_onln == -1 && errno == EINVAL))
nproc_onln = 2;
ret = g_thread_pool_new (func, user_data, (int)nproc_onln, FALSE, &local_error);
g_assert_no_error (local_error);
return ret;
}
+4
View File
@@ -37,6 +37,10 @@ gboolean ot_spawn_sync_checked (const char *cwd,
char **stderr_data,
GError **error);
GThreadPool * ot_thread_pool_new_nproc (GFunc func,
gpointer user_data);
G_END_DECLS
#endif