2023-01-16 05:54:34 +01:00
|
|
|
/*
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
UMKa - User-Mode KolibriOS developer tools
|
|
|
|
io - input/output platform specific code
|
|
|
|
|
|
|
|
Copyright (C) 2023 Ivan Baravy <dunkaist@gmail.com>
|
|
|
|
*/
|
|
|
|
|
2023-02-01 19:30:44 +01:00
|
|
|
#ifndef UMKAIO_H_INCLUDED
|
|
|
|
#define UMKAIO_H_INCLUDED
|
2023-01-16 05:54:34 +01:00
|
|
|
|
2023-02-03 05:39:32 +01:00
|
|
|
#include <stdatomic.h>
|
2023-02-03 00:52:35 +01:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <pthread.h>
|
2023-01-16 05:54:34 +01:00
|
|
|
|
2023-02-06 17:01:37 +01:00
|
|
|
#if !defined (O_BINARY)
|
|
|
|
#define O_BINARY 0 // for Windows
|
|
|
|
#endif
|
|
|
|
|
2023-01-18 09:29:08 +01:00
|
|
|
struct umka_io {
|
2023-02-03 05:39:32 +01:00
|
|
|
const atomic_int *running;
|
2023-02-03 00:52:35 +01:00
|
|
|
pthread_t iot;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct iot_cmd_read_arg {
|
|
|
|
int fd;
|
|
|
|
void *buf;
|
|
|
|
size_t count;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct iot_cmd_read_ret {
|
|
|
|
ssize_t val;
|
|
|
|
};
|
|
|
|
|
|
|
|
union iot_cmd_read {
|
|
|
|
struct iot_cmd_read_arg arg;
|
|
|
|
struct iot_cmd_read_ret ret;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct iot_cmd_write_arg {
|
|
|
|
int fd;
|
|
|
|
void *buf;
|
|
|
|
size_t count;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct iot_cmd_write_ret {
|
|
|
|
ssize_t val;
|
|
|
|
};
|
|
|
|
|
|
|
|
union iot_cmd_write {
|
|
|
|
struct iot_cmd_write_arg arg;
|
|
|
|
struct iot_cmd_write_ret ret;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
IOT_CMD_TYPE_READ,
|
|
|
|
IOT_CMD_TYPE_WRITE,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct iot_cmd {
|
|
|
|
pthread_cond_t iot_cond;
|
|
|
|
pthread_mutex_t iot_mutex;
|
|
|
|
pthread_mutex_t mutex;
|
2023-02-03 05:39:32 +01:00
|
|
|
atomic_int status;
|
2023-02-03 00:52:35 +01:00
|
|
|
int type;
|
|
|
|
union {
|
|
|
|
union iot_cmd_read read;
|
|
|
|
union iot_cmd_write write;
|
|
|
|
};
|
2023-01-18 09:29:08 +01:00
|
|
|
};
|
2023-01-17 01:49:11 +01:00
|
|
|
|
2023-01-18 09:29:08 +01:00
|
|
|
struct umka_io *
|
2023-02-03 05:39:32 +01:00
|
|
|
io_init(atomic_int *running);
|
2023-01-17 01:49:11 +01:00
|
|
|
|
|
|
|
void
|
2023-01-18 09:29:08 +01:00
|
|
|
io_close(struct umka_io *io);
|
2023-01-17 01:49:11 +01:00
|
|
|
|
2023-01-16 05:54:34 +01:00
|
|
|
ssize_t
|
2023-02-06 17:01:37 +01:00
|
|
|
io_read(int fd, void *buf, size_t count, const struct umka_io *io);
|
2023-01-16 05:54:34 +01:00
|
|
|
|
|
|
|
ssize_t
|
2023-02-06 17:01:37 +01:00
|
|
|
io_write(int fd, const void *buf, size_t count, const struct umka_io *io);
|
2023-01-16 05:54:34 +01:00
|
|
|
|
2023-02-01 19:30:44 +01:00
|
|
|
#endif // UMKAIO_H_INCLUDED
|