chiark / gitweb /
tree-wide: drop 'This file is part of systemd' blurb
[elogind.git] / man / sd_event_source_set_priority.xml
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">
4
5 <!--
6   SPDX-License-Identifier: LGPL-2.1+
7
8   Copyright 2015 Lennart Poettering
9 -->
10
11 <refentry id="sd_event_source_set_priority" xmlns:xi="http://www.w3.org/2001/XInclude">
12
13   <refentryinfo>
14     <title>sd_event_source_set_priority</title>
15     <productname>elogind</productname>
16
17     <authorgroup>
18       <author>
19         <contrib>Developer</contrib>
20         <firstname>Lennart</firstname>
21         <surname>Poettering</surname>
22         <email>lennart@poettering.net</email>
23       </author>
24     </authorgroup>
25   </refentryinfo>
26
27   <refmeta>
28     <refentrytitle>sd_event_source_set_priority</refentrytitle>
29     <manvolnum>3</manvolnum>
30   </refmeta>
31
32   <refnamediv>
33     <refname>sd_event_source_set_priority</refname>
34     <refname>sd_event_source_get_priority</refname>
35     <refname>SD_EVENT_PRIORITY_IMPORTANT</refname>
36     <refname>SD_EVENT_PRIORITY_NORMAL</refname>
37     <refname>SD_EVENT_PRIORITY_IDLE</refname>
38
39     <refpurpose>Set or retrieve the priority of event sources</refpurpose>
40   </refnamediv>
41
42   <refsynopsisdiv>
43     <funcsynopsis>
44       <funcsynopsisinfo>#include &lt;elogind/sd-event.h&gt;</funcsynopsisinfo>
45
46       <funcsynopsisinfo><token>enum</token> {
47         <constant>SD_EVENT_PRIORITY_IMPORTANT</constant> = -100,
48         <constant>SD_EVENT_PRIORITY_NORMAL</constant> = 0,
49         <constant>SD_EVENT_PRIORITY_IDLE</constant> = 100,
50 };</funcsynopsisinfo>
51
52       <funcprototype>
53         <funcdef>int <function>sd_event_source_set_priority</function></funcdef>
54         <paramdef>sd_event_source *<parameter>source</parameter></paramdef>
55         <paramdef>int64_t <parameter>priority</parameter></paramdef>
56       </funcprototype>
57
58       <funcprototype>
59         <funcdef>int <function>sd_event_source_get_priority</function></funcdef>
60         <paramdef>sd_event_source *<parameter>source</parameter></paramdef>
61         <paramdef>int64_t *<parameter>priority</parameter></paramdef>
62       </funcprototype>
63
64     </funcsynopsis>
65   </refsynopsisdiv>
66
67   <refsect1>
68     <title>Description</title>
69
70     <para><function>sd_event_source_set_priority()</function> may be
71     used to set the priority for the event source object specified as
72     <parameter>source</parameter>. The priority is specified as an
73     arbitrary signed 64bit integer. The priority is initialized to
74     <constant>SD_EVENT_PRIORITY_NORMAL</constant> (0) when the event
75     source is allocated with a call such as
76     <citerefentry><refentrytitle>sd_event_add_io</refentrytitle><manvolnum>3</manvolnum></citerefentry>
77     or
78     <citerefentry><refentrytitle>sd_event_add_time</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
79     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
80     event sources' priorities. Event sources with smaller priority
81     values are dispatched first. As well-known points of reference,
82     the constants <constant>SD_EVENT_PRIORITY_IMPORTANT</constant>
83     (-100), <constant>SD_EVENT_PRIORITY_NORMAL</constant> (0) and
84     <constant>SD_EVENT_PRIORITY_IDLE</constant> (100) may be used to
85     indicate event sources that shall be dispatched early, normally or
86     late. It is recommended to specify priorities based on these
87     definitions, and relative to them — however, the full 64bit
88     signed integer range is available for ordering event
89     sources.</para>
90
91     <para>Priorities define the order in which event sources that have
92     seen events are dispatched. Care should be taken to ensure that
93     high-priority event sources (those with negative priority values
94     assigned) do not cause starvation of low-priority event sources
95     (those with positive priority values assigned).</para>
96
97     <para>The order in which event sources with the same priority are
98     dispatched is undefined, but the event loop generally tries to
99     dispatch them in the order it learnt about events on them. As the
100     backing kernel primitives do not provide accurate information
101     about the order in which events occurred this is not necessarily
102     reliable. However, it is guaranteed that if events are seen on
103     multiple same-priority event sources at the same time, each one is
104     not dispatched again until all others have been dispatched
105     once. This behavior guarantees that within each priority
106     particular event sources do not starve or dominate the event
107     loop.</para>
108
109     <para>The priority of event sources may be changed at any time of their lifetime, with the exception of inotify
110     event sources (i.e. those created with
111     <citerefentry><refentrytitle>sd_event_add_inotify</refentrytitle><manvolnum>3</manvolnum></citerefentry>) whose
112     priority may only be changed in the time between their initial creation and the first subsequent event loop
113     iteration.</para>
114
115     <para><function>sd_event_source_get_priority()</function> may be
116     used to query the current priority assigned to the event source
117     object <parameter>source</parameter>.</para>
118   </refsect1>
119
120   <refsect1>
121     <title>Return Value</title>
122
123     <para>On success,
124     <function>sd_event_source_set_priority()</function> and
125     <function>sd_event_source_get_priority()</function> return a
126     non-negative integer. On failure, they return a negative
127     errno-style error code.</para>
128   </refsect1>
129
130   <refsect1>
131     <title>Errors</title>
132
133     <para>Returned errors may indicate the following problems:</para>
134
135     <variablelist>
136       <varlistentry>
137         <term><constant>-EINVAL</constant></term>
138
139         <listitem><para><parameter>source</parameter> is not a valid
140         pointer to an <structname>sd_event_source</structname>
141         object.</para></listitem>
142       </varlistentry>
143
144       <varlistentry>
145         <term><constant>-ENOMEM</constant></term>
146
147         <listitem><para>Not enough memory.</para></listitem>
148       </varlistentry>
149
150       <varlistentry>
151         <term><constant>-ESTALE</constant></term>
152
153         <listitem><para>The event loop is already terminated.</para></listitem>
154
155       </varlistentry>
156
157       <varlistentry>
158         <term><constant>-ECHILD</constant></term>
159
160         <listitem><para>The event loop has been created in a different process.</para></listitem>
161
162       </varlistentry>
163
164     </variablelist>
165   </refsect1>
166
167   <xi:include href="libelogind-pkgconfig.xml" />
168
169   <refsect1>
170     <title>See Also</title>
171
172     <para>
173       <citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
174       <citerefentry><refentrytitle>sd_event_add_io</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
175       <citerefentry><refentrytitle>sd_event_add_time</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
176       <citerefentry><refentrytitle>sd_event_add_child</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
177       <citerefentry><refentrytitle>sd_event_add_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
178       <citerefentry><refentrytitle>sd_event_add_defer</refentrytitle><manvolnum>3</manvolnum></citerefentry>
179     </para>
180   </refsect1>
181
182 </refentry>