mirror of https://github.com/GNOME/gimp.git
app/base/base-config.[ch] use a gulong for the tile_cache_size.
2002-05-28 Sven Neumann <sven@gimp.org> * app/base/base-config.[ch] * app/gui/user-install-dialog.c: use a gulong for the tile_cache_size. * app/base/tile-cache.c: cleanup, no changes. * app/config/gimpconfig-types.c (string_to_memsize): avoid overflows.
This commit is contained in:
parent
6707e317d1
commit
d453d02362
|
@ -1,3 +1,12 @@
|
||||||
|
2002-05-28 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
|
* app/base/base-config.[ch]
|
||||||
|
* app/gui/user-install-dialog.c: use a gulong for the tile_cache_size.
|
||||||
|
|
||||||
|
* app/base/tile-cache.c: cleanup, no changes.
|
||||||
|
|
||||||
|
* app/config/gimpconfig-types.c (string_to_memsize): avoid overflows.
|
||||||
|
|
||||||
2002-05-28 Michael Natterer <mitch@gimp.org>
|
2002-05-28 Michael Natterer <mitch@gimp.org>
|
||||||
|
|
||||||
Yes, this is a bit hackish...
|
Yes, this is a bit hackish...
|
||||||
|
|
|
@ -36,7 +36,7 @@ static GimpBaseConfig static_base_config =
|
||||||
INIT_MEMBER(temp_path , NULL),
|
INIT_MEMBER(temp_path , NULL),
|
||||||
INIT_MEMBER(swap_path , NULL),
|
INIT_MEMBER(swap_path , NULL),
|
||||||
|
|
||||||
INIT_MEMBER(tile_cache_size , 33554432),
|
INIT_MEMBER(tile_cache_size , 1 << 25),
|
||||||
INIT_MEMBER(stingy_memory_use, FALSE),
|
INIT_MEMBER(stingy_memory_use, FALSE),
|
||||||
INIT_MEMBER(num_processors , 1)
|
INIT_MEMBER(num_processors , 1)
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,7 +26,7 @@ struct _GimpBaseConfig
|
||||||
{
|
{
|
||||||
gchar *temp_path;
|
gchar *temp_path;
|
||||||
gchar *swap_path;
|
gchar *swap_path;
|
||||||
guint tile_cache_size;
|
gulong tile_cache_size;
|
||||||
gboolean stingy_memory_use;
|
gboolean stingy_memory_use;
|
||||||
gint num_processors;
|
gint num_processors;
|
||||||
};
|
};
|
||||||
|
|
|
@ -60,18 +60,18 @@ typedef struct _TileList
|
||||||
Tile *last;
|
Tile *last;
|
||||||
} TileList;
|
} TileList;
|
||||||
|
|
||||||
static gulong max_tile_size = TILE_WIDTH * TILE_HEIGHT * 4;
|
static gulong max_tile_size = TILE_WIDTH * TILE_HEIGHT * 4;
|
||||||
static gulong cur_cache_size = 0;
|
static gulong cur_cache_size = 0;
|
||||||
static gulong max_cache_size = 0;
|
static gulong max_cache_size = 0;
|
||||||
static gulong cur_cache_dirty = 0;
|
static gulong cur_cache_dirty = 0;
|
||||||
static TileList clean_list = { NULL, NULL };
|
static TileList clean_list = { NULL, NULL };
|
||||||
static TileList dirty_list = { NULL, NULL };
|
static TileList dirty_list = { NULL, NULL };
|
||||||
|
|
||||||
#ifdef USE_PTHREADS
|
#ifdef USE_PTHREADS
|
||||||
static pthread_t preswap_thread;
|
static pthread_t preswap_thread;
|
||||||
static pthread_mutex_t dirty_mutex = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t dirty_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
static pthread_cond_t dirty_signal = PTHREAD_COND_INITIALIZER;
|
static pthread_cond_t dirty_signal = PTHREAD_COND_INITIALIZER;
|
||||||
static pthread_mutex_t tile_mutex = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t tile_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
#define CACHE_LOCK pthread_mutex_lock(&tile_mutex)
|
#define CACHE_LOCK pthread_mutex_lock(&tile_mutex)
|
||||||
#define CACHE_UNLOCK pthread_mutex_unlock(&tile_mutex)
|
#define CACHE_UNLOCK pthread_mutex_unlock(&tile_mutex)
|
||||||
#else
|
#else
|
||||||
|
@ -99,8 +99,10 @@ tile_cache_insert (Tile *tile)
|
||||||
* it was the most recently accessed tile.
|
* it was the most recently accessed tile.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
list = (TileList*)(tile->listhead);
|
list = (TileList *) tile->listhead;
|
||||||
newlist = (tile->dirty || tile->swap_offset == -1) ? &dirty_list : &clean_list;
|
|
||||||
|
newlist = ((tile->dirty || tile->swap_offset == -1) ?
|
||||||
|
&dirty_list : &clean_list);
|
||||||
|
|
||||||
/* if list is NULL, the tile is not in the cache */
|
/* if list is NULL, the tile is not in the cache */
|
||||||
|
|
||||||
|
@ -120,7 +122,9 @@ tile_cache_insert (Tile *tile)
|
||||||
list->first = tile->next;
|
list->first = tile->next;
|
||||||
|
|
||||||
tile->listhead = NULL;
|
tile->listhead = NULL;
|
||||||
if (list == &dirty_list) cur_cache_dirty -= tile_size (tile);
|
|
||||||
|
if (list == &dirty_list)
|
||||||
|
cur_cache_dirty -= tile_size (tile);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -154,8 +158,11 @@ tile_cache_insert (Tile *tile)
|
||||||
tile->prev = newlist->last;
|
tile->prev = newlist->last;
|
||||||
tile->listhead = newlist;
|
tile->listhead = newlist;
|
||||||
|
|
||||||
if (newlist->last) newlist->last->next = tile;
|
if (newlist->last)
|
||||||
else newlist->first = tile;
|
newlist->last->next = tile;
|
||||||
|
else
|
||||||
|
newlist->first = tile;
|
||||||
|
|
||||||
newlist->last = tile;
|
newlist->last = tile;
|
||||||
|
|
||||||
/* gosgood@idt.net 1999-12-04 */
|
/* gosgood@idt.net 1999-12-04 */
|
||||||
|
@ -163,9 +170,10 @@ tile_cache_insert (Tile *tile)
|
||||||
/* Invariant: test for selecting dirty list should be the same */
|
/* Invariant: test for selecting dirty list should be the same */
|
||||||
/* as counting files dirty. */
|
/* as counting files dirty. */
|
||||||
|
|
||||||
if ((tile->dirty) || ( tile->swap_offset == -1))
|
if (tile->dirty || (tile->swap_offset == -1))
|
||||||
{
|
{
|
||||||
cur_cache_dirty += tile_size (tile);
|
cur_cache_dirty += tile_size (tile);
|
||||||
|
|
||||||
if (1)
|
if (1)
|
||||||
{
|
{
|
||||||
#ifdef USE_PTHREADS
|
#ifdef USE_PTHREADS
|
||||||
|
@ -199,7 +207,7 @@ tile_cache_flush_internal (Tile *tile)
|
||||||
/* Find where the tile is in the cache.
|
/* Find where the tile is in the cache.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
list = (TileList*)(tile->listhead);
|
list = (TileList *) tile->listhead;
|
||||||
|
|
||||||
if (list)
|
if (list)
|
||||||
{
|
{
|
||||||
|
@ -207,7 +215,9 @@ tile_cache_flush_internal (Tile *tile)
|
||||||
* is referencing.
|
* is referencing.
|
||||||
*/
|
*/
|
||||||
cur_cache_size -= tile_size (tile);
|
cur_cache_size -= tile_size (tile);
|
||||||
if (list == &dirty_list) cur_cache_dirty -= tile_size (tile);
|
|
||||||
|
if (list == &dirty_list)
|
||||||
|
cur_cache_dirty -= tile_size (tile);
|
||||||
|
|
||||||
if (tile->next)
|
if (tile->next)
|
||||||
tile->next->prev = tile->prev;
|
tile->next->prev = tile->prev;
|
||||||
|
@ -334,7 +344,8 @@ tile_idle_thread (gpointer data)
|
||||||
{
|
{
|
||||||
list = tile->listhead;
|
list = tile->listhead;
|
||||||
|
|
||||||
if (list == &dirty_list) cur_cache_dirty -= tile_size (tile);
|
if (list == &dirty_list)
|
||||||
|
cur_cache_dirty -= tile_size (tile);
|
||||||
|
|
||||||
if (tile->next)
|
if (tile->next)
|
||||||
tile->next->prev = tile->prev;
|
tile->next->prev = tile->prev;
|
||||||
|
@ -350,9 +361,12 @@ tile_idle_thread (gpointer data)
|
||||||
tile->prev = clean_list.last;
|
tile->prev = clean_list.last;
|
||||||
tile->listhead = &clean_list;
|
tile->listhead = &clean_list;
|
||||||
|
|
||||||
if (clean_list.last) clean_list.last->next = tile;
|
if (clean_list.last)
|
||||||
else clean_list.first = tile;
|
clean_list.last->next = tile;
|
||||||
clean_list.last = tile;
|
else
|
||||||
|
clean_list.first = tile;
|
||||||
|
|
||||||
|
clean_list.last = tile;
|
||||||
|
|
||||||
CACHE_UNLOCK;
|
CACHE_UNLOCK;
|
||||||
|
|
||||||
|
@ -373,15 +387,19 @@ tile_idle_thread (gpointer data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else /* !USE_PTHREADS */
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
tile_idle_preswap (gpointer data)
|
tile_idle_preswap (gpointer data)
|
||||||
{
|
{
|
||||||
Tile *tile;
|
Tile *tile;
|
||||||
if (cur_cache_dirty*2 < max_cache_size) return TRUE;
|
|
||||||
if ((tile = dirty_list.first))
|
if (cur_cache_dirty*2 < max_cache_size)
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
if ((tile = dirty_list.first))
|
||||||
{
|
{
|
||||||
tile_swap_out(tile);
|
tile_swap_out (tile);
|
||||||
|
|
||||||
dirty_list.first = tile->next;
|
dirty_list.first = tile->next;
|
||||||
if (tile->next)
|
if (tile->next)
|
||||||
|
@ -392,8 +410,12 @@ tile_idle_preswap (gpointer data)
|
||||||
tile->next = NULL;
|
tile->next = NULL;
|
||||||
tile->prev = clean_list.last;
|
tile->prev = clean_list.last;
|
||||||
tile->listhead = &clean_list;
|
tile->listhead = &clean_list;
|
||||||
if (clean_list.last) clean_list.last->next = tile;
|
|
||||||
else clean_list.first = tile;
|
if (clean_list.last)
|
||||||
|
clean_list.last->next = tile;
|
||||||
|
else
|
||||||
|
clean_list.first = tile;
|
||||||
|
|
||||||
clean_list.last = tile;
|
clean_list.last = tile;
|
||||||
cur_cache_dirty -= tile_size (tile);
|
cur_cache_dirty -= tile_size (tile);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include <glib-object.h>
|
#include <glib-object.h>
|
||||||
|
|
||||||
|
@ -166,7 +167,8 @@ string_to_memsize (const GValue *src_value,
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
size = strtoul (str, &end, 0);
|
size = strtoul (str, &end, 0);
|
||||||
if (size == ULONG_MAX)
|
|
||||||
|
if (size == ULONG_MAX && errno == ERANGE)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (end && *end)
|
if (end && *end)
|
||||||
|
@ -190,8 +192,17 @@ string_to_memsize (const GValue *src_value,
|
||||||
default:
|
default:
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* protect against overflow */
|
||||||
|
if (shift)
|
||||||
|
{
|
||||||
|
gulong limit = G_MAXULONG >> (shift);
|
||||||
|
|
||||||
size <<= shift;
|
if (size != (size & limit))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
size <<= shift;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_value_set_ulong (dest_value, size);
|
g_value_set_ulong (dest_value, size);
|
||||||
|
@ -199,6 +210,7 @@ string_to_memsize (const GValue *src_value,
|
||||||
return;
|
return;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
g_value_set_ulong (dest_value, 0);
|
||||||
g_warning ("Can't convert string to GimpMemsize.");
|
g_warning ("Can't convert string to GimpMemsize.");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1128,7 +1128,7 @@ user_install_tuning (void)
|
||||||
gtk_widget_show (hbox);
|
gtk_widget_show (hbox);
|
||||||
|
|
||||||
tile_cache_adj = gtk_adjustment_new (base_config->tile_cache_size,
|
tile_cache_adj = gtk_adjustment_new (base_config->tile_cache_size,
|
||||||
0, (4069.0 * 1024 * 1024), 1.0, 1.0, 0.0);
|
0, G_MAXULONG, 1.0, 1.0, 0.0);
|
||||||
memsize = gimp_mem_size_entry_new (GTK_ADJUSTMENT (tile_cache_adj));
|
memsize = gimp_mem_size_entry_new (GTK_ADJUSTMENT (tile_cache_adj));
|
||||||
gtk_box_pack_end (GTK_BOX (hbox), memsize, FALSE, FALSE, 0);
|
gtk_box_pack_end (GTK_BOX (hbox), memsize, FALSE, FALSE, 0);
|
||||||
gtk_widget_show (memsize);
|
gtk_widget_show (memsize);
|
||||||
|
@ -1310,7 +1310,7 @@ user_install_resolution_done (void)
|
||||||
GList *update = NULL;
|
GList *update = NULL;
|
||||||
GList *remove = NULL;
|
GList *remove = NULL;
|
||||||
|
|
||||||
gint new_tile_cache_size;
|
gulong new_tile_cache_size;
|
||||||
gchar *new_swap_path;
|
gchar *new_swap_path;
|
||||||
gboolean new_using_xserver_resolution;
|
gboolean new_using_xserver_resolution;
|
||||||
gdouble new_monitor_xres;
|
gdouble new_monitor_xres;
|
||||||
|
|
|
@ -1128,7 +1128,7 @@ user_install_tuning (void)
|
||||||
gtk_widget_show (hbox);
|
gtk_widget_show (hbox);
|
||||||
|
|
||||||
tile_cache_adj = gtk_adjustment_new (base_config->tile_cache_size,
|
tile_cache_adj = gtk_adjustment_new (base_config->tile_cache_size,
|
||||||
0, (4069.0 * 1024 * 1024), 1.0, 1.0, 0.0);
|
0, G_MAXULONG, 1.0, 1.0, 0.0);
|
||||||
memsize = gimp_mem_size_entry_new (GTK_ADJUSTMENT (tile_cache_adj));
|
memsize = gimp_mem_size_entry_new (GTK_ADJUSTMENT (tile_cache_adj));
|
||||||
gtk_box_pack_end (GTK_BOX (hbox), memsize, FALSE, FALSE, 0);
|
gtk_box_pack_end (GTK_BOX (hbox), memsize, FALSE, FALSE, 0);
|
||||||
gtk_widget_show (memsize);
|
gtk_widget_show (memsize);
|
||||||
|
@ -1310,7 +1310,7 @@ user_install_resolution_done (void)
|
||||||
GList *update = NULL;
|
GList *update = NULL;
|
||||||
GList *remove = NULL;
|
GList *remove = NULL;
|
||||||
|
|
||||||
gint new_tile_cache_size;
|
gulong new_tile_cache_size;
|
||||||
gchar *new_swap_path;
|
gchar *new_swap_path;
|
||||||
gboolean new_using_xserver_resolution;
|
gboolean new_using_xserver_resolution;
|
||||||
gdouble new_monitor_xres;
|
gdouble new_monitor_xres;
|
||||||
|
|
Loading…
Reference in New Issue