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 Copyright 2015 Lennart Poettering
11 <refentry id="sd_event_source_set_priority" xmlns:xi="http://www.w3.org/2001/XInclude">
14 <title>sd_event_source_set_priority</title>
15 <productname>elogind</productname>
19 <contrib>Developer</contrib>
20 <firstname>Lennart</firstname>
21 <surname>Poettering</surname>
22 <email>lennart@poettering.net</email>
28 <refentrytitle>sd_event_source_set_priority</refentrytitle>
29 <manvolnum>3</manvolnum>
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>
39 <refpurpose>Set or retrieve the priority of event sources</refpurpose>
44 <funcsynopsisinfo>#include <elogind/sd-event.h></funcsynopsisinfo>
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,
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>
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>
68 <title>Description</title>
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>
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
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>
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
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
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>
121 <title>Return Value</title>
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>
131 <title>Errors</title>
133 <para>Returned errors may indicate the following problems:</para>
137 <term><constant>-EINVAL</constant></term>
139 <listitem><para><parameter>source</parameter> is not a valid
140 pointer to an <structname>sd_event_source</structname>
141 object.</para></listitem>
145 <term><constant>-ENOMEM</constant></term>
147 <listitem><para>Not enough memory.</para></listitem>
151 <term><constant>-ESTALE</constant></term>
153 <listitem><para>The event loop is already terminated.</para></listitem>
158 <term><constant>-ECHILD</constant></term>
160 <listitem><para>The event loop has been created in a different process.</para></listitem>
167 <xi:include href="libelogind-pkgconfig.xml" />
170 <title>See Also</title>
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>