1 <?xml version='
1.0'
?> <!--*- Mode: nxml; nxml-child-indent: 2; indent-tabs-mode: nil -*-->
2 <!DOCTYPE refentry PUBLIC
"-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
6 SPDX-License-Identifier: LGPL-2.1+
8 This file is part of systemd.
10 Copyright 2015 Lennart Poettering
13 <refentry id=
"sd_event_source_set_priority" xmlns:
xi=
"http://www.w3.org/2001/XInclude">
16 <title>sd_event_source_set_priority
</title>
17 <productname>systemd
</productname>
21 <contrib>Developer
</contrib>
22 <firstname>Lennart
</firstname>
23 <surname>Poettering
</surname>
24 <email>lennart@poettering.net
</email>
30 <refentrytitle>sd_event_source_set_priority
</refentrytitle>
31 <manvolnum>3</manvolnum>
35 <refname>sd_event_source_set_priority
</refname>
36 <refname>sd_event_source_get_priority
</refname>
37 <refname>SD_EVENT_PRIORITY_IMPORTANT
</refname>
38 <refname>SD_EVENT_PRIORITY_NORMAL
</refname>
39 <refname>SD_EVENT_PRIORITY_IDLE
</refname>
41 <refpurpose>Set or retrieve the priority of event sources
</refpurpose>
46 <funcsynopsisinfo>#include
<systemd/sd-event.h
></funcsynopsisinfo>
48 <funcsynopsisinfo><token>enum
</token> {
49 <constant>SD_EVENT_PRIORITY_IMPORTANT
</constant> = -
100,
50 <constant>SD_EVENT_PRIORITY_NORMAL
</constant> =
0,
51 <constant>SD_EVENT_PRIORITY_IDLE
</constant> =
100,
55 <funcdef>int
<function>sd_event_source_set_priority
</function></funcdef>
56 <paramdef>sd_event_source *
<parameter>source
</parameter></paramdef>
57 <paramdef>int64_t
<parameter>priority
</parameter></paramdef>
61 <funcdef>int
<function>sd_event_source_get_priority
</function></funcdef>
62 <paramdef>sd_event_source *
<parameter>source
</parameter></paramdef>
63 <paramdef>int64_t *
<parameter>priority
</parameter></paramdef>
70 <title>Description
</title>
72 <para><function>sd_event_source_set_priority()
</function> may be
73 used to set the priority for the event source object specified as
74 <parameter>source
</parameter>. The priority is specified as an
75 arbitrary signed
64bit integer. The priority is initialized to
76 <constant>SD_EVENT_PRIORITY_NORMAL
</constant> (
0) when the event
77 source is allocated with a call such as
78 <citerefentry><refentrytitle>sd_event_add_io
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
80 <citerefentry><refentrytitle>sd_event_add_time
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
81 and may be changed with this call. If multiple event sources have seen events at the same time, they are dispatched in the order indicated by the
82 event sources' priorities. Event sources with smaller priority
83 values are dispatched first. As well-known points of reference,
84 the constants
<constant>SD_EVENT_PRIORITY_IMPORTANT
</constant>
85 (-
100),
<constant>SD_EVENT_PRIORITY_NORMAL
</constant> (
0) and
86 <constant>SD_EVENT_PRIORITY_IDLE
</constant> (
100) may be used to
87 indicate event sources that shall be dispatched early, normally or
88 late. It is recommended to specify priorities based on these
89 definitions, and relative to them — however, the full
64bit
90 signed integer range is available for ordering event
93 <para>Priorities define the order in which event sources that have
94 seen events are dispatched. Care should be taken to ensure that
95 high-priority event sources (those with negative priority values
96 assigned) do not cause starvation of low-priority event sources
97 (those with positive priority values assigned).
</para>
99 <para>The order in which event sources with the same priority are
100 dispatched is undefined, but the event loop generally tries to
101 dispatch them in the order it learnt about events on them. As the
102 backing kernel primitives do not provide accurate information
103 about the order in which events occurred this is not necessarily
104 reliable. However, it is guaranteed that if events are seen on
105 multiple same-priority event sources at the same time, each one is
106 not dispatched again until all others have been dispatched
107 once. This behavior guarantees that within each priority
108 particular event sources do not starve or dominate the event
111 <para><function>sd_event_source_get_priority()
</function> may be
112 used to query the current priority assigned to the event source
113 object
<parameter>source
</parameter>.
</para>
117 <title>Return Value
</title>
120 <function>sd_event_source_set_priority()
</function> and
121 <function>sd_event_source_get_priority()
</function> return a
122 non-negative integer. On failure, they return a negative
123 errno-style error code.
</para>
127 <title>Errors
</title>
129 <para>Returned errors may indicate the following problems:
</para>
133 <term><constant>-EINVAL
</constant></term>
135 <listitem><para><parameter>source
</parameter> is not a valid
136 pointer to an
<structname>sd_event_source
</structname>
137 object.
</para></listitem>
141 <term><constant>-ENOMEM
</constant></term>
143 <listitem><para>Not enough memory.
</para></listitem>
147 <term><constant>-ESTALE
</constant></term>
149 <listitem><para>The event loop is already terminated.
</para></listitem>
154 <term><constant>-ECHILD
</constant></term>
156 <listitem><para>The event loop has been created in a different process.
</para></listitem>
163 <xi:include href=
"libsystemd-pkgconfig.xml" />
166 <title>See Also
</title>
169 <citerefentry><refentrytitle>sd-event
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
170 <citerefentry><refentrytitle>sd_event_add_io
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
171 <citerefentry><refentrytitle>sd_event_add_time
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
172 <citerefentry><refentrytitle>sd_event_add_child
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
173 <citerefentry><refentrytitle>sd_event_add_signal
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
174 <citerefentry><refentrytitle>sd_event_add_defer
</refentrytitle><manvolnum>3</manvolnum></citerefentry>