v0.2.1 c0399be

gthreadpool.go RawHistoryFolder

1// Package glib was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package glib
3
4import (
5	"structs"
6	"unsafe"
7
8	"github.com/ebitengine/purego"
9
10	"github.com/bnema/puregotk/pkg/core"
11)
12
13// The `GThreadPool` struct represents a thread pool.
14//
15// A thread pool is useful when you wish to asynchronously fork out the execution of work
16// and continue working in your own thread. If that will happen often, the overhead of starting
17// and destroying a thread each time might be too high. In such cases reusing already started
18// threads seems like a good idea. And it indeed is, but implementing this can be tedious
19// and error-prone.
20//
21// Therefore GLib provides thread pools for your convenience. An added advantage is, that the
22// threads can be shared between the different subsystems of your program, when they are using GLib.
23//
24// To create a new thread pool, you use [func@GLib.ThreadPool.new].
25// It is destroyed by [method@GLib.ThreadPool.free].
26//
27// If you want to execute a certain task within a thread pool, use [method@GLib.ThreadPool.push].
28//
29// To get the current number of running threads you call [method@GLib.ThreadPool.get_num_threads].
30// To get the number of still unprocessed tasks you call [method@GLib.ThreadPool.unprocessed].
31// To control the maximum number of threads for a thread pool, you use
32// [method@GLib.ThreadPool.get_max_threads]. and [method@GLib.ThreadPool.set_max_threads].
33//
34// Finally you can control the number of unused threads, that are kept alive by GLib for future use.
35// The current number can be fetched with [func@GLib.ThreadPool.get_num_unused_threads].
36// The maximum number can be controlled by [func@GLib.ThreadPool.get_max_unused_threads] and
37// [func@GLib.ThreadPool.set_max_unused_threads]. All currently unused threads
38// can be stopped by calling [func@GLib.ThreadPool.stop_unused_threads].
39type ThreadPool struct {
40	_ structs.HostLayout
41
42	Func Func
43
44	UserData uintptr
45
46	Exclusive bool
47}
48
49func (x *ThreadPool) GoPointer() uintptr {
50	return uintptr(unsafe.Pointer(x))
51}
52
53var xThreadPoolFree func(uintptr, bool, bool)
54
55// Frees all resources allocated for @pool.
56//
57// If @immediate is %TRUE, no new task is processed for @pool.
58// Otherwise @pool is not freed before the last task is processed.
59// Note however, that no thread of this pool is interrupted while
60// processing a task. Instead at least all still running threads
61// can finish their tasks before the @pool is freed.
62//
63// If @wait_ is %TRUE, this function does not return before all
64// tasks to be processed (dependent on @immediate, whether all
65// or only the currently running) are ready.
66// Otherwise this function returns immediately.
67//
68// After calling this function @pool must not be used anymore.
69func (x *ThreadPool) Free(ImmediateVar bool, WaitVar bool) {
70
71	xThreadPoolFree(x.GoPointer(), ImmediateVar, WaitVar)
72
73}
74
75var xThreadPoolGetMaxThreads func(uintptr) int
76
77// Returns the maximal number of threads for @pool.
78func (x *ThreadPool) GetMaxThreads() int {
79
80	cret := xThreadPoolGetMaxThreads(x.GoPointer())
81	return cret
82}
83
84var xThreadPoolGetNumThreads func(uintptr) uint
85
86// Returns the number of threads currently running in @pool.
87func (x *ThreadPool) GetNumThreads() uint {
88
89	cret := xThreadPoolGetNumThreads(x.GoPointer())
90	return cret
91}
92
93var xThreadPoolMoveToFront func(uintptr, uintptr) bool
94
95// Moves the item to the front of the queue of unprocessed
96// items, so that it will be processed next.
97func (x *ThreadPool) MoveToFront(DataVar uintptr) bool {
98
99	cret := xThreadPoolMoveToFront(x.GoPointer(), DataVar)
100	return cret
101}
102
103var xThreadPoolPush func(uintptr, uintptr, **Error) bool
104
105// Inserts @data into the list of tasks to be executed by @pool.
106//
107// When the number of currently running threads is lower than the
108// maximal allowed number of threads, a new thread is started (or
109// reused) with the properties given to g_thread_pool_new().
110// Otherwise, @data stays in the queue until a thread in this pool
111// finishes its previous task and processes @data.
112//
113// @error can be %NULL to ignore errors, or non-%NULL to report
114// errors. An error can only occur when a new thread couldn't be
115// created. In that case @data is simply appended to the queue of
116// work to do.
117//
118// Before version 2.32, this function did not return a success status.
119func (x *ThreadPool) Push(DataVar uintptr) (bool, error) {
120	var cerr *Error
121
122	cret := xThreadPoolPush(x.GoPointer(), DataVar, &cerr)
123	if cerr == nil {
124		return cret, nil
125	}
126	return cret, cerr
127
128}
129
130var xThreadPoolSetMaxThreads func(uintptr, int, **Error) bool
131
132// Sets the maximal allowed number of threads for @pool.
133// A value of -1 means that the maximal number of threads
134// is unlimited. If @pool is an exclusive thread pool, setting
135// the maximal number of threads to -1 is not allowed.
136//
137// Setting @max_threads to 0 means stopping all work for @pool.
138// It is effectively frozen until @max_threads is set to a non-zero
139// value again.
140//
141// A thread is never terminated while calling @func, as supplied by
142// g_thread_pool_new(). Instead the maximal number of threads only
143// has effect for the allocation of new threads in g_thread_pool_push().
144// A new thread is allocated, whenever the number of currently
145// running threads in @pool is smaller than the maximal number.
146//
147// @error can be %NULL to ignore errors, or non-%NULL to report
148// errors. An error can only occur when a new thread couldn't be
149// created.
150//
151// Before version 2.32, this function did not return a success status.
152func (x *ThreadPool) SetMaxThreads(MaxThreadsVar int) (bool, error) {
153	var cerr *Error
154
155	cret := xThreadPoolSetMaxThreads(x.GoPointer(), MaxThreadsVar, &cerr)
156	if cerr == nil {
157		return cret, nil
158	}
159	return cret, cerr
160
161}
162
163var xThreadPoolSetSortFunction func(uintptr, uintptr, uintptr)
164
165// Sets the function used to sort the list of tasks. This allows the
166// tasks to be processed by a priority determined by @func, and not
167// just in the order in which they were added to the pool.
168//
169// Note, if the maximum number of threads is more than 1, the order
170// that threads are executed cannot be guaranteed 100%. Threads are
171// scheduled by the operating system and are executed at random. It
172// cannot be assumed that threads are executed in the order they are
173// created.
174func (x *ThreadPool) SetSortFunction(FuncVar *CompareDataFunc, UserDataVar uintptr) {
175
176	var FuncVarRef uintptr
177	if FuncVar != nil {
178		FuncVarPtr := uintptr(unsafe.Pointer(FuncVar))
179		if cbRefPtr, ok := GetCallback(FuncVarPtr); ok {
180			FuncVarRef = cbRefPtr
181		} else {
182			fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr) int {
183				cbFn := *FuncVar
184				return cbFn(arg0, arg1, arg2)
185			}
186			FuncVarRef = purego.NewCallback(fcb)
187			SaveCallbackWithClosure(FuncVarPtr, FuncVarRef, FuncVar)
188		}
189	}
190
191	xThreadPoolSetSortFunction(x.GoPointer(), FuncVarRef, UserDataVar)
192
193}
194
195var xThreadPoolUnprocessed func(uintptr) uint
196
197// Returns the number of tasks still unprocessed in @pool.
198func (x *ThreadPool) Unprocessed() uint {
199
200	cret := xThreadPoolUnprocessed(x.GoPointer())
201	return cret
202}
203
204var xThreadPoolGetMaxIdleTime func() uint
205
206// This function will return the maximum @interval that a
207// thread will wait in the thread pool for new tasks before
208// being stopped.
209//
210// If this function returns 0, threads waiting in the thread
211// pool for new work are not stopped.
212func ThreadPoolGetMaxIdleTime() uint {
213
214	cret := xThreadPoolGetMaxIdleTime()
215
216	return cret
217}
218
219var xThreadPoolGetMaxUnusedThreads func() int
220
221// Returns the maximal allowed number of unused threads.
222func ThreadPoolGetMaxUnusedThreads() int {
223
224	cret := xThreadPoolGetMaxUnusedThreads()
225
226	return cret
227}
228
229var xThreadPoolGetNumUnusedThreads func() uint
230
231// Returns the number of currently unused threads.
232func ThreadPoolGetNumUnusedThreads() uint {
233
234	cret := xThreadPoolGetNumUnusedThreads()
235
236	return cret
237}
238
239var xThreadPoolSetMaxIdleTime func(uint)
240
241// This function will set the maximum @interval that a thread
242// waiting in the pool for new tasks can be idle for before
243// being stopped. This function is similar to calling
244// g_thread_pool_stop_unused_threads() on a regular timeout,
245// except this is done on a per thread basis.
246//
247// By setting @interval to 0, idle threads will not be stopped.
248//
249// The default value is 15000 (15 seconds).
250func ThreadPoolSetMaxIdleTime(IntervalVar uint) {
251
252	xThreadPoolSetMaxIdleTime(IntervalVar)
253
254}
255
256var xThreadPoolSetMaxUnusedThreads func(int)
257
258// Sets the maximal number of unused threads to @max_threads.
259// If @max_threads is -1, no limit is imposed on the number
260// of unused threads.
261//
262// The default value is 8 since GLib 2.84. Previously the default value was 2.
263func ThreadPoolSetMaxUnusedThreads(MaxThreadsVar int) {
264
265	xThreadPoolSetMaxUnusedThreads(MaxThreadsVar)
266
267}
268
269var xThreadPoolStopUnusedThreads func()
270
271// Stops all currently unused threads. This does not change the
272// maximal number of unused threads. This function can be used to
273// regularly stop all unused threads e.g. from g_timeout_add().
274func ThreadPoolStopUnusedThreads() {
275
276	xThreadPoolStopUnusedThreads()
277
278}
279
280func init() {
281	core.SetPackageName("GLIB", "glib-2.0")
282	core.SetSharedLibraries("GLIB", []string{"libgobject-2.0.so.0", "libglib-2.0.so.0"})
283	var libs []uintptr
284	for _, libPath := range core.GetPaths("GLIB") {
285		lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
286		if err != nil {
287			panic(err)
288		}
289		libs = append(libs, lib)
290	}
291
292	core.PuregoSafeRegister(&xThreadPoolGetMaxIdleTime, libs, "g_thread_pool_get_max_idle_time")
293	core.PuregoSafeRegister(&xThreadPoolGetMaxUnusedThreads, libs, "g_thread_pool_get_max_unused_threads")
294	core.PuregoSafeRegister(&xThreadPoolGetNumUnusedThreads, libs, "g_thread_pool_get_num_unused_threads")
295	core.PuregoSafeRegister(&xThreadPoolSetMaxIdleTime, libs, "g_thread_pool_set_max_idle_time")
296	core.PuregoSafeRegister(&xThreadPoolSetMaxUnusedThreads, libs, "g_thread_pool_set_max_unused_threads")
297	core.PuregoSafeRegister(&xThreadPoolStopUnusedThreads, libs, "g_thread_pool_stop_unused_threads")
298
299	core.PuregoSafeRegister(&xThreadPoolFree, libs, "g_thread_pool_free")
300	core.PuregoSafeRegister(&xThreadPoolGetMaxThreads, libs, "g_thread_pool_get_max_threads")
301	core.PuregoSafeRegister(&xThreadPoolGetNumThreads, libs, "g_thread_pool_get_num_threads")
302	core.PuregoSafeRegister(&xThreadPoolMoveToFront, libs, "g_thread_pool_move_to_front")
303	core.PuregoSafeRegister(&xThreadPoolPush, libs, "g_thread_pool_push")
304	core.PuregoSafeRegister(&xThreadPoolSetMaxThreads, libs, "g_thread_pool_set_max_threads")
305	core.PuregoSafeRegister(&xThreadPoolSetSortFunction, libs, "g_thread_pool_set_sort_function")
306	core.PuregoSafeRegister(&xThreadPoolUnprocessed, libs, "g_thread_pool_unprocessed")
307
308}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 102

↑↓ moveenter openesc close