Movatterモバイル変換


[0]ホーム

URL:


man7.org > Linux >man-pages

Linux/UNIX system programming training


sd_event_new(3) — Linux manual page

NAME |SYNOPSIS |DESCRIPTION |RETURN VALUE |NOTES |HISTORY |SEE ALSO |NOTES |COLOPHON

SD_EVENT_NEW(3)                sd_event_newSD_EVENT_NEW(3)

NAME        top

       sd_event_new, sd_event_default, sd_event_ref, sd_event_unref,       sd_event_unrefp, sd_event_get_tid, sd_event - Acquire and release       an event loop object

SYNOPSIS        top

#include <systemd/sd-event.h>typedef struct sd_event sd_event;int sd_event_new(sd_event **event);int sd_event_default(sd_event **event);sd_event *sd_event_ref(sd_event *event);sd_event *sd_event_unref(sd_event *event);void sd_event_unrefp(sd_event **event);int sd_event_get_tid(sd_event *event, pid_t *ret);

DESCRIPTION        top

sd_event_new()allocates a new event loop object. The event loop       object is returned in theevent parameter. After use, drop the       returned reference withsd_event_unref(). When the last reference       is dropped, the object is freed.sd_event_default()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 withsd_event_unref(). 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 ofsd_event_new()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.       After allocating an event loop object, add event sources to it       withsd_event_add_io(3),sd_event_add_time(3),sd_event_add_signal(3),sd_event_add_child(3),sd_event_add_inotify(3),sd_event_add_defer(3),sd_event_add_post(3) orsd_event_add_exit(3), and then execute the       event loop usingsd_event_loop(3).sd_event_ref()increases the reference count of the specified       event loop object by one.sd_event_unref()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 withsd_event_default(), then releasing       it, and then acquiring a new one withsd_event_default()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.sd_event_unrefp()is similar tosd_event_unref()but takes a       pointer to a pointer to ansd_eventobject. This call is useful in       conjunction with GCC's and LLVM'sClean-up Variable Attribute[1].       Note that this function is defined as inline function. Use a       declaration like the following, in order to allocate an event loop       object that is freed automatically as the code block is left:           {                   __attribute__((cleanup(sd_event_unrefp))) sd_event *event = NULL;                   int r;                   ...                   r = sd_event_default(&event);                   if (r < 0) {                     errno = -r;                     fprintf(stderr, "Failed to allocate event loop: %m\n");                   }                   ...           }sd_event_ref(),sd_event_unref()andsd_event_unrefp()execute no       operation if the passed in event loop object isNULL.sd_event_get_tid()retrieves the thread identifier ("TID") of the       thread the specified event loop object is associated with. This       call is only supported for event loops allocated withsd_event_default(), and returns the identifier for the thread the       event loop is the default event loop of. Seegettid(2) for more       information on thread identifiers.

RETURN VALUE        top

       On success,sd_event_new(),sd_event_default()andsd_event_get_tid()return 0 or a positive integer. On failure,       they return a negative errno-style error code.sd_event_ref()       always returns a pointer to the event loop object passed in.sd_event_unref()always returnsNULL.Errors       Returned errors may indicate the following problems:-ENOMEM           Not enough memory to allocate the object.-EMFILE           The maximum number of event loops has been allocated.-ENXIOsd_event_get_tid()was invoked on an event loop object that           was not allocated withsd_event_default().

NOTES        top

       Functions described here are available as a shared library, which       can be compiled against and linked to with thelibsystemd pkg-config(1) file.       The code described here usesgetenv(3), which is declared to be       not multi-thread-safe. This means that the code calling the       functions described here must not callsetenv(3) from a parallel       thread. It is recommended to only do calls tosetenv()from an       early phase of the program when no other threads have been       started.

HISTORY        top

sd_event_new(),sd_event_default(),sd_event_ref(), andsd_event_unref()were added in version 213.sd_event_unrefp()andsd_event_get_tid()were added in version       229.

SEE ALSO        top

systemd(1),sd-event(3),sd_event_add_io(3),sd_event_add_time(3),sd_event_add_signal(3),sd_event_add_child(3),sd_event_add_inotify(3),sd_event_add_defer(3),sd_event_run(3),gettid(2)

NOTES        top

        1. Clean-up Variable Attributehttps://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html

COLOPHON        top

       This page is part of thesystemd (systemd system and service       manager) project.  Information about the project can be found at       ⟨http://www.freedesktop.org/wiki/Software/systemd⟩.  If you have a       bug report for this manual page, see       ⟨http://www.freedesktop.org/wiki/Software/systemd/#bugreports⟩.       This page was obtained from the project's upstream Git repository       ⟨https://github.com/systemd/systemd.git⟩ on 2025-08-11.  (At that       time, the date of the most recent commit that was found in the       repository was 2025-08-11.)  If you discover any rendering       problems in this HTML version of the page, or you believe there is       a better or more up-to-date source for the page, or you have       corrections or improvements to the information in this COLOPHON       (which isnot part of the original manual page), send a mail to       man-pages@man7.orgsystemd 258~rc2SD_EVENT_NEW(3)

Pages that refer to this page:sd-event(3)sd_event_add_child(3)sd_event_add_defer(3)sd_event_add_inotify(3)sd_event_add_io(3)sd_event_add_memory_pressure(3)sd_event_add_signal(3)sd_event_add_time(3)sd_event_exit(3)sd_event_get_fd(3)sd_event_now(3)sd_event_run(3)sd_event_set_signal_exit(3)sd_event_set_watchdog(3)sd_event_wait(3)systemd.directives(7)systemd.index(7)



HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface.

For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere.

Hosting byjambit GmbH.

Cover of TLPI


[8]ページ先頭

©2009-2025 Movatter.jp