HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions
v1::loop Class Reference

Public Member Functions

 loop (loop const &)=delete
 
 loop (loop &&) noexcept=delete
 
loopoperator= (loop const &)=delete
 
loopoperator= (loop &&) noexcept=delete
 
void set_maximum_frame_rate (double frame_rate) noexcept
 Set maximum frame rate.
 
void set_vsync_monitor_id (uintptr_t id) noexcept
 Set the monitor id for vertical sync.
 
template<forward_of< void()> Func>
void wfree_post_function (Func &&func) noexcept
 Wait-free post a function to be called from the loop.
 
template<forward_of< void()> Func>
void post_function (Func &&func) noexcept
 Post a function to be called from the loop.
 
template<typename Func >
auto async_function (Func &&func) noexcept
 Call a function from the loop.
 
template<forward_of< void()> Func>
callback< void()> delay_function (utc_nanoseconds time_point, Func &&func) noexcept
 Call a function at a certain time.
 
template<forward_of< void()> Func>
callback< void()> repeat_function (std::chrono::nanoseconds period, utc_nanoseconds time_point, Func &&func) noexcept
 Call a function repeatedly.
 
template<forward_of< void()> Func>
callback< void()> repeat_function (std::chrono::nanoseconds period, Func &&func) noexcept
 Call a function repeatedly.
 
void subscribe_render (weak_callback< void(utc_nanoseconds)> callback) noexcept
 
template<forward_of< void(utc_nanoseconds)> Func>
callback< void(utc_nanoseconds)> subscribe_render (Func &&func) noexcept
 Subscribe a render function to be called on vsync.
 
void add_socket (int fd, socket_event event_mask, std::function< void(int, socket_events const &)> f)
 Add a callback that reacts on a socket.
 
void remove_socket (int fd)
 Remove the callback associated with a socket.
 
int resume (std::stop_token stop_token={}) noexcept
 Resume the loop on the current thread.
 
void resume_once (bool block=false) noexcept
 Resume for a single iteration.
 
bool on_thread () const noexcept
 Check if the current thread is the same as the loop's thread.
 

Static Public Member Functions

static looplocal () noexcept
 Get or create the thread-local loop.
 
static hi_no_inline loopmain () noexcept
 Get or create the main-loop.
 
static hi_no_inline looptimer () noexcept
 Get or create the timer event-loop.
 

Member Function Documentation

◆ add_socket()

void v1::loop::add_socket ( int fd,
socket_event event_mask,
std::function< void(int, socket_events const &)> f )
inline

Add a callback that reacts on a socket.

In most cases mode is set to one of the following values:

  • error | read: Unblock when there is data available for read.
  • error | write: Unblock when there is buffer space available for write.
  • error | read | write: Unblock when there is data available for read of when there is buffer space available for write.
Note
Only one callback can be associated with a socket.
Parameters
fdFile descriptor of the socket.
event_maskThe socket events to wait for.
fThe callback to call when the file descriptor unblocks.

◆ async_function()

template<typename Func >
auto v1::loop::async_function ( Func && func)
inlinenoexcept

Call a function from the loop.

Note
It is safe to call this function from another thread.
Parameters
funcThe function to call from the loop. The function must not take any argument, but may return a value.
Returns
A std::future for the return value.

◆ delay_function()

template<forward_of< void()> Func>
callback< void()> v1::loop::delay_function ( utc_nanoseconds time_point,
Func && func )
inlinenoexcept

Call a function at a certain time.

Parameters
time_pointThe time at which to call the function.
funcThe function to be called.

◆ local()

hi_no_inline loop & v1::loop::local ( )
inlinestaticnoexcept

Get or create the thread-local loop.

◆ main()

static hi_no_inline loop & v1::loop::main ( )
inlinestaticnoexcept

Get or create the main-loop.

Note
The first time main() is called must be from the main-thread. In this case there is no race condition on the first time main() is called.

◆ on_thread()

bool v1::loop::on_thread ( ) const
inlinenoexcept

Check if the current thread is the same as the loop's thread.

The loop's thread is the thread that calls resume().

◆ post_function()

template<forward_of< void()> Func>
void v1::loop::post_function ( Func && func)
inlinenoexcept

Post a function to be called from the loop.

Note
It is safe to call this function from another thread.
Parameters
funcThe function to call from the loop. The function must not take any arguments and return void.

◆ remove_socket()

void v1::loop::remove_socket ( int fd)
inline

Remove the callback associated with a socket.

Parameters
fdThe file descriptor of the socket.

◆ repeat_function() [1/2]

template<forward_of< void()> Func>
callback< void()> v1::loop::repeat_function ( std::chrono::nanoseconds period,
Func && func )
inlinenoexcept

Call a function repeatedly.

Parameters
periodThe period between calls to the function.
funcThe function to be called.

◆ repeat_function() [2/2]

template<forward_of< void()> Func>
callback< void()> v1::loop::repeat_function ( std::chrono::nanoseconds period,
utc_nanoseconds time_point,
Func && func )
inlinenoexcept

Call a function repeatedly.

Parameters
periodThe period between calls to the function.
time_pointThe time at which to call the function.
funcThe function to be called.

◆ resume()

int v1::loop::resume ( std::stop_token stop_token = {})
inlinenoexcept

Resume the loop on the current thread.

Parameters
stop_tokenThe thread's stop token to use to determine when to stop. If not stop token is given, then resume will automatically stop when there are no more windows, sockets, functions or timers.
Returns
Exit code when the loop is exited.

◆ resume_once()

void v1::loop::resume_once ( bool block = false)
inlinenoexcept

Resume for a single iteration.

The resume_once(false) may be used to continue processing events and GUI redraws while the GUI event queue is blocked. This happens on win32 when a window is being moved, resized, the title bar or system menu being clicked.

It should be called often, as it will be used to process network messages and latency of network processing will be increased based on the amount of times this function is called.

Note
This function must be called from the same thread as resume().
Parameters
blockAllow processing to block, this is normally done only inside resume().

◆ set_maximum_frame_rate()

void v1::loop::set_maximum_frame_rate ( double frame_rate)
inlinenoexcept

Set maximum frame rate.

A frame rate above 30.0 may will cause the vsync thread to block on

Parameters
frame_rateThe maximum frame rate that a window will be updated.

◆ set_vsync_monitor_id()

void v1::loop::set_vsync_monitor_id ( uintptr_t id)
inlinenoexcept

Set the monitor id for vertical sync.

◆ subscribe_render()

template<forward_of< void(utc_nanoseconds)> Func>
callback< void(utc_nanoseconds)> v1::loop::subscribe_render ( Func && func)
inlinenoexcept

Subscribe a render function to be called on vsync.

Parameters
fA function to be called when vsync occurs.

◆ timer()

static hi_no_inline loop & v1::loop::timer ( )
inlinestaticnoexcept

Get or create the timer event-loop.

Note
The first time this is called a thread is started to handle the timer events.

◆ wfree_post_function()

template<forward_of< void()> Func>
void v1::loop::wfree_post_function ( Func && func)
inlinenoexcept

Wait-free post a function to be called from the loop.

Note
It is safe to call this function from another thread.
The event loop is not directly notified that a new function exists and will be delayed until after the loop has woken for other work.
The post is only wait-free if the function fifo is not full, and the function is small enough to fit in a slot on the fifo.
Parameters
funcThe function to call from the loop. The function must not take any arguments and return void.

The documentation for this class was generated from the following file: