* viking -- GPS Data and Topo Analyzer, Explorer, and Manager
*
* Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
+ * Copyright (c) 2015, Rob Norris <rw_norris@hotmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "background.h"
#include "settings.h"
+#include "util.h"
-static GThreadPool *thread_pool = NULL;
+static GThreadPool *thread_pool_remote = NULL;
+static GThreadPool *thread_pool_local = NULL;
static gboolean stop_all_threads = FALSE;
static GtkWidget *bgwindow = NULL;
/**
* a_background_thread:
+ * @bp: Which pool this thread should run in
* @parent:
* @message:
* @func: worker function
*
* Function to enlist new background function.
*/
-void a_background_thread ( GtkWindow *parent, const gchar *message, vik_thr_func func, gpointer userdata, vik_thr_free_func userdata_free_func, vik_thr_free_func userdata_cancel_cleanup_func, gint number_items )
+void a_background_thread ( Background_Pool_Type bp, GtkWindow *parent, const gchar *message, vik_thr_func func, gpointer userdata, vik_thr_free_func userdata_free_func, vik_thr_free_func userdata_cancel_cleanup_func, gint number_items )
{
GtkTreeIter *piter = g_malloc ( sizeof ( GtkTreeIter ) );
gpointer *args = g_malloc ( sizeof(gpointer) * VIK_BG_NUM_ARGS );
-1 );
/* run the thread in the background */
- g_thread_pool_push( thread_pool, args, NULL );
+ if ( bp == BACKGROUND_POOL_REMOTE )
+ g_thread_pool_push( thread_pool_remote, args, NULL );
+ else
+ g_thread_pool_push( thread_pool_local, args, NULL );
}
/**
}
#define VIK_SETTINGS_BACKGROUND_MAX_THREADS "background_max_threads"
+#define VIK_SETTINGS_BACKGROUND_MAX_THREADS_LOCAL "background_max_threads_local"
/**
* a_background_init:
*/
void a_background_init()
{
- /* initialize thread pool */
+ // initialize thread pools
gint max_threads = 10; /* limit maximum number of threads running at one time */
gint maxt;
if ( a_settings_get_integer ( VIK_SETTINGS_BACKGROUND_MAX_THREADS, &maxt ) )
max_threads = maxt;
- thread_pool = g_thread_pool_new ( (GFunc) thread_helper, NULL, max_threads, FALSE, NULL );
+ thread_pool_remote = g_thread_pool_new ( (GFunc) thread_helper, NULL, max_threads, FALSE, NULL );
+
+ if ( a_settings_get_integer ( VIK_SETTINGS_BACKGROUND_MAX_THREADS_LOCAL, &maxt ) )
+ max_threads = maxt;
+ else {
+ guint cpus = util_get_number_of_cpus ();
+ max_threads = cpus > 1 ? cpus-1 : 1; // Don't use all available CPUs!
+ }
+
+ thread_pool_local = g_thread_pool_new ( (GFunc) thread_helper, NULL, max_threads, FALSE, NULL );
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
*/
void a_background_uninit()
{
- /* wait until all running threads stop */
stop_all_threads = TRUE;
- g_thread_pool_free ( thread_pool, TRUE, TRUE );
+ // wait until these threads stop
+ g_thread_pool_free ( thread_pool_remote, TRUE, TRUE );
+ // Don't wait for these
+ g_thread_pool_free ( thread_pool_local, TRUE, FALSE );
gtk_list_store_clear ( bgstore );
g_object_unref ( bgstore );