Skip to content

Commit

Permalink
Deprecate GCond and GMutex compat layer
Browse files Browse the repository at this point in the history
  • Loading branch information
kleisauke committed Nov 8, 2024
1 parent b27b8e4 commit a16fda3
Show file tree
Hide file tree
Showing 53 changed files with 389 additions and 545 deletions.
2 changes: 0 additions & 2 deletions doc/using-threads.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,6 @@ main(int argc, char **argv)
if (VIPS_INIT(argv[0]))
vips_error_exit(NULL);

g_mutex_init(&allocation_lock);

for (i = 0; i < NUM_IN_PARALLEL; i++)
workers[i] = g_thread_new(NULL, (GThreadFunc) worker, argv[1]);

Expand Down
16 changes: 8 additions & 8 deletions libvips/conversion/sequential.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ typedef struct _VipsSequential {

/* Lock access to y_pos with this.
*/
GMutex *lock;
GMutex lock;

/* The next read from our source will fetch this scanline, ie. it's 0
* when we start.
Expand All @@ -106,7 +106,7 @@ vips_sequential_dispose(GObject *gobject)
{
VipsSequential *sequential = (VipsSequential *) gobject;

VIPS_FREEF(vips_g_mutex_free, sequential->lock);
g_mutex_clear(&sequential->lock);

G_OBJECT_CLASS(vips_sequential_parent_class)->dispose(gobject);
}
Expand All @@ -126,14 +126,14 @@ vips_sequential_generate(VipsRegion *out_region,

VIPS_GATE_START("vips_sequential_generate: wait");

vips__worker_lock(sequential->lock);
vips__worker_lock(&sequential->lock);

VIPS_GATE_STOP("vips_sequential_generate: wait");

/* If we've seen an error, everything must stop.
*/
if (sequential->error) {
g_mutex_unlock(sequential->lock);
g_mutex_unlock(&sequential->lock);
return -1;
}

Expand All @@ -157,7 +157,7 @@ vips_sequential_generate(VipsRegion *out_region,
area.height = VIPS_MIN(sequential->tile_height, r->top - area.top);
if (vips_region_prepare(ir, &area)) {
sequential->error = -1;
g_mutex_unlock(sequential->lock);
g_mutex_unlock(&sequential->lock);
return -1;
}

Expand All @@ -172,13 +172,13 @@ vips_sequential_generate(VipsRegion *out_region,
if (vips_region_prepare(ir, r) ||
vips_region_region(out_region, ir, r, r->left, r->top)) {
sequential->error = -1;
g_mutex_unlock(sequential->lock);
g_mutex_unlock(&sequential->lock);
return -1;
}

sequential->y_pos = VIPS_MAX(sequential->y_pos, VIPS_RECT_BOTTOM(r));

g_mutex_unlock(sequential->lock);
g_mutex_unlock(&sequential->lock);

return 0;
}
Expand Down Expand Up @@ -270,7 +270,7 @@ vips_sequential_class_init(VipsSequentialClass *class)
static void
vips_sequential_init(VipsSequential *sequential)
{
sequential->lock = vips_g_mutex_new();
g_mutex_init(&sequential->lock);
sequential->tile_height = 1;
sequential->error = 0;
sequential->trace = FALSE;
Expand Down
32 changes: 16 additions & 16 deletions libvips/conversion/tilecache.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ typedef struct _VipsBlockCache {
gboolean threaded;
gboolean persistent;

GMutex *lock; /* Lock everything here */
GCond *new_tile; /* A new tile is ready */
GMutex lock; /* Lock everything here */
GCond new_tile; /* A new tile is ready */
GHashTable *tiles; /* Tiles, hashed by coordinates */
GQueue *recycle; /* Queue of unreffed tiles to reuse */
} VipsBlockCache;
Expand Down Expand Up @@ -158,8 +158,8 @@ vips_block_cache_dispose(GObject *gobject)
VipsBlockCache *cache = (VipsBlockCache *) gobject;

vips_block_cache_drop_all(cache);
VIPS_FREEF(vips_g_mutex_free, cache->lock);
VIPS_FREEF(vips_g_cond_free, cache->new_tile);
g_mutex_clear(&cache->lock);
g_cond_clear(&cache->new_tile);

if (cache->tiles)
g_assert(g_hash_table_size(cache->tiles) == 0);
Expand Down Expand Up @@ -342,14 +342,14 @@ vips_block_cache_minimise(VipsImage *image, VipsBlockCache *cache)
{
VIPS_DEBUG_MSG("vips_block_cache_minimise:\n");

g_mutex_lock(cache->lock);
g_mutex_lock(&cache->lock);

/* We can't drop tiles that are in use.
*/
g_hash_table_foreach_remove(cache->tiles,
vips_tile_unlocked, NULL);

g_mutex_unlock(cache->lock);
g_mutex_unlock(&cache->lock);
}

static int
Expand Down Expand Up @@ -481,8 +481,8 @@ vips_block_cache_init(VipsBlockCache *cache)
cache->threaded = FALSE;
cache->persistent = FALSE;

cache->lock = vips_g_mutex_new();
cache->new_tile = vips_g_cond_new();
g_mutex_init(&cache->lock);
g_cond_init(&cache->new_tile);
cache->tiles = g_hash_table_new_full(
(GHashFunc) vips_rect_hash,
(GEqualFunc) vips_rect_equal,
Expand Down Expand Up @@ -615,7 +615,7 @@ vips_tile_cache_gen(VipsRegion *out_region,

VIPS_GATE_START("vips_tile_cache_gen: wait1");

vips__worker_lock(cache->lock);
vips__worker_lock(&cache->lock);

VIPS_GATE_STOP("vips_tile_cache_gen: wait1");

Expand Down Expand Up @@ -674,7 +674,7 @@ vips_tile_cache_gen(VipsRegion *out_region,
* mode, we keep the lock and make 'em wait.
*/
if (cache->threaded)
g_mutex_unlock(cache->lock);
g_mutex_unlock(&cache->lock);

/* Don't compute if we've seen an error
* previously.
Expand All @@ -688,7 +688,7 @@ vips_tile_cache_gen(VipsRegion *out_region,
if (cache->threaded) {
VIPS_GATE_START("vips_tile_cache_gen: wait2");

g_mutex_lock(cache->lock);
g_mutex_lock(&cache->lock);

VIPS_GATE_STOP("vips_tile_cache_gen: wait2");
}
Expand Down Expand Up @@ -718,7 +718,7 @@ vips_tile_cache_gen(VipsRegion *out_region,
/* Let everyone know there's a new DATA tile.
* They need to all check their work lists.
*/
g_cond_broadcast(cache->new_tile);
g_cond_broadcast(&cache->new_tile);

break;
}
Expand All @@ -741,15 +741,15 @@ vips_tile_cache_gen(VipsRegion *out_region,

VIPS_GATE_START("vips_tile_cache_gen: wait3");

vips__worker_cond_wait(cache->new_tile, cache->lock);
vips__worker_cond_wait(&cache->new_tile, &cache->lock);

VIPS_GATE_STOP("vips_tile_cache_gen: wait3");

VIPS_DEBUG_MSG("vips_tile_cache_gen: awake!\n");
}
}

g_mutex_unlock(cache->lock);
g_mutex_unlock(&cache->lock);

return result;
}
Expand Down Expand Up @@ -889,7 +889,7 @@ vips_line_cache_gen(VipsRegion *out_region,

VIPS_GATE_START("vips_line_cache_gen: wait");

vips__worker_lock(block_cache->lock);
vips__worker_lock(&block_cache->lock);

VIPS_GATE_STOP("vips_line_cache_gen: wait");

Expand All @@ -903,7 +903,7 @@ vips_line_cache_gen(VipsRegion *out_region,
block_cache->max_tiles);
}

g_mutex_unlock(block_cache->lock);
g_mutex_unlock(&block_cache->lock);

return vips_tile_cache_gen(out_region, seq, a, b, stop);
}
Expand Down
8 changes: 4 additions & 4 deletions libvips/convolution/convi.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,9 @@ vips_convi_compile_section(VipsConvi *convi, VipsImage *in, Pass *pass)

/* Some orcs seem to be unstable with many compilers active at once.
*/
g_mutex_lock(vips__global_lock);
g_mutex_lock(&vips__global_lock);
result = orc_program_compile(p);
g_mutex_unlock(vips__global_lock);
g_mutex_unlock(&vips__global_lock);

if (!ORC_COMPILE_RESULT_IS_SUCCESSFUL(result))
return -1;
Expand Down Expand Up @@ -549,9 +549,9 @@ vips_convi_compile_clip(VipsConvi *convi)

/* Some orcs seem to be unstable with many compilers active at once.
*/
g_mutex_lock(vips__global_lock);
g_mutex_lock(&vips__global_lock);
result = orc_program_compile(p);
g_mutex_unlock(vips__global_lock);
g_mutex_unlock(&vips__global_lock);

if (!ORC_COMPILE_RESULT_IS_SUCCESSFUL(result))
return -1;
Expand Down
17 changes: 8 additions & 9 deletions libvips/create/text.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ static PangoFontMap *vips_text_fontmap = NULL;

/* ... single-thread vips_text_fontfiles with this.
*/
static GMutex *vips_text_lock = NULL;
static GMutex vips_text_lock;

/* All the fontfiles we've loaded. fontconfig lets you add a fontfile
* repeatedly, and we obviously don't want that.
Expand Down Expand Up @@ -376,7 +376,6 @@ vips_text_autofit(VipsText *text)
static void *
vips_text_init_once(void *client)
{
vips_text_lock = vips_g_mutex_new();
vips_text_fontmap = pango_cairo_font_map_new();
vips_text_fontfiles = g_hash_table_new(g_str_hash, g_str_equal);

Expand Down Expand Up @@ -416,7 +415,7 @@ vips_text_build(VipsObject *object)
* between all vips_text instances, we must lock all the way to the
* end of text rendering.
*/
g_mutex_lock(vips_text_lock);
g_mutex_lock(&vips_text_lock);

#ifdef HAVE_FONTCONFIG
if (text->fontfile &&
Expand Down Expand Up @@ -451,21 +450,21 @@ vips_text_build(VipsObject *object)
if (vips_object_argument_isset(object, "height") &&
!vips_object_argument_isset(object, "dpi")) {
if (vips_text_autofit(text)) {
g_mutex_unlock(vips_text_lock);
g_mutex_unlock(&vips_text_lock);
return -1;
}
}

/* Layout. Can fail for "", for example.
*/
if (vips_text_get_extents(text, &extents)) {
g_mutex_unlock(vips_text_lock);
g_mutex_unlock(&vips_text_lock);
return -1;
}

if (extents.width == 0 ||
extents.height == 0) {
g_mutex_unlock(vips_text_lock);
g_mutex_unlock(&vips_text_lock);
vips_error(class->nickname, "%s", _("no text to render"));
return -1;
}
Expand All @@ -480,7 +479,7 @@ vips_text_build(VipsObject *object)

if (vips_image_pipelinev(t[0], VIPS_DEMAND_STYLE_ANY, NULL) ||
vips_image_write_prepare(t[0])) {
g_mutex_unlock(vips_text_lock);
g_mutex_unlock(&vips_text_lock);
return -1;
}
in = t[0];
Expand All @@ -494,7 +493,7 @@ vips_text_build(VipsObject *object)
status = cairo_surface_status(surface);
if (status) {
cairo_surface_destroy(surface);
g_mutex_unlock(vips_text_lock);
g_mutex_unlock(&vips_text_lock);
vips_error(class->nickname,
"%s", cairo_status_to_string(status));
return -1;
Expand All @@ -509,7 +508,7 @@ vips_text_build(VipsObject *object)

cairo_destroy(cr);

g_mutex_unlock(vips_text_lock);
g_mutex_unlock(&vips_text_lock);

if (text->rgba) {
/* Cairo makes pre-multipled BRGA -- we must byteswap and
Expand Down
1 change: 0 additions & 1 deletion libvips/deprecated/im_exr2vips.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
#include <string.h>

#include <vips/vips.h>
#include <vips/thread.h>
#include <vips/internal.h>

#include "../foreign/pforeign.h"
Expand Down
1 change: 0 additions & 1 deletion libvips/deprecated/im_nifti2vips.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
#include <string.h>

#include <vips/vips.h>
#include <vips/thread.h>
#include <vips/internal.h>

static int
Expand Down
1 change: 0 additions & 1 deletion libvips/deprecated/im_openslide2vips.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
#include <string.h>

#include <vips/vips.h>
#include <vips/thread.h>
#include <vips/internal.h>

static int
Expand Down
1 change: 0 additions & 1 deletion libvips/deprecated/im_tiff2vips.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@

#include <vips/vips.h>
#include <vips/internal.h>
#include <vips/thread.h>

#include "../foreign/pforeign.h"

Expand Down
Loading

0 comments on commit a16fda3

Please sign in to comment.