ssa: don't swap the arguments of comparison operators
[ajla.git] / iomux.h
blob1501a19714bb7f6f903b110a00e8acac7a02c546
1 /*
2 * Copyright (C) 2024 Mikulas Patocka
4 * This file is part of Ajla.
6 * Ajla is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software
8 * Foundation, either version 3 of the License, or (at your option) any later
9 * version.
11 * Ajla is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along with
16 * Ajla. If not, see <https://www.gnu.org/licenses/>.
19 #ifndef AJLA_IOMUX_H
20 #define AJLA_IOMUX_H
22 #include "os.h"
24 #define POLL_US 10000
25 #define POLL_WINCH_US 3000000
27 #if defined(OS_OS2) || defined(OS_WIN32)
28 #elif defined(HAVE_KQUEUE) && defined(HAVE_SYS_EVENT_H) && !defined(NO_DIR_HANDLES)
30 #define IOMUX_KQUEUE
32 #elif defined(HAVE_EPOLL_CREATE) && defined(HAVE_SYS_EPOLL_H)
34 #define IOMUX_EPOLL
35 #if defined(HAVE_INOTIFY_INIT) && defined(HAVE_SYS_INOTIFY_H)
36 #define IOMUX_EPOLL_INOTIFY
37 #endif
39 #else
41 #define IOMUX_SELECT
43 #endif
45 struct iomux_wait;
47 void iomux_enable_poll(void);
48 void iomux_never(mutex_t **mutex_to_lock, struct list *list_entry);
49 void iomux_register_wait(handle_t handle, bool wr, mutex_t **address_to_lock, struct list *list_entry);
51 typedef void *notify_handle_t;
52 #if defined(IOMUX_EPOLL_INOTIFY) || defined(IOMUX_KQUEUE) || defined(OS_WIN32)
53 bool iomux_directory_handle_alloc(dir_handle_t handle, notify_handle_t *h, uint64_t *seq, ajla_error_t *err);
54 bool iomux_directory_handle_wait(notify_handle_t h, uint64_t seq, mutex_t **mutex_to_lock, struct list *list_entry);
55 void iomux_directory_handle_free(notify_handle_t h);
56 #else
57 static inline bool iomux_directory_handle_alloc(dir_handle_t attr_unused handle, notify_handle_t attr_unused *h, uint64_t attr_unused *seq, ajla_error_t attr_unused *err)
59 fatal_mayfail(error_ajla(EC_SYNC, AJLA_ERROR_NOT_SUPPORTED), err, "directory monitoring not supported");
60 return false;
62 static inline bool iomux_directory_handle_wait(notify_handle_t attr_unused h, uint64_t attr_unused seq, mutex_t attr_unused **mutex_to_lock, struct list attr_unused *list_entry)
64 internal(file_line, "iomux_directory_handle_wait: the system doesn't support directory monitoring");
66 static inline void iomux_directory_handle_free(notify_handle_t attr_unused h)
68 internal(file_line, "iomux_directory_handle_free: the system doesn't support directory monitoring");
70 #endif
72 bool iomux_test_handle(handle_t h, bool wr);
74 void iomux_check_all(uint32_t us);
75 #define IOMUX_INDEFINITE_WAIT ((uint32_t)-1)
77 #ifndef wake_up_wait_list
78 void u_name(wake_up_wait_list)(struct list *wait_list, mutex_t *mutex_to_lock, bool can_allocate_memory);
79 void c_name(wake_up_wait_list)(struct list *wait_list, mutex_t *mutex_to_lock, bool can_allocate_memory);
80 #endif
82 void iomux_init(void);
83 void iomux_done(void);
85 #endif