Debian Codegraph @

crt/aws-c-common/include/aws/common/thread_scheduler.h

raw symbols SCIP
1 #ifndef AWS_COMMON_THREAD_SCHEDULER_H
2 #define AWS_COMMON_THREAD_SCHEDULER_H
3 /**
4 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * SPDX-License-Identifier: Apache-2.0.
6 */
7
8 #include <aws/common/common.h>
9
10 AWS_PUSH_SANE_WARNING_LEVEL
11
12 struct aws_thread_scheduler;
13 struct aws_thread_options;
14 struct aws_task;
15
16 AWS_EXTERN_C_BEGIN
17
18 /**
19 * Creates a new instance of a thread scheduler. This object receives scheduled tasks and executes them inside a
20 * background thread. On success, this function returns an instance with a ref-count of 1. On failure it returns NULL.
21 *
22 * thread_options are optional.
23 *
24 * The semantics of this interface conform to the semantics of aws_task_scheduler.
25 */
26 AWS_COMMON_API
27 struct aws_thread_scheduler *aws_thread_scheduler_new(
28 struct aws_allocator *allocator,
29 const struct aws_thread_options *thread_options);
30
31 /**
32 * Acquire a reference to the scheduler.
33 */
34 AWS_COMMON_API void aws_thread_scheduler_acquire(struct aws_thread_scheduler *scheduler);
35
36 /**
37 * Release a reference to the scheduler.
38 */
39 AWS_COMMON_API void aws_thread_scheduler_release(const struct aws_thread_scheduler *scheduler);
40
41 /**
42 * Schedules a task to run in the future. time_to_run is the absolute time from the system hw_clock.
43 */
44 AWS_COMMON_API void aws_thread_scheduler_schedule_future(
45 struct aws_thread_scheduler *scheduler,
46 struct aws_task *task,
47 uint64_t time_to_run);
48
49 /**
50 * Schedules a task to run as soon as possible.
51 */
52 AWS_COMMON_API void aws_thread_scheduler_schedule_now(struct aws_thread_scheduler *scheduler, struct aws_task *task);
53
54 /**
55 * Cancel a task that has been scheduled. The cancellation callback will be invoked in the background thread.
56 * This function is slow, so please don't do it in the hot path for your code.
57 */
58 AWS_COMMON_API void aws_thread_scheduler_cancel_task(struct aws_thread_scheduler *scheduler, struct aws_task *task);
59
60 AWS_EXTERN_C_END
61 AWS_POP_SANE_WARNING_LEVEL
62
63 #endif /* AWS_COMMON_THREAD_SCHEDULER_H */