summaryrefslogtreecommitdiff
path: root/man/sd_event_new.3
blob: d2449b725d474a6a5cc1a11dc29f9f045e3ec9d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
'\" t
.TH "SD_EVENT_NEW" "3" "" "systemd 221" "sd_event_new"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
sd_event_new, sd_event_default, sd_event_ref, sd_event_unref \- Acquire and release an event loop object
.SH "SYNOPSIS"
.sp
.ft B
.nf
#include <systemd/sd\-bus\&.h>
.fi
.ft
.HP \w'int\ sd_event_new('u
.BI "int sd_event_new(sd_bus\ **" "event" ");"
.HP \w'int\ sd_event_default('u
.BI "int sd_event_default(sd_bus\ **" "event" ");"
.HP \w'sd_bus\ *sd_event_ref('u
.BI "sd_bus *sd_event_ref(sd_bus\ *" "event" ");"
.HP \w'sd_bus\ *sd_event_unref('u
.BI "sd_bus *sd_event_unref(sd_bus\ *" "event" ");"
.SH "DESCRIPTION"
.PP
\fBsd_event_new()\fR
allocates a new event loop object\&. The event loop object is returned in the
\fIevent\fR
parameter\&. After use, drop the returned reference with
\fBsd_event_unref()\fR\&. When the last reference is dropped, the object is freed\&.
.PP
\fBsd_event_default()\fR
acquires a reference to the default event loop object of the calling thread, possibly allocating a new object if no default event loop object has been allocated yet for the thread\&. After use, drop the returned reference with
\fBsd_event_unref()\fR\&. When the last reference is dropped, the event loop is freed\&. If this function is called while the object returned from a previous call from the same thread is still referenced, the same object is returned again, but the reference is increased by one\&. It is recommended to use this call instead of
\fBsd_event_new()\fR
in order to share event loop objects between various components that are dispatched in the same thread\&. All threads have exactly either zero or one default event loop objects associated, but never more\&.
.PP
\fBsd_event_ref()\fR
increases the reference count of the specified event loop object by one\&.
.PP
\fBsd_event_unref()\fR
decreases the reference count of the specified event loop object by one\&. If the count hits zero, the object is freed\&. Note that it is freed regardless of whether it is the default event loop object for a thread or not\&. This means that allocating an event loop with
\fBsd_event_default()\fR, then releasing it, and then acquiring a new one with
\fBsd_event_default()\fR
will result in two distinct objects\&. Note that in order to free an event loop object, all remaining event sources of the event loop also need to be freed as each keeps a reference to it\&.
.SH "RETURN VALUE"
.PP
On success,
\fBsd_event_new()\fR
and
\fBsd_event_default()\fR
return 0 or a positive integer\&. On failure, they return a negative errno\-style error code\&.
\fBsd_event_ref()\fR
always returns a pointer to the event loop object passed in\&.
\fBsd_event_unref()\fR
always returns
\fBNULL\fR\&.
.SH "ERRORS"
.PP
Returned errors may indicate the following problems:
.PP
\fB\-ENOMEM\fR
.RS 4
Not enough memory to allocate the object\&.
.RE
.PP
\fB\-EMFILE\fR
.RS 4
The maximum number of event loops has been allocated\&.
.RE
.SH "NOTES"
.PP
\fBsd_event_new()\fR
and the other functions described here are available as a shared library, which can be compiled and linked to with the
\fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
file\&.
.SH "SEE ALSO"
.PP
\fBsystemd\fR(1),
\fBsd-event\fR(3),
\fBsd_event_add_io\fR(3),
\fBsd_event_add_time\fR(3),
\fBsd_event_add_signal\fR(3),
\fBsd_event_add_child\fR(3),
\fBsd_event_add_defer\fR(3),
\fBsd_event_add_post\fR(3),
\fBsd_event_add_exit\fR(3)