2018-12-12 13:15:54 +00:00
|
|
|
/*
|
2020-02-20 15:35:16 +00:00
|
|
|
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
|
2018-12-12 13:15:54 +00:00
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
2022-06-11 05:32:01 +00:00
|
|
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
2018-12-12 13:15:54 +00:00
|
|
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
#ifndef _HIO_PRV_H_
|
|
|
|
#define _HIO_PRV_H_
|
2018-12-12 13:15:54 +00:00
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
#include <hio.h>
|
|
|
|
#include <hio-utl.h>
|
2019-01-24 09:53:10 +00:00
|
|
|
|
2020-11-15 03:40:15 +00:00
|
|
|
/* enable floating-point support in basic formatting functions */
|
2021-07-22 07:43:01 +00:00
|
|
|
#define HIO_ENABLE_FLTFMT
|
2020-11-15 03:40:15 +00:00
|
|
|
|
2019-01-31 13:27:37 +00:00
|
|
|
#if defined(__has_builtin)
|
|
|
|
|
|
|
|
# if (!__has_builtin(__builtin_memset) || !__has_builtin(__builtin_memcpy) || !__has_builtin(__builtin_memmove) || !__has_builtin(__builtin_memcmp))
|
|
|
|
# include <string.h>
|
|
|
|
# endif
|
|
|
|
|
|
|
|
# if __has_builtin(__builtin_memset)
|
2021-07-22 07:43:01 +00:00
|
|
|
# define HIO_MEMSET(dst,src,size) __builtin_memset(dst,src,size)
|
2019-01-31 13:27:37 +00:00
|
|
|
# else
|
2021-07-22 07:43:01 +00:00
|
|
|
# define HIO_MEMSET(dst,src,size) memset(dst,src,size)
|
2019-01-31 13:27:37 +00:00
|
|
|
# endif
|
|
|
|
# if __has_builtin(__builtin_memcpy)
|
2021-07-22 07:43:01 +00:00
|
|
|
# define HIO_MEMCPY(dst,src,size) __builtin_memcpy(dst,src,size)
|
2019-01-31 13:27:37 +00:00
|
|
|
# else
|
2021-07-22 07:43:01 +00:00
|
|
|
# define HIO_MEMCPY(dst,src,size) memcpy(dst,src,size)
|
2019-01-31 13:27:37 +00:00
|
|
|
# endif
|
|
|
|
# if __has_builtin(__builtin_memmove)
|
2021-07-22 07:43:01 +00:00
|
|
|
# define HIO_MEMMOVE(dst,src,size) __builtin_memmove(dst,src,size)
|
2019-01-31 13:27:37 +00:00
|
|
|
# else
|
2021-07-22 07:43:01 +00:00
|
|
|
# define HIO_MEMMOVE(dst,src,size) memmove(dst,src,size)
|
2019-01-31 13:27:37 +00:00
|
|
|
# endif
|
|
|
|
# if __has_builtin(__builtin_memcmp)
|
2021-07-22 07:43:01 +00:00
|
|
|
# define HIO_MEMCMP(dst,src,size) __builtin_memcmp(dst,src,size)
|
2019-01-31 13:27:37 +00:00
|
|
|
# else
|
2021-07-22 07:43:01 +00:00
|
|
|
# define HIO_MEMCMP(dst,src,size) memcmp(dst,src,size)
|
2019-01-31 13:27:37 +00:00
|
|
|
# endif
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2019-11-24 05:10:55 +00:00
|
|
|
# if !defined(HAVE___BUILTIN_MEMSET) || !defined(HAVE___BUILTIN_MEMCPY) || !defined(HAVE___BUILTIN_MEMMOVE) || !defined(HAVE___BUILTIN_MEMCMP)
|
2019-01-31 13:27:37 +00:00
|
|
|
# include <string.h>
|
|
|
|
# endif
|
|
|
|
|
|
|
|
# if defined(HAVE___BUILTIN_MEMSET)
|
2021-07-22 07:43:01 +00:00
|
|
|
# define HIO_MEMSET(dst,src,size) __builtin_memset(dst,src,size)
|
2019-01-31 13:27:37 +00:00
|
|
|
# else
|
2021-07-22 07:43:01 +00:00
|
|
|
# define HIO_MEMSET(dst,src,size) memset(dst,src,size)
|
2019-01-31 13:27:37 +00:00
|
|
|
# endif
|
|
|
|
# if defined(HAVE___BUILTIN_MEMCPY)
|
2021-07-22 07:43:01 +00:00
|
|
|
# define HIO_MEMCPY(dst,src,size) __builtin_memcpy(dst,src,size)
|
2019-01-31 13:27:37 +00:00
|
|
|
# else
|
2021-07-22 07:43:01 +00:00
|
|
|
# define HIO_MEMCPY(dst,src,size) memcpy(dst,src,size)
|
2019-01-31 13:27:37 +00:00
|
|
|
# endif
|
|
|
|
# if defined(HAVE___BUILTIN_MEMMOVE)
|
2021-07-22 07:43:01 +00:00
|
|
|
# define HIO_MEMMOVE(dst,src,size) __builtin_memmove(dst,src,size)
|
2019-01-31 13:27:37 +00:00
|
|
|
# else
|
2021-07-22 07:43:01 +00:00
|
|
|
# define HIO_MEMMOVE(dst,src,size) memmove(dst,src,size)
|
2019-01-31 13:27:37 +00:00
|
|
|
# endif
|
|
|
|
# if defined(HAVE___BUILTIN_MEMCMP)
|
2021-07-22 07:43:01 +00:00
|
|
|
# define HIO_MEMCMP(dst,src,size) __builtin_memcmp(dst,src,size)
|
2019-01-31 13:27:37 +00:00
|
|
|
# else
|
2021-07-22 07:43:01 +00:00
|
|
|
# define HIO_MEMCMP(dst,src,size) memcmp(dst,src,size)
|
2019-01-31 13:27:37 +00:00
|
|
|
# endif
|
|
|
|
|
|
|
|
#endif
|
2019-01-24 18:03:27 +00:00
|
|
|
|
|
|
|
/* =========================================================================
|
|
|
|
* MIO ASSERTION
|
|
|
|
* ========================================================================= */
|
2021-07-22 07:43:01 +00:00
|
|
|
#if defined(HIO_BUILD_RELEASE)
|
|
|
|
# define HIO_ASSERT(hio,expr) ((void)0)
|
2019-01-24 18:03:27 +00:00
|
|
|
#else
|
2021-07-22 07:43:01 +00:00
|
|
|
# define HIO_ASSERT(hio,expr) ((void)((expr) || (hio_sys_assertfail(hio, #expr, __FILE__, __LINE__), 0)))
|
2019-01-24 18:03:27 +00:00
|
|
|
#endif
|
2018-12-12 13:15:54 +00:00
|
|
|
|
|
|
|
|
2023-01-11 14:59:41 +00:00
|
|
|
/* i don't want an error raised inside the callback to override
|
2019-01-24 18:03:27 +00:00
|
|
|
* the existing error number and message. */
|
2021-07-22 07:43:01 +00:00
|
|
|
#define HIO_SYS_WRITE_LOG(hio,mask,ptr,len) do { \
|
|
|
|
int __shuterr = (hio)->_shuterr; \
|
|
|
|
(hio)->_shuterr = 1; \
|
|
|
|
hio_sys_writelog (hio, mask, ptr, len); \
|
|
|
|
(hio)->_shuterr = __shuterr; \
|
2019-01-24 18:03:27 +00:00
|
|
|
} while(0)
|
|
|
|
|
2021-08-12 09:32:24 +00:00
|
|
|
#if defined(__cplusplus)
|
2018-12-12 13:15:54 +00:00
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
int hio_makesyshndasync (
|
|
|
|
hio_t* hio,
|
|
|
|
hio_syshnd_t hnd
|
2018-12-12 13:15:54 +00:00
|
|
|
);
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
int hio_makesyshndcloexec (
|
|
|
|
hio_t* hio,
|
|
|
|
hio_syshnd_t hnd
|
2020-07-24 17:29:52 +00:00
|
|
|
);
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
void hio_cleartmrjobs (
|
|
|
|
hio_t* hio
|
2018-12-12 13:15:54 +00:00
|
|
|
);
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
void hio_firetmrjobs (
|
|
|
|
hio_t* hio,
|
|
|
|
const hio_ntime_t* tmbase,
|
|
|
|
hio_oow_t* firecnt
|
2018-12-12 13:15:54 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
2020-09-03 03:56:32 +00:00
|
|
|
/**
|
2023-01-11 14:59:41 +00:00
|
|
|
* The hio_gettmrtmout() function gets the remaining time until the first
|
|
|
|
* scheduled job is to be triggered. It stores in \a tmout the difference between
|
2020-09-03 03:56:32 +00:00
|
|
|
* the given time \a tm and the scheduled time and returns 1. If there is no
|
|
|
|
* job scheduled, it returns 0.
|
|
|
|
*/
|
2021-07-22 07:43:01 +00:00
|
|
|
int hio_gettmrtmout (
|
|
|
|
hio_t* hio,
|
|
|
|
const hio_ntime_t* tm,
|
|
|
|
hio_ntime_t* tmout
|
2018-12-12 13:15:54 +00:00
|
|
|
);
|
|
|
|
|
2019-01-27 02:09:22 +00:00
|
|
|
/* ========================================================================== */
|
|
|
|
/* system intefaces */
|
2019-01-24 18:03:27 +00:00
|
|
|
/* ========================================================================== */
|
2019-01-29 16:57:16 +00:00
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
int hio_sys_init (
|
|
|
|
hio_t* hio
|
2019-01-29 16:57:16 +00:00
|
|
|
);
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
void hio_sys_fini (
|
|
|
|
hio_t* hio
|
2019-01-29 16:57:16 +00:00
|
|
|
);
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
void hio_sys_assertfail (
|
2023-01-11 14:59:41 +00:00
|
|
|
hio_t* hio,
|
2021-07-22 07:43:01 +00:00
|
|
|
const hio_bch_t* expr,
|
|
|
|
const hio_bch_t* file,
|
|
|
|
hio_oow_t line
|
2019-01-24 18:03:27 +00:00
|
|
|
);
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
hio_errnum_t hio_sys_syserrstrb (
|
|
|
|
hio_t* hio,
|
2019-01-24 18:03:27 +00:00
|
|
|
int syserr_type,
|
|
|
|
int syserr_code,
|
2021-07-22 07:43:01 +00:00
|
|
|
hio_bch_t* buf,
|
|
|
|
hio_oow_t len
|
2019-01-24 18:03:27 +00:00
|
|
|
);
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
void hio_sys_resetlog (
|
|
|
|
hio_t* hio
|
2021-07-19 09:27:44 +00:00
|
|
|
);
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
void hio_sys_locklog (
|
|
|
|
hio_t* hio
|
2021-07-20 14:40:46 +00:00
|
|
|
);
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
void hio_sys_unlocklog (
|
|
|
|
hio_t* hio
|
2021-07-20 14:40:46 +00:00
|
|
|
);
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
void hio_sys_writelog (
|
|
|
|
hio_t* hio,
|
|
|
|
hio_bitmask_t mask,
|
|
|
|
const hio_ooch_t* msg,
|
|
|
|
hio_oow_t len
|
2019-01-24 18:03:27 +00:00
|
|
|
);
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
void hio_sys_intrmux (
|
|
|
|
hio_t* hio
|
2021-07-17 17:21:38 +00:00
|
|
|
);
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
int hio_sys_ctrlmux (
|
|
|
|
hio_t* hio,
|
|
|
|
hio_sys_mux_cmd_t cmd,
|
|
|
|
hio_dev_t* dev,
|
2019-01-31 09:16:44 +00:00
|
|
|
int dev_cap
|
2019-01-27 02:09:22 +00:00
|
|
|
);
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
int hio_sys_waitmux (
|
|
|
|
hio_t* hio,
|
|
|
|
const hio_ntime_t* tmout,
|
|
|
|
hio_sys_mux_evtcb_t event_handler
|
2019-01-27 16:22:55 +00:00
|
|
|
);
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
void hio_sys_gettime (
|
|
|
|
hio_t* hio,
|
|
|
|
hio_ntime_t* now
|
2019-01-30 10:18:58 +00:00
|
|
|
);
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
void hio_sys_getrealtime (
|
|
|
|
hio_t* hio,
|
|
|
|
hio_ntime_t* now
|
2020-05-06 09:28:36 +00:00
|
|
|
);
|
|
|
|
|
2021-08-12 09:32:24 +00:00
|
|
|
#if defined(__cplusplus)
|
2018-12-12 13:15:54 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|