File: thread_scheduler.h

package info (click to toggle)
aws-crt-python 0.20.4%2Bdfsg-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 72,656 kB
  • sloc: ansic: 381,805; python: 23,008; makefile: 6,251; sh: 4,536; cpp: 699; ruby: 208; java: 77; perl: 73; javascript: 46; xml: 11
file content (63 lines) | stat: -rw-r--r-- 2,003 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef AWS_COMMON_THREAD_SCHEDULER_H
#define AWS_COMMON_THREAD_SCHEDULER_H
/**
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */

#include <aws/common/common.h>

AWS_PUSH_SANE_WARNING_LEVEL

struct aws_thread_scheduler;
struct aws_thread_options;
struct aws_task;

AWS_EXTERN_C_BEGIN

/**
 * Creates a new instance of a thread scheduler. This object receives scheduled tasks and executes them inside a
 * background thread. On success, this function returns an instance with a ref-count of 1. On failure it returns NULL.
 *
 * thread_options are optional.
 *
 * The semantics of this interface conform to the semantics of aws_task_scheduler.
 */
AWS_COMMON_API
struct aws_thread_scheduler *aws_thread_scheduler_new(
    struct aws_allocator *allocator,
    const struct aws_thread_options *thread_options);

/**
 * Acquire a reference to the scheduler.
 */
AWS_COMMON_API void aws_thread_scheduler_acquire(struct aws_thread_scheduler *scheduler);

/**
 * Release a reference to the scheduler.
 */
AWS_COMMON_API void aws_thread_scheduler_release(const struct aws_thread_scheduler *scheduler);

/**
 * Schedules a task to run in the future. time_to_run is the absolute time from the system hw_clock.
 */
AWS_COMMON_API void aws_thread_scheduler_schedule_future(
    struct aws_thread_scheduler *scheduler,
    struct aws_task *task,
    uint64_t time_to_run);

/**
 * Schedules a task to run as soon as possible.
 */
AWS_COMMON_API void aws_thread_scheduler_schedule_now(struct aws_thread_scheduler *scheduler, struct aws_task *task);

/**
 * Cancel a task that has been scheduled. The cancellation callback will be invoked in the background thread.
 * This function is slow, so please don't do it in the hot path for your code.
 */
AWS_COMMON_API void aws_thread_scheduler_cancel_task(struct aws_thread_scheduler *scheduler, struct aws_task *task);

AWS_EXTERN_C_END
AWS_POP_SANE_WARNING_LEVEL

#endif /* AWS_COMMON_THREAD_SCHEDULER_H */