Commit 366629ff authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

app/base/base.c moved some code from base_init() into tile_swap_init().

2005-02-13  Sven Neumann  <sven@gimp.org>

	* app/base/base.c
	* app/base/tile-swap.[ch]: moved some code from base_init() into
	tile_swap_init().

	* app/base/pixel-processor.[ch]: prepared for porting to GThreadPool.

	* app/config/gimpbaseconfig.c: changed "num-processors" option to
	require a confirmation before being changed.
parent 38f5524b
2005-02-13 Sven Neumann <sven@gimp.org>
* app/base/base.c
* app/base/tile-swap.[ch]: moved some code from base_init() into
tile_swap_init().
* app/base/pixel-processor.[ch]: prepared for porting to GThreadPool.
* app/config/gimpbaseconfig.c: changed "num-processors" option to
require a confirmation before being changed.
2005-02-13 Sven Neumann <sven@gimp.org>
* configure.in: check for gthread-2.0 unless the --disable-mp
......
......@@ -46,6 +46,7 @@
#include "composite/gimp-composite.h"
#include "base.h"
#include "pixel-processor.h"
#include "temp-buf.h"
#include "tile-cache.h"
#include "tile-swap.h"
......@@ -58,6 +59,9 @@ static void base_toast_old_temp_files (GimpBaseConfig *config);
static void base_tile_cache_size_notify (GObject *config,
GParamSpec *param_spec,
gpointer data);
static void base_num_processors_notify (GObject *config,
GParamSpec *param_spec,
gpointer data);
/* public functions */
......@@ -67,9 +71,6 @@ base_init (GimpBaseConfig *config,
gboolean be_verbose,
gboolean use_cpu_accel)
{
gchar *swapfile;
gchar *swapdir;
gchar *path;
gboolean swap_is_ok;
g_return_val_if_fail (GIMP_IS_BASE_CONFIG (config), FALSE);
......@@ -78,7 +79,6 @@ base_init (GimpBaseConfig *config,
base_config = g_object_ref (config);
tile_cache_init (config->tile_cache_size);
g_signal_connect (config, "notify::tile-cache-size",
G_CALLBACK (base_tile_cache_size_notify),
NULL);
......@@ -89,20 +89,15 @@ base_init (GimpBaseConfig *config,
if (! config->swap_path)
g_object_set (config, "swap_path", "${gimp_dir}", NULL);
swapdir = gimp_config_path_expand (config->swap_path, TRUE, NULL);
swapfile = g_strdup_printf ("gimpswap.%lu", (unsigned long) getpid ());
path = g_build_filename (swapdir, swapfile, NULL);
g_free (swapfile);
g_free (swapdir);
tile_swap_add (path, NULL, NULL);
g_free (path);
tile_swap_init (config->swap_path);
swap_is_ok = tile_swap_test ();
pixel_processor_init (config->num_processors);
g_signal_connect (config, "notify::num_processors",
G_CALLBACK (base_num_processors_notify),
NULL);
gimp_composite_init (be_verbose, use_cpu_accel);
paint_funcs_setup ();
......@@ -115,6 +110,7 @@ base_exit (void)
{
g_return_if_fail (base_config != NULL);
pixel_processor_exit ();
swapping_free ();
paint_funcs_free ();
tile_swap_exit ();
......@@ -192,3 +188,11 @@ base_tile_cache_size_notify (GObject *config,
{
tile_cache_set_size (GIMP_BASE_CONFIG (config)->tile_cache_size);
}
static void
base_num_processors_notify (GObject *config,
GParamSpec *param_spec,
gpointer data)
{
pixel_processor_set_num_threads (GIMP_BASE_CONFIG (config)->num_processors);
}
......@@ -37,10 +37,7 @@
#include "tile.h"
#endif
#ifdef __GNUC__
#warning FIXME: extern GimpBaseConfig *base_config;
#endif
extern GimpBaseConfig *base_config;
static gint num_threads = 0;
typedef void (* p1_func) (gpointer data,
......@@ -223,7 +220,7 @@ static void
pixel_regions_do_parallel (PixelProcessor *processor)
{
#ifdef ENABLE_MP
gint nthreads = MIN (base_config->num_processors, MAX_THREADS);
gint nthreads = MIN (num_threads, MAX_THREADS);
/* make sure we have at least one tile per thread */
nthreads = MIN (nthreads,
......@@ -330,6 +327,24 @@ pixel_regions_process_parallel_valist (PixelProcessorFunc func,
#endif
}
void
pixel_processor_init (gint num_threads)
{
num_threads = MAX (num_threads, MAX_THREADS);
}
void
pixel_processor_set_num_threads (gint num_threads)
{
num_threads = MAX (num_threads, MAX_THREADS);
}
void
pixel_processor_exit (void)
{
num_threads = 0;
}
void
pixel_regions_process_parallel (PixelProcessorFunc func,
gpointer data,
......
......@@ -25,10 +25,14 @@
typedef void (* PixelProcessorFunc) (void);
void pixel_regions_process_parallel (PixelProcessorFunc func,
gpointer data,
gint num_regions,
...);
void pixel_processor_init (gint num_threads);
void pixel_processor_set_num_threads (gint num_threads);
void pixel_processor_exit (void);
void pixel_regions_process_parallel (PixelProcessorFunc func,
gpointer data,
gint num_regions,
...);
#endif /* __PIXEL_PROCESSOR_H__ */
......@@ -34,6 +34,7 @@
#include <glib/gstdio.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpconfig/gimpconfig.h"
#ifdef G_OS_WIN32
#include "libgimpbase/gimpwin32-io.h"
......@@ -91,7 +92,6 @@ struct _AsyncSwapArgs
};
static void tile_swap_init (void);
static guint tile_swap_hash (gint *key);
static gint tile_swap_compare (gint *a,
gint *b);
......@@ -129,7 +129,7 @@ static gpointer tile_swap_in_thread (gpointer);
#endif
static gboolean initialize = TRUE;
static gboolean initialized = FALSE;
static GHashTable * swap_files = NULL;
static GList * open_swap_files = NULL;
static gint nopen_swap_files = 0;
......@@ -208,9 +208,43 @@ tile_swap_exit1 (gpointer key,
}
}
void
tile_swap_init (const gchar *path)
{
gchar *swapfile;
gchar *swapdir;
gchar *swappath;
g_return_if_fail (path != NULL);
g_return_if_fail (! initialized);
initialized = TRUE;
swap_files = g_hash_table_new ((GHashFunc) tile_swap_hash,
(GCompareFunc) tile_swap_compare);
swapdir = gimp_config_path_expand (path, TRUE, NULL);
swapfile = g_strdup_printf ("gimpswap.%lu", (unsigned long) getpid ());
swappath = g_build_filename (swapdir, swapfile, NULL);
g_free (swapfile);
g_free (swapdir);
tile_swap_add (swappath, NULL, NULL);
g_free (swappath);
#ifdef NOTDEF /* USE_PTHREADS */
pthread_create (&swapin_thread, NULL, &tile_swap_in_thread, NULL);
#endif
}
void
tile_swap_exit (void)
{
g_return_if_fail (initialized);
#ifdef HINTS_SANITY
extern int tile_exist_peak;
......@@ -220,6 +254,8 @@ tile_swap_exit (void)
if (swap_files)
g_hash_table_foreach (swap_files, tile_swap_exit1, NULL);
initialized = FALSE;
}
gint
......@@ -234,8 +270,7 @@ tile_swap_add (gchar *filename,
pthread_mutex_lock(&swapfile_mutex);
#endif
if (initialize)
tile_swap_init ();
g_return_val_if_fail (initialized, -1);
swap_file = g_new (SwapFile, 1);
swap_file->filename = g_strdup (filename);
......@@ -271,11 +306,10 @@ tile_swap_remove (gint swap_num)
SwapFile *swap_file;
#ifdef USE_PTHREADS
pthread_mutex_lock(&swapfile_mutex);
pthread_mutex_lock (&swapfile_mutex);
#endif
if (initialize)
tile_swap_init ();
g_return_if_fail (initialized);
swap_file = g_hash_table_lookup (swap_files, &swap_num);
if (!swap_file)
......@@ -340,7 +374,8 @@ tile_swap_test (void)
SwapFile *swap_file;
int swap_num = 1;
g_assert (initialize == FALSE);
g_return_val_if_fail (initialized, FALSE);
swap_file = g_hash_table_lookup (swap_files, &swap_num);
g_assert (swap_file->fd == -1);
......@@ -354,29 +389,13 @@ tile_swap_test (void)
close (swap_file->fd);
swap_file->fd = -1;
g_unlink (swap_file->filename);
return TRUE;
}
return FALSE;
}
static void
tile_swap_init (void)
{
if (initialize)
{
initialize = FALSE;
swap_files = g_hash_table_new ((GHashFunc) tile_swap_hash,
(GCompareFunc) tile_swap_compare);
#ifdef NOTDEF /* USE_PTHREADS */
pthread_create (&swapin_thread, NULL, &tile_swap_in_thread, NULL);
#endif
}
}
static guint
tile_swap_hash (gint *key)
{
......@@ -399,8 +418,7 @@ tile_swap_command (Tile *tile,
pthread_mutex_lock(&swapfile_mutex);
#endif
if (initialize)
tile_swap_init ();
g_return_if_fail (initialized);
do {
swap_file = g_hash_table_lookup (swap_files, &tile->swap_num);
......
......@@ -36,16 +36,17 @@ typedef gint (* SwapFunc) (gint fd,
gpointer user_data);
void tile_swap_init (const gchar *path);
void tile_swap_exit (void);
gint tile_swap_add (gchar *filename,
SwapFunc swap_func,
gpointer user_data);
void tile_swap_remove (gint swap_num);
void tile_swap_in (Tile *tile);
void tile_swap_in_async (Tile *tile);
void tile_swap_out (Tile *tile);
void tile_swap_delete (Tile *tile);
void tile_swap_compress (gint swap_num);
gint tile_swap_add (gchar *filename,
SwapFunc swap_func,
gpointer user_data);
void tile_swap_remove (gint swap_num);
void tile_swap_in (Tile *tile);
void tile_swap_in_async (Tile *tile);
void tile_swap_out (Tile *tile);
void tile_swap_delete (Tile *tile);
void tile_swap_compress (gint swap_num);
gboolean tile_swap_test (void);
......
......@@ -118,7 +118,7 @@ gimp_base_config_class_init (GimpBaseConfigClass *klass)
GIMP_CONFIG_INSTALL_PROP_UINT (object_class, PROP_NUM_PROCESSORS,
"num-processors", NUM_PROCESSORS_BLURB,
1, 16, 2,
0);
GIMP_CONFIG_PARAM_CONFIRM);
GIMP_CONFIG_INSTALL_PROP_MEMSIZE (object_class, PROP_TILE_CACHE_SIZE,
"tile-cache-size", TILE_CACHE_SIZE_BLURB,
0, GIMP_MAX_MEMSIZE, 1 << 28, /* 256MB */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment