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+ -->
6 <refentry id=
"sd_event_source_unref" xmlns:
xi=
"http://www.w3.org/2001/XInclude">
9 <title>sd_event_source_unref
</title>
10 <productname>systemd
</productname>
14 <refentrytitle>sd_event_source_unref
</refentrytitle>
15 <manvolnum>3</manvolnum>
19 <refname>sd_event_source_unref
</refname>
20 <refname>sd_event_source_unrefp
</refname>
21 <refname>sd_event_source_ref
</refname>
22 <refname>sd_event_source_disable_unref
</refname>
23 <refname>sd_event_source_disable_unrefp
</refname>
25 <refpurpose>Increase or decrease event source reference counters
</refpurpose>
30 <funcsynopsisinfo>#include
<systemd/sd-event.h
></funcsynopsisinfo>
33 <funcdef>sd_event_source*
<function>sd_event_source_unref
</function></funcdef>
34 <paramdef>sd_event_source *
<parameter>source
</parameter></paramdef>
38 <funcdef>void
<function>sd_event_source_unrefp
</function></funcdef>
39 <paramdef>sd_event_source **
<parameter>source
</parameter></paramdef>
43 <funcdef>sd_event_source*
<function>sd_event_source_ref
</function></funcdef>
44 <paramdef>sd_event_source *
<parameter>source
</parameter></paramdef>
48 <funcdef>sd_event_source*
<function>sd_event_source_disable_unref
</function></funcdef>
49 <paramdef>sd_event_source *
<parameter>source
</parameter></paramdef>
53 <funcdef>void
<function>sd_event_source_disable_unrefp
</function></funcdef>
54 <paramdef>sd_event_source **
<parameter>source
</parameter></paramdef>
60 <title>Description
</title>
62 <para><function>sd_event_source_unref()
</function> may be used to
63 decrement by one the reference counter of the event source object
64 specified as
<parameter>source
</parameter>. The reference counter
65 is initially set to one, when the event source is created with calls
67 <citerefentry><refentrytitle>sd_event_add_io
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
69 <citerefentry><refentrytitle>sd_event_add_time
</refentrytitle><manvolnum>3</manvolnum></citerefentry>. When
70 the reference counter reaches zero it is removed from its event loop
71 object and destroyed.
</para>
73 <para><function>sd_event_source_unrefp()
</function> is similar to
74 <function>sd_event_source_unref()
</function> but takes a pointer to a
75 pointer to an
<type>sd_event_source
</type> object. This call is useful in
76 conjunction with GCC's and LLVM's
<ulink
77 url=
"https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html">Clean-up
78 Variable Attribute
</ulink>. Note that this function is defined as
79 inline function.
</para>
81 <para><function>sd_event_source_ref()
</function> may be used
82 to increase by one the reference counter of the event source object
83 specified as
<parameter>source
</parameter>.
</para>
85 <para><function>sd_event_source_unref()
</function>,
86 <function>sd_bus_creds_unrefp()
</function> and
87 <function>sd_bus_creds_ref()
</function> execute no operation if
88 the passed event source object is
89 <constant>NULL
</constant>.
</para>
91 <para>Note that event source objects stay alive and may be dispatched as long as they have a reference
92 counter greater than zero. In order to drop a reference of an event source and make sure the associated
93 event source handler function is not called anymore it is recommended to combine a call of
94 <function>sd_event_source_unref()
</function> with a prior call to
95 <function>sd_event_source_set_enabled()
</function> with
<constant>SD_EVENT_OFF
</constant> or call
96 <function>sd_event_source_disable_unref()
</function>, see below.
</para>
98 <para><function>sd_event_source_disable_unref()
</function> combines a call to
99 <function>sd_event_source_set_enabled()
</function> with
<constant>SD_EVENT_OFF
</constant> with
100 <function>sd_event_source_unref()
</function>. This ensures that the source is disabled before the local
101 reference to it is lost. The
<parameter>source
</parameter> parameter is allowed to be
102 <constant>NULL
</constant>.
</para>
104 <para><function>sd_event_source_disable_unrefp()
</function> is similar to
105 <function>sd_event_source_unrefp()
</function>, but in addition disables the source first. This call is
106 useful in conjunction with GCC's and LLVM's
107 <ulink url=
"https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html">Clean-up Variable
108 Attribute
</ulink>. Note that this function is defined as inline function.
</para>
112 <title>Return Value
</title>
114 <para><function>sd_event_source_unref()
</function> and
115 <function>sd_event_source_disable_unref()
</function> always return
<constant>NULL
</constant>.
116 <function>sd_event_source_ref()
</function> always returns the event source object passed in.
</para>
119 <xi:include href=
"libsystemd-pkgconfig.xml" />
122 <title>See Also
</title>
125 <citerefentry><refentrytitle>sd-event
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
126 <citerefentry><refentrytitle>sd_event_add_io
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
127 <citerefentry><refentrytitle>sd_event_add_time
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
128 <citerefentry><refentrytitle>sd_event_add_signal
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
129 <citerefentry><refentrytitle>sd_event_add_child
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
130 <citerefentry><refentrytitle>sd_event_add_inotify
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
131 <citerefentry><refentrytitle>sd_event_add_defer
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
132 <citerefentry><refentrytitle>sd_event_source_set_enabled
</refentrytitle><manvolnum>3</manvolnum></citerefentry>