2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4 <!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
6 <refentry id="sd_event_source_set_floating" xmlns:xi="http://www.w3.org/2001/XInclude">
9 <title>sd_event_source_set_floating</title>
10 <productname>systemd</productname>
14 <refentrytitle>sd_event_source_set_floating</refentrytitle>
15 <manvolnum>3</manvolnum>
19 <refname>sd_event_source_set_floating</refname>
20 <refname>sd_event_source_get_floating</refname>
22 <refpurpose>Set or retrieve 'floating' state of event sources</refpurpose>
27 <funcsynopsisinfo>#include <systemd/sd-event.h></funcsynopsisinfo>
30 <funcdef>int <function>sd_event_source_set_floating</function></funcdef>
31 <paramdef>sd_event_source *<parameter>source</parameter></paramdef>
32 <paramdef>int <parameter>floating</parameter></paramdef>
36 <funcdef>int <function>sd_event_source_get_floating</function></funcdef>
37 <paramdef>sd_event_source *<parameter>source</parameter></paramdef>
44 <title>Description</title>
46 <para><function>sd_event_source_set_floating()</function> takes a boolean and sets the 'floating' state
47 of the specified event source object. This is used to change the direction of reference counts for the
48 object and the event loop it is associated with. In non-floating mode, the event source object holds a
49 reference to the event loop object, but not vice versa. The creator of the event source object must hold
50 a reference to it as long as the source should exist. In floating mode, the event loop holds a reference
51 to the source object, and will decrease the reference count when being freed. This means that a reference
52 to the event loop should be held to prevent both from being destroyed.</para>
54 <para>Various calls that allocate event source objects (i.e.
55 <citerefentry><refentrytitle>sd_event_add_io</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
56 <citerefentry><refentrytitle>sd_event_add_time</refentrytitle><manvolnum>3</manvolnum></citerefentry> and
57 similar) will automatically set an event source object to 'floating' mode if the caller passed
58 <constant>NULL</constant> in the parameter used to return a reference to the event source object.
59 Nevertheless, it may be necessary to gain temporary access to the source object, for example to adjust
60 event source properties after allocation (e.g. its priority or description string). In those cases the
61 object may be created in non-floating mode, and the returned reference used to adjust the properties, and
62 the object marked as floating afterwards, and the reference in the caller dropped.</para>
64 <para><function>sd_event_source_get_floating()</function> may be used to query the current 'floating'
65 state of the event source object <parameter>source</parameter>. It returns zero if 'floating' mode is
66 off, positive if it is on.</para>
70 <title>Return Value</title>
72 <para>On success, <function>sd_event_source_set_floating()</function> and
73 <function>sd_event_source_get_floating()</function> return a non-negative integer. On failure, they
74 return a negative errno-style error code.</para>
79 <para>Returned errors may indicate the following problems:</para>
83 <term><constant>-EINVAL</constant></term>
85 <listitem><para><parameter>source</parameter> is not a valid pointer to an
86 <structname>sd_event_source</structname> object.</para>
88 <xi:include href="version-info.xml" xpointer="v244"/></listitem>
92 <term><constant>-ECHILD</constant></term>
94 <listitem><para>The event loop has been created in a different process, library or module instance.</para>
96 <xi:include href="version-info.xml" xpointer="v244"/></listitem>
104 <xi:include href="libsystemd-pkgconfig.xml" />
107 <title>History</title>
108 <para><function>sd_event_source_set_floating()</function> and
109 <function>sd_event_source_get_floating()</function> were added in version 244.</para>
113 <title>See Also</title>
116 <citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
117 <citerefentry><refentrytitle>sd_event_add_io</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
118 <citerefentry><refentrytitle>sd_event_add_time</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
119 <citerefentry><refentrytitle>sd_event_add_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
120 <citerefentry><refentrytitle>sd_event_add_child</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
121 <citerefentry><refentrytitle>sd_event_add_inotify</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
122 <citerefentry><refentrytitle>sd_event_add_defer</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
123 <citerefentry><refentrytitle>sd_event_source_set_description</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
124 <citerefentry><refentrytitle>sd_event_source_set_priority</refentrytitle><manvolnum>3</manvolnum></citerefentry>