Commit d154b398 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

configure.in app/base/tile-cache.c app/base/tile-private.h

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

	* configure.in
	* app/base/tile-cache.c
	* app/base/tile-private.h
	* app/base/tile-swap.c
	* app/base/tile.c: in an attempt to safe this code from bit-rot,
	ported the experimental threaded tile-swapper to gthread.
parent 50f9c145
2005-02-13 Sven Neumann <sven@gimp.org>
* configure.in
* app/base/tile-cache.c
* app/base/tile-private.h
* app/base/tile-swap.c
* app/base/tile.c: in an attempt to safe this code from bit-rot,
ported the experimental threaded tile-swapper to gthread.
2005-02-13 Sven Neumann <sven@gimp.org>
* app/base/gimphistogram.c: port this code to gthread as well.
......
......@@ -18,10 +18,6 @@
#include "config.h"
#ifdef USE_PTHREADS
#include <pthread.h>
#endif
#include <glib-object.h>
#include "base-types.h"
......@@ -43,7 +39,7 @@
static gboolean tile_cache_zorch_next (void);
static void tile_cache_flush_internal (Tile *tile);
#ifdef USE_PTHREADS
#ifdef ENABLE_THREADED_TILE_SWAPPER
static gpointer tile_idle_thread (gpointer data);
#else
static gboolean tile_idle_preswap (gpointer data);
......@@ -65,15 +61,16 @@ static gulong cur_cache_dirty = 0;
static TileList clean_list = { NULL, NULL };
static TileList dirty_list = { NULL, NULL };
#ifdef USE_PTHREADS
static pthread_t preswap_thread;
static pthread_mutex_t dirty_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t dirty_signal = PTHREAD_COND_INITIALIZER;
static pthread_mutex_t tile_mutex = PTHREAD_MUTEX_INITIALIZER;
#define CACHE_LOCK pthread_mutex_lock (&tile_mutex)
#define CACHE_UNLOCK pthread_mutex_unlock (&tile_mutex)
#ifdef ENABLE_THREADED_TILE_SWAPPER
static GThread *preswap_thread = NULL;
static GMutex *dirty_mutex = NULL;
static GCond *dirty_signal = NULL;
static GStaticMutex tile_mutex = G_STATIC_MUTEX_INIT;
#define CACHE_LOCK g_static_mutex_lock (&tile_mutex)
#define CACHE_UNLOCK g_static_mutex_unlock (&tile_mutex)
#else
static guint idle_swapper = 0;
static guint idle_swapper = 0;
#define CACHE_LOCK /* nothing */
#define CACHE_UNLOCK /* nothing */
#endif
......@@ -91,8 +88,11 @@ tile_cache_init (gulong tile_cache_size)
max_cache_size = tile_cache_size;
#ifdef USE_PTHREADS
pthread_create (&preswap_thread, NULL, &tile_idle_thread, NULL);
#ifdef ENABLE_THREADED_TILE_SWAPPER
dirty_mutex = g_mutex_new ();
dirty_signal = g_cond_new ();
preswap_thread = g_thread_create (&tile_idle_thread, NULL, FALSE, NULL);
#else
idle_swapper = g_timeout_add (IDLE_SWAPPER_TIMEOUT,
tile_idle_preswap,
......@@ -193,10 +193,10 @@ tile_cache_insert (Tile *tile)
{
cur_cache_dirty += tile_size_inline (tile);
#ifdef USE_PTHREADS
pthread_mutex_lock (&dirty_mutex);
pthread_cond_signal (&dirty_signal);
pthread_mutex_unlock (&dirty_mutex);
#ifdef ENABLE_THREADED_TILE_SWAPPER
g_mutex_lock (dirty_mutex);
g_cond_signal (dirty_signal);
g_mutex_unlock (dirty_mutex);
#endif
}
......@@ -302,7 +302,7 @@ tile_cache_zorch_next (void)
}
#if USE_PTHREADS
#ifdef ENABLE_THREADED_TILE_SWAPPER
static gpointer
tile_idle_thread (gpointer data)
......@@ -324,9 +324,9 @@ tile_idle_thread (gpointer data)
count = 0;
pthread_mutex_lock (&dirty_mutex);
pthread_cond_wait (&dirty_signal, &dirty_mutex);
pthread_mutex_unlock (&dirty_mutex);
g_mutex_lock (dirty_mutex);
g_cond_wait (dirty_signal, dirty_mutex);
g_mutex_unlock (dirty_mutex);
CACHE_LOCK;
}
......@@ -385,7 +385,7 @@ tile_idle_thread (gpointer data)
}
}
#else /* !USE_PTHREADS */
#else /* !ENABLE_THREADED_TILE_SWAPPER */
static gboolean
tile_idle_preswap (gpointer data)
......@@ -422,4 +422,4 @@ tile_idle_preswap (gpointer data)
return TRUE;
}
#endif /* !USE_PTHREADS */
#endif /* !ENABLE_THREADED_TILE_SWAPPER */
......@@ -19,16 +19,8 @@
#ifndef __TILE_PRIVATE_H__
#define __TILE_PRIVATE_H__
#include "config.h"
#ifdef USE_PTHREADS
#include <pthread.h>
#endif
#include <sys/types.h>
#include <glib.h>
typedef struct _TileLink TileLink;
......@@ -87,15 +79,15 @@ struct _Tile
Tile *prev; /* List pointers for the tile cache lists */
gpointer listhead; /* Pointer to the head of the list this tile is on */
#ifdef USE_PTHREADS
pthread_mutex_t mutex;
#ifdef ENABLE_THREADED_TILE_SWAPPER
GMutex *mutex;
#endif
};
#ifdef USE_PTHREADS
#define TILE_MUTEX_LOCK(tile) pthread_mutex_lock(&((tile)->mutex))
#define TILE_MUTEX_UNLOCK(tile) pthread_mutex_unlock(&((tile)->mutex))
#ifdef ENABLE_THREADED_TILE_SWAPPER
#define TILE_MUTEX_LOCK(tile) g_mutex_lock((tile)->mutex)
#define TILE_MUTEX_UNLOCK(tile) g_mutex_unlock((tile)->mutex)
#else
#define TILE_MUTEX_LOCK(tile) /* nothing */
#define TILE_MUTEX_UNLOCK(tile) /* nothing */
......
......@@ -19,17 +19,13 @@
#include "config.h"
#include <errno.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/types.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef USE_PTHREADS
#include <pthread.h>
#endif
#include <glib-object.h>
#include <glib/gstdio.h>
......@@ -124,7 +120,7 @@ static void tile_swap_resize (DefSwapFile *def_swap_file,
static Gap * tile_swap_gap_new (off_t start,
off_t end);
static void tile_swap_gap_destroy (Gap *gap);
#ifdef USE_PTHREADS
#ifdef ENABLE_THREADED_TILE_SWAPPER
static gpointer tile_swap_in_thread (gpointer);
#endif
......@@ -135,13 +131,13 @@ static GList * open_swap_files = NULL;
static gint nopen_swap_files = 0;
static gint next_swap_num = 1;
static off_t swap_file_grow = 16 * TILE_WIDTH * TILE_HEIGHT * 4;
#ifdef USE_PTHREADS
static pthread_mutex_t swapfile_mutex = PTHREAD_MUTEX_INITIALIZER;
#ifdef ENABLE_THREADED_TILE_SWAPPER
static GStaticMutex swapfile_mutex = G_STATIC_MUTEX_INIT;
/* async_swapin_mutex protects only the list, not the tiles therein */
static pthread_t swapin_thread;
static pthread_mutex_t async_swapin_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t async_swapin_signal = PTHREAD_COND_INITIALIZER;
static GThread * swapin_thread = NULL;
static GMutex * async_swapin_mutex = NULL;
static GCond * async_swapin_signal = NULL;
static GSList * async_swapin_tiles = NULL;
static GSList * async_swapin_tiles_end = NULL;
#endif
......@@ -235,8 +231,11 @@ tile_swap_init (const gchar *path)
g_free (swappath);
#ifdef NOTDEF /* USE_PTHREADS */
pthread_create (&swapin_thread, NULL, &tile_swap_in_thread, NULL);
#ifdef ENABLE_THREADED_TILE_SWAPPER
async_swapin_signal = g_cond_new ();
async_swapin_mutex = g_mutex_new ();
swapin_thread = g_thread_create (tile_swap_in_thread, NULL, FALSE, NULL);
#endif
}
......@@ -254,8 +253,6 @@ tile_swap_exit (void)
if (swap_files)
g_hash_table_foreach (swap_files, tile_swap_exit1, NULL);
initialized = FALSE;
}
gint
......@@ -266,8 +263,8 @@ tile_swap_add (gchar *filename,
SwapFile *swap_file;
DefSwapFile *def_swap_file;
#ifdef USE_PTHREADS
pthread_mutex_lock(&swapfile_mutex);
#ifdef ENABLE_THREADED_TILE_SWAPPER
g_static_mutex_lock (&swapfile_mutex);
#endif
g_return_val_if_fail (initialized, -1);
......@@ -294,8 +291,8 @@ tile_swap_add (gchar *filename,
g_hash_table_insert (swap_files, &swap_file->swap_num, swap_file);
#ifdef USE_PTHREADS
pthread_mutex_unlock(&swapfile_mutex);
#ifdef ENABLE_THREADED_TILE_SWAPPER
g_static_mutex_unlock (&swapfile_mutex);
#endif
return swap_file->swap_num;
}
......@@ -305,8 +302,8 @@ tile_swap_remove (gint swap_num)
{
SwapFile *swap_file;
#ifdef USE_PTHREADS
pthread_mutex_lock (&swapfile_mutex);
#ifdef ENABLE_THREADED_TILE_SWAPPER
g_static_mutex_lock (&swapfile_mutex);
#endif
g_return_if_fail (initialized);
......@@ -322,8 +319,8 @@ tile_swap_remove (gint swap_num)
g_free (swap_file);
out:
#ifdef USE_PTHREADS
pthread_mutex_unlock(&swapfile_mutex);
#ifdef ENABLE_THREADED_TILE_SWAPPER
g_static_mutex_unlock (&swapfile_mutex);
#endif
return;
}
......@@ -414,8 +411,8 @@ tile_swap_command (Tile *tile,
gint command)
{
SwapFile *swap_file;
#ifdef USE_PTHREADS
pthread_mutex_lock(&swapfile_mutex);
#ifdef ENABLE_THREADED_TILE_SWAPPER
g_static_mutex_lock (&swapfile_mutex);
#endif
g_return_if_fail (initialized);
......@@ -440,8 +437,8 @@ tile_swap_command (Tile *tile,
tile, command, swap_file->user_data));
out:
#ifdef USE_PTHREADS
pthread_mutex_unlock(&swapfile_mutex);
#ifdef ENABLE_THREADED_TILE_SWAPPER
g_static_mutex_unlock (&swapfile_mutex);
#endif
return;
......@@ -531,7 +528,7 @@ tile_swap_default_in_async (DefSwapFile *def_swap_file,
gint fd,
Tile *tile)
{
#ifdef NOTDEF /* USE_PTHREADS */
#ifdef ENABLE_THREADED_TILE_SWAPPER
AsyncSwapArgs *args;
args = g_new(AsyncSwapArgs, 1);
......@@ -540,14 +537,14 @@ tile_swap_default_in_async (DefSwapFile *def_swap_file,
args->tile = tile;
/* add this tile to the list of tiles for the async swapin task */
pthread_mutex_lock (&async_swapin_mutex);
g_mutex_lock (async_swapin_mutex);
g_slist_append (async_swapin_tiles_end, args);
if (!async_swapin_tiles)
async_swapin_tiles = async_swapin_tiles_end;
pthread_cond_signal (&async_swapin_signal);
pthread_mutex_unlock (&async_swapin_mutex);
g_cond_broadcast (async_swapin_signal);
g_mutex_unlock (async_swapin_mutex);
#else
/* ignore; it's only a hint anyway */
......@@ -883,7 +880,7 @@ tile_swap_gap_destroy (Gap *gap)
}
#ifdef NOTDEF /* USE_PTHREADS */
#ifdef ENABLE_THREADED_TILE_SWAPPER
/* go through the list of tiles that are likely to be used soon and
* try to swap them in. If any tile is not in a state to be swapped
* in, ignore it, and the error will get dealt with when the tile
......@@ -958,12 +955,11 @@ tile_swap_in_thread (gpointer data)
while (TRUE)
{
pthread_mutex_lock (&async_swapin_mutex);
g_mutex_lock (async_swapin_mutex);
if (!async_swapin_tiles)
{
pthread_cond_wait (&async_swapin_signal, &async_swapin_mutex);
}
g_cond_wait (async_swapin_signal, async_swapin_mutex);
args = async_swapin_tiles->data;
free_item = async_swapin_tiles;
......@@ -973,7 +969,7 @@ tile_swap_in_thread (gpointer data)
if (!async_swapin_tiles)
async_swapin_tiles_end = NULL;
pthread_mutex_unlock (&async_swapin_mutex);
g_mutex_unlock (async_swapin_mutex);
tile_swap_in_attempt(args->def_swap_file, args->fd, args->tile);
......
......@@ -103,10 +103,8 @@ tile_init (Tile *tile,
tile->listhead = NULL;
tile->rowhint = NULL;
#ifdef USE_PTHREADS
{
pthread_mutex_init (&tile->mutex, NULL);
}
#ifdef ENABLE_THREADED_TILE_SWAPPER
tile->mutex = g_mutex_new ();
#endif
tile_count++;
......@@ -263,6 +261,11 @@ tile_destroy (Tile *tile)
tile_cache_flush (tile);
TILE_MUTEX_UNLOCK (tile);
#ifdef ENABLE_THREADED_TILE_SWAPPER
g_mutex_free (tile->mutex);
#endif
g_free (tile);
tile_count--;
......
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