Debian Codegraph @

src/dex-limiter.h

raw symbols SCIP
1 /*
2 * dex-limiter.h
3 *
4 * Copyright 2026 Christian Hergert
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this library; if not, see <http://www.gnu.org/licenses/>.
18 *
19 * SPDX-License-Identifier: LGPL-2.1-or-later
20 */
21
22 #pragma once
23
24 #if !defined (DEX_INSIDE) && !defined (DEX_COMPILATION)
25 # error "Only <libdex.h> can be included directly."
26 #endif
27
28 #include "dex-scheduler.h"
29 #include "dex-thread-pool.h"
30 #include "dex-version-macros.h"
31
32 G_BEGIN_DECLS
33
34 #define DEX_TYPE_LIMITER (dex_limiter_get_type())
35 #define DEX_LIMITER(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj, DEX_TYPE_LIMITER, DexLimiter))
36 #define DEX_IS_LIMITER(obj) (G_TYPE_CHECK_INSTANCE_TYPE(obj, DEX_TYPE_LIMITER))
37
38 typedef struct _DexLimiter DexLimiter;
39
40 DEX_AVAILABLE_IN_1_2
41 GType dex_limiter_get_type (void);
42 DEX_AVAILABLE_IN_1_2
43 DexLimiter *dex_limiter_new (guint max_concurrency);
44 DEX_AVAILABLE_IN_1_2
45 DexFuture *dex_limiter_close_after_drain (DexLimiter *limiter) G_GNUC_WARN_UNUSED_RESULT;
46 DEX_AVAILABLE_IN_1_2
47 guint dex_limiter_get_max_concurrency (DexLimiter *limiter);
48 DEX_AVAILABLE_IN_1_2
49 DexFuture *dex_limiter_acquire (DexLimiter *limiter) G_GNUC_WARN_UNUSED_RESULT;
50 DEX_AVAILABLE_IN_1_2
51 void dex_limiter_release (DexLimiter *limiter);
52 DEX_AVAILABLE_IN_1_2
53 DexFuture *dex_limiter_run (DexLimiter *limiter,
54 DexScheduler *scheduler,
55 gsize stack_size,
56 DexFiberFunc func,
57 gpointer func_data,
58 GDestroyNotify func_data_destroy) G_GNUC_WARN_UNUSED_RESULT;
59 DEX_AVAILABLE_IN_1_2
60 DexFuture *dex_limiter_run_coroutine (DexLimiter *limiter,
61 DexScheduler *scheduler,
62 DexCoroutineFunc func,
63 gpointer user_data,
64 GDestroyNotify user_data_destroy) G_GNUC_WARN_UNUSED_RESULT;
65 DEX_AVAILABLE_IN_1_2
66 DexFuture *dex_limiter_run_on_pool (DexLimiter *limiter,
67 DexThreadPool *pool,
68 DexThreadFunc thread_func,
69 gpointer user_data,
70 GDestroyNotify user_data_destroy) G_GNUC_WARN_UNUSED_RESULT;
71 DEX_AVAILABLE_IN_1_2
72 void dex_limiter_close (DexLimiter *limiter);
73
74 G_DEFINE_AUTOPTR_CLEANUP_FUNC (DexLimiter, dex_unref)
75
76 G_END_DECLS