| 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.5/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> |
| 87 |
|
| 88 |
<xi:include href="version-info.xml" xpointer="v244"/></listitem> |
| 89 |
</varlistentry> |
| 90 |
|
| 91 |
<varlistentry> |
| 92 |
<term><constant>-ECHILD</constant></term> |
| 93 |
|
| 94 |
<listitem><para>The event loop has been created in a different process, library or module instance.</para> |
| 95 |
|
| 96 |
<xi:include href="version-info.xml" xpointer="v244"/></listitem> |
| 97 |
|
| 98 |
</varlistentry> |
| 99 |
|
| 100 |
</variablelist> |
| 101 |
</refsect2> |
| 102 |
</refsect1> |
| 103 |
|
| 104 |
<xi:include href="libsystemd-pkgconfig.xml" /> |
| 105 |
|
| 106 |
<refsect1> |
| 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> |
| 110 |
</refsect1> |
| 111 |
|
| 112 |
<refsect1> |
| 113 |
<title>See Also</title> |
| 114 |
|
| 115 |
<para><simplelist type="inline"> |
| 116 |
<member><citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 117 |
<member><citerefentry><refentrytitle>sd_event_add_io</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 118 |
<member><citerefentry><refentrytitle>sd_event_add_time</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 119 |
<member><citerefentry><refentrytitle>sd_event_add_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 120 |
<member><citerefentry><refentrytitle>sd_event_add_child</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 121 |
<member><citerefentry><refentrytitle>sd_event_add_inotify</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 122 |
<member><citerefentry><refentrytitle>sd_event_add_defer</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 123 |
<member><citerefentry><refentrytitle>sd_event_source_set_description</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 124 |
<member><citerefentry><refentrytitle>sd_event_source_set_priority</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 125 |
</simplelist></para> |
| 126 |
</refsect1> |
| 127 |
|
| 128 |
</refentry> |