Lely core libraries 2.3.4
thrd_loop.c File Reference

This file is part of the event library; it contains the implementation of the thread-local event loop functions. More...

#include "ev.h"
#include <lely/ev/exec.h>
#include <lely/ev/task.h>
#include <lely/ev/thrd_loop.h>
#include <assert.h>
#include <stdint.h>
Include dependency graph for thrd_loop.c:

Go to the source code of this file.

Data Structures

struct  ev_thrd_loop
 A thread-local event loop. More...
 

Functions

static struct ev_thrd_loopev_thrd_loop (void)
 Returns a pointer to the thread-local event loop.
 
ev_exec_tev_thrd_loop_get_exec (void)
 Returns a pointer to the executor corresponding to the thread-local event loop. More...
 
void ev_thrd_loop_stop (void)
 Stops the thread-local event loop. More...
 
int ev_thrd_loop_stopped (void)
 Returns 1 if the thread-local event loop is stopped, and 0 if not.
 
void ev_thrd_loop_restart (void)
 Restarts a thread-local event loop. More...
 
size_t ev_thrd_loop_run (void)
 If the thread-local event loop is not stopped, run all available tasks. More...
 
size_t ev_thrd_loop_run_one (void)
 If the thread-local event loop is not stopped, executes the first task submitted to it, if available. More...
 

Detailed Description

This file is part of the event library; it contains the implementation of the thread-local event loop functions.

See also
lely/ev/thrd_loop.h
Author
J. S. Seldenthuis jseld.nosp@m.enth.nosp@m.uis@l.nosp@m.ely..nosp@m.com

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition in file thrd_loop.c.

Function Documentation

◆ ev_thrd_loop_get_exec()

ev_exec_t * ev_thrd_loop_get_exec ( void  )

Returns a pointer to the executor corresponding to the thread-local event loop.

This pointer is shared between all threads.

Definition at line 75 of file thrd_loop.c.

◆ ev_thrd_loop_stop()

void ev_thrd_loop_stop ( void  )

Stops the thread-local event loop.

Subsequent calls to ev_thrd_loop_run() and ev_thrd_loop_run_one() will return 0 immediately.

Postcondition
ev_thrd_loop_stopped() returns 1.

Definition at line 83 of file thrd_loop.c.

◆ ev_thrd_loop_restart()

void ev_thrd_loop_restart ( void  )

Restarts a thread-local event loop.

Postcondition
ev_thrd_loop_stopped() returns 0.

Definition at line 95 of file thrd_loop.c.

◆ ev_thrd_loop_run()

size_t ev_thrd_loop_run ( void  )

If the thread-local event loop is not stopped, run all available tasks.

If, afterwards, no outstanding work remains, performs ev_thrd_loop_stop().

Returns
the number of executed tasks.

Definition at line 101 of file thrd_loop.c.

◆ ev_thrd_loop_run_one()

size_t ev_thrd_loop_run_one ( void  )

If the thread-local event loop is not stopped, executes the first task submitted to it, if available.

If, afterwards, no outstanding work remains, performs ev_thrd_loop_stop().

Returns
1 if a task was executed, and 0 if not.

Definition at line 110 of file thrd_loop.c.