1<?xml version='1.0'?> 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 --> 5 6<refentry id="sd_event_source_set_floating" xmlns:xi="http://www.w3.org/2001/XInclude"> 7 8 <refentryinfo> 9 <title>sd_event_source_set_floating</title> 10 <productname>systemd</productname> 11 </refentryinfo> 12 13 <refmeta> 14 <refentrytitle>sd_event_source_set_floating</refentrytitle> 15 <manvolnum>3</manvolnum> 16 </refmeta> 17 18 <refnamediv> 19 <refname>sd_event_source_set_floating</refname> 20 <refname>sd_event_source_get_floating</refname> 21 22 <refpurpose>Set or retrieve 'floating' state of event sources</refpurpose> 23 </refnamediv> 24 25 <refsynopsisdiv> 26 <funcsynopsis> 27 <funcsynopsisinfo>#include <systemd/sd-event.h></funcsynopsisinfo> 28 29 <funcprototype> 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> 33 </funcprototype> 34 35 <funcprototype> 36 <funcdef>int <function>sd_event_source_get_floating</function></funcdef> 37 <paramdef>sd_event_source *<parameter>source</parameter></paramdef> 38 </funcprototype> 39 40 </funcsynopsis> 41 </refsynopsisdiv> 42 43 <refsect1> 44 <title>Description</title> 45 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> 53 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> 63 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> 67 </refsect1> 68 69 <refsect1> 70 <title>Return Value</title> 71 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> 75 76 <refsect2> 77 <title>Errors</title> 78 79 <para>Returned errors may indicate the following problems:</para> 80 81 <variablelist> 82 <varlistentry> 83 <term><constant>-EINVAL</constant></term> 84 85 <listitem><para><parameter>source</parameter> is not a valid pointer to an 86 <structname>sd_event_source</structname> object.</para></listitem> 87 </varlistentry> 88 89 <varlistentry> 90 <term><constant>-ECHILD</constant></term> 91 92 <listitem><para>The event loop has been created in a different process.</para></listitem> 93 94 </varlistentry> 95 96 </variablelist> 97 </refsect2> 98 </refsect1> 99 100 <xi:include href="libsystemd-pkgconfig.xml" /> 101 102 <refsect1> 103 <title>See Also</title> 104 105 <para> 106 <citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry>, 107 <citerefentry><refentrytitle>sd_event_add_io</refentrytitle><manvolnum>3</manvolnum></citerefentry>, 108 <citerefentry><refentrytitle>sd_event_add_time</refentrytitle><manvolnum>3</manvolnum></citerefentry>, 109 <citerefentry><refentrytitle>sd_event_add_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry>, 110 <citerefentry><refentrytitle>sd_event_add_child</refentrytitle><manvolnum>3</manvolnum></citerefentry>, 111 <citerefentry><refentrytitle>sd_event_add_inotify</refentrytitle><manvolnum>3</manvolnum></citerefentry>, 112 <citerefentry><refentrytitle>sd_event_add_defer</refentrytitle><manvolnum>3</manvolnum></citerefentry>, 113 <citerefentry><refentrytitle>sd_event_source_set_description</refentrytitle><manvolnum>3</manvolnum></citerefentry>, 114 <citerefentry><refentrytitle>sd_event_source_set_priority</refentrytitle><manvolnum>3</manvolnum></citerefentry> 115 </para> 116 </refsect1> 117 118</refentry> 119