Commit Graph

74 Commits

Author SHA1 Message Date
Kleis Auke Wolthuizen 848a119faa
threadset: stop idle threads after a regular timeout (#3253)
* Add `vips_semaphore_down_timeout` to public API

In preparation for the next commit.

* threadset: stop idle threads after a regular timeout

In line with the previous behaviour of GLib's threadpool.

* threadset: fix a small memory leak

* threadset: ensure idle threads are freed on exit

GLib threads are spawned with `ref_count == 2`, this reference is
decreased during thread exit and associated resources are freed
during `g_thread_join()`. However, idle threads that are stopped
after a regular timeout are not joined. To fix this, decrease the
reference count during `vips_threadset_add()` and increase it just
before joining the thread with `g_thread_join()`.

See:
2d5d990c6a/glib/gthread.c (L522)
2d5d990c6a/glib/gthread-posix.c (L1287)

* Deprecate `vips_g_thread_join()` in favor of `g_thread_join()`

* nit: remove extra semicolon
2023-01-03 12:00:35 +00:00
Kleis Auke Wolthuizen 0337c09700
Cleanup gettext handling (#2695)
Use GLib's i18n support instead of copying and pasting that
logic into its own header. This deprecates the vips/intl.h
header in favour of glib/gi18n.h.
2022-02-27 15:27:28 +00:00
John Cupitt af61d375bc
experiment with removing shutdown from atexit (#2439)
remove shutdown from atexit

Because atexit() can be called at almost any point during process termination,
including after worker threads have been force-quit, we can't use it for
cleanup.

New policy: use vips_shutdown() explicitly if you need to clean up,
though it's optional. Only use atexit() for leak checking.
2021-09-17 19:02:53 +01:00
John Cupitt e96fc955bc comment reason for thread_execute revert 2021-06-07 14:30:21 +01:00
John Cupitt 939437d56e Merge commit '4c263a36e9e728b5ab5cc1f4f3cafe5738a6b6e7' into 8.11 2021-06-07 14:26:58 +01:00
Kleis Auke Wolthuizen 4c263a36e9 Don't run sinkscreen thread in threadpool
Since threads on Windows can be terminated prior to the execution
of the atexit registered functions (i.e. vips_shutdown), causing
a surprising deadlock. This thread is never recycled, so it should
be fine.

Reverts commit d1b4d12388 partially.
2021-06-07 14:39:47 +02:00
John Cupitt f39e2e271d don't invalidate in sinkscreen
it was called from a bg thread and could race when under heavy load, eg.
vipsdisp displaying animated jpg images
2021-06-06 16:53:00 +01:00
John Cupitt f637206e8d move vips_threadpool_push to internal API
and rename as vips__thread_execute()
2021-05-17 08:42:39 +01:00
Kleis Auke Wolthuizen 83575e347a Use gatomicrefcount in sinkscreen 2021-05-03 13:21:45 +02:00
Kleis Auke Wolthuizen d1b4d12388 Move sink_disc and sink_screen threads to threadpool
And deprecate the vips_g_thread_new and vips_g_thread_join
functions.
2021-05-03 13:21:45 +02:00
John Cupitt 1f4f975e7d make leak test exit with an error code
and run the libvips leak test in CI
2021-02-08 11:25:56 +00:00
John Cupitt 817bb1d65c fix typo 2020-08-28 19:06:21 +01:00
John Cupitt 2c4c4132e8 Merge branch '8.10' 2020-08-28 17:47:40 +01:00
John Cupitt 99423649b9 start sinkscreen thread on first use
we were starting the sinkscreen background thread during vips_init() --
instead, start it on first use

see https://github.com/libvips/libvips/issues/1792
2020-08-28 17:46:23 +01:00
Kleis Auke Wolthuizen 9f5304632f Fix a small memory leak in sinkscreen 2020-08-27 18:11:03 +02:00
Kleis Auke Wolthuizen 9246094033 Fix function pointer cast issues
It is undefined behavior in C and C++ to cast a function pointer
to another type and call it that way. This does work in most native
platforms, however, despite it being UB, but in WASM it can fail.

See:
https://emscripten.org/docs/porting/guidelines/function_pointer_issues.html
2020-06-30 13:35:41 +02:00
John Cupitt 8ba31844d6 fix a race in startup
We were creating a background thread before creating the semaphore that held
the thread. This could sometimes segv under a debugger.
2020-04-15 16:53:58 +01:00
John Cupitt 8840bc8a14 better render init stops a race
when running inside some versions of gdb
2020-04-02 14:23:06 +01:00
John Cupitt c9b87ce4f5 fix a thread leak in sink_screen
we were not joining the bg render thread when it exited

instead, keep the thread around with a semaphore for it to wait on
2018-01-08 11:47:47 +00:00
John Cupitt 1b89d62eb5 fix a race associated with sink_screen
sink_screen was not keeping a ref to its input, so in rare conditions
it could try to make a region on a dead image
2018-01-05 16:27:44 +00:00
John Cupitt f9f717a843 add VIPS_ONCE and use it everywhere
Lovell's idea: save the function call in the most common case
2017-11-23 08:43:08 +00:00
Alistair Thomas 7452d046ca Update GObject introspection annotations for libvips/iofuncs directory 2017-09-30 13:31:00 +01:00
John Cupitt 26a534eeac count threads for leak test
see https://github.com/jcupitt/libvips/issues/542
2016-10-19 10:52:18 +01:00
John Cupitt 8ebed8fe03 fix the bg render thread in sinkscreen
it could exit under heavy load, resulting in black everywhere ... now
let it exit when there's no work, and restart next time a dirty tile
appears
2015-12-02 15:51:25 +00:00
John Cupitt c57a03d8a6 improve vips_sink_screen() shutdown
is now very careful not to do anything to output images after they've
been unreffed ... fixes a crash in vipsdisp
2015-12-01 13:12:07 +00:00
John Cupitt af84b3097c more docs work 2014-08-19 16:57:37 +01:00
John Cupitt f582c1bd4e check for init before render shutdown
we could shut down render without having inited it, check

thanks andrea
2014-01-31 14:48:15 +00:00
John Cupitt 2cbaacbb0b oops! 2014-01-29 14:26:09 +00:00
John Cupitt 1564213b67 oop, invalidate mask as well 2014-01-29 12:21:47 +00:00
John Cupitt 9cb152596c bg render thread quits on shutdown
fixes a small memleak
2014-01-29 09:07:58 +00:00
John Cupitt 16830d6937 vips_sink_screen() now invalidates for you
clients no longer need to call vips_image_invalidate_all()
2014-01-28 13:08:02 +00:00
John Cupitt c80e7292be formatting 2014-01-27 15:03:08 +00:00
John Cupitt 12cf71a6a9 combin copy_fields and demand_hint
We had two API calls, vips_image_copy_fields() and vips_demand_hint().
They are now combined in the single vips_image_pipeline() call.

All operations are now slightly smaller and simpler.
2013-10-22 09:29:40 +01:00
John Cupitt 697555962a fix vips_image_write() for non "p" sources
oops!
2013-06-06 14:43:52 +01:00
John Cupitt 8956ba536b fix some cppcheck warnings 2013-05-01 18:46:15 +01:00
John Cupitt d6e8abce9b added "persistent" option to tilecache
sometimes you need to keep pixels between evaluations
2013-04-25 17:43:15 +01:00
Benjamin Gilbert 8cc76a6ba3 Update address for Free Software Foundation
Also update LGPLv2.1 license text from the copy currently on the GNU
website.
2013-03-07 00:40:19 -05:00
John Cupitt 7e3494f6eb new new g_thread*() API 2012-10-23 13:36:39 +01:00
John Cupitt fad78f8555 rework gthread usage
glib-2.32 deprecated g_mutex_new() ... use a compat function to hide
this change

also remove the --without-threads configure flag, gthread is now
compulsory, so there was no longer any point
2012-10-22 22:08:53 +01:00
John Cupitt a5b3eb2040 amke vips_cache() a vips8 operation 2012-01-13 13:15:56 +00:00
John Cupitt d0ec401a12 hackery to get goi working 2011-12-31 18:22:42 +00:00
John Cupitt a62f5f8832 remove wio_output 2011-12-21 12:08:29 +00:00
John Cupitt 952199e92a add VipsCopy
add a basic VipsCopy operation, also demand_hint is now void
2011-09-29 13:34:14 +01:00
John Cupitt ae8faf6597 remove dmalloc support
we never used it and valgrind etc. is better anyway
2011-09-23 17:12:47 +01:00
John Cupitt 2909cb93a4 add a 'stop' param to generate
generate now has a 'stop' param, set this to indicate early successful
termination

this will be used by VipsMin and friends to stop scanning early for
conditions like seen a 0 in a uchar image while searching for min
2011-08-29 14:29:33 +01:00
John Cupitt 971615d6ae back to fixed refs, add a pool system instead
floating refs were very confusing and annoying, instead use simple fixed
refs and add a pool system to track refs for you

also fixed a couple of dumb errors in close callbacks
2011-06-02 12:23:56 +01:00
John Cupitt 8ddc805878 phew all done
iofuncs is now all on the vips_ namespace, and all revised, hopefully
2011-03-28 17:18:06 +01:00
John Cupitt 4120f7b296 cleanup util
just a few little things left, yay
2011-03-28 16:03:31 +01:00
John Cupitt c7b74f620f yet more cleanups
just util.c left now, woo
2011-03-28 14:57:43 +01:00
John Cupitt 11966af809 fix up im_incheck() and friends
sorted out, moved to vips_
2011-03-25 14:48:28 +00:00