From 0f604972af9110d2ad670b0403894ae1d1015495 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Wed, 12 Dec 2018 14:16:49 +0000 Subject: [PATCH] trimmed some source files --- mio/lib/main.c | 8 +- mio/lib/mio-cmn.h | 316 +++++++++++++++++++++++++++++++++++++++------- mio/lib/mio-pro.c | 20 +-- mio/lib/mio-pro.h | 4 +- mio/lib/mio-prv.h | 70 +++------- mio/lib/mio-sck.c | 4 +- mio/lib/mio-sck.h | 8 +- mio/lib/mio-tmr.c | 8 +- mio/lib/mio-utl.c | 46 +++---- mio/lib/mio.c | 34 ++--- mio/lib/mio.h | 23 +--- 11 files changed, 363 insertions(+), 178 deletions(-) diff --git a/mio/lib/main.c b/mio/lib/main.c index 8844e1d..991954f 100644 --- a/mio/lib/main.c +++ b/mio/lib/main.c @@ -56,14 +56,14 @@ struct mmgr_stat_t { - mio_size_t total_count; + mio_oow_t total_count; }; typedef struct mmgr_stat_t mmgr_stat_t; static mmgr_stat_t mmgr_stat; -static void* mmgr_alloc (mio_mmgr_t* mmgr, mio_size_t size) +static void* mmgr_alloc (mio_mmgr_t* mmgr, mio_oow_t size) { void* x; @@ -78,7 +78,7 @@ printf ("CRITICAL ERROR ---> too many heap chunks...\n"); return x; } -static void* mmgr_realloc (mio_mmgr_t* mmgr, void* ptr, mio_size_t size) +static void* mmgr_realloc (mio_mmgr_t* mmgr, void* ptr, mio_oow_t size) { return realloc (ptr, size); } @@ -160,7 +160,7 @@ static int tcp_sck_on_connect (mio_dev_sck_t* tcp) mio_sckfam_t fam; mio_scklen_t len; - mio_mchar_t buf1[128], buf2[128]; + mio_bch_t buf1[128], buf2[128]; memset (buf1, 0, MIO_SIZEOF(buf1)); memset (buf2, 0, MIO_SIZEOF(buf2)); diff --git a/mio/lib/mio-cmn.h b/mio/lib/mio-cmn.h index a3d33b9..9babbfa 100644 --- a/mio/lib/mio-cmn.h +++ b/mio/lib/mio-cmn.h @@ -57,7 +57,6 @@ # endif #endif - /* ========================================================================= * PRIMITIVE TYPE DEFINTIONS * ========================================================================= */ @@ -85,7 +84,6 @@ typedef signed char mio_int8_t; #endif - /* mio_int16_t */ #if defined(MIO_SIZEOF_SHORT) && (MIO_SIZEOF_SHORT == 2) # define MIO_HAVE_UINT16_T @@ -202,7 +200,10 @@ #elif defined(MIO_SIZEOF___INT128_T) && (MIO_SIZEOF___INT128_T == 16) # define MIO_HAVE_UINT128_T # define MIO_HAVE_INT128_T - #if defined(__clang__) + #if defined(MIO_SIZEOF___UINT128_T) && (MIO_SIZEOF___UINT128_T == MIO_SIZEOF___INT128_T) + typedef __uint128_t mio_uint128_t; + typedef __int128_t mio_int128_t; + #elif defined(__clang__) typedef __uint128_t mio_uint128_t; typedef __int128_t mio_int128_t; #else @@ -276,18 +277,169 @@ /* ========================================================================= * BASIC MIO TYPES * =========================================================================*/ +typedef char mio_bch_t; +typedef int mio_bci_t; +typedef unsigned char mio_bchu_t; /* unsigned version of mio_bch_t for inner working */ +#define MIO_SIZEOF_BCH_T MIO_SIZEOF_CHAR +#define MIO_SIZEOF_BCI_T MIO_SIZEOF_INT -typedef mio_uint8_t mio_byte_t; -typedef mio_uintptr_t mio_size_t; +#if defined(MIO_UNICODE_SIZE) && (MIO_UNICODE_SIZE >= 4) +# if defined(__GNUC__) && defined(__CHAR32_TYPE__) + typedef __CHAR32_TYPE__ mio_uch_t; +# else + typedef mio_uint32_t mio_uch_t; +# endif + typedef mio_uint32_t mio_uchu_t; /* same as mio_uch_t as it is already unsigned */ +# define MIO_SIZEOF_UCH_T 4 + +#elif defined(__GNUC__) && defined(__CHAR16_TYPE__) + typedef __CHAR16_TYPE__ mio_uch_t; + typedef mio_uint16_t mio_uchu_t; /* same as mio_uch_t as it is already unsigned */ +# define MIO_SIZEOF_UCH_T 2 +#else + typedef mio_uint16_t mio_uch_t; + typedef mio_uint16_t mio_uchu_t; /* same as mio_uch_t as it is already unsigned */ +# define MIO_SIZEOF_UCH_T 2 +#endif + +typedef mio_int32_t mio_uci_t; +#define MIO_SIZEOF_UCI_T 4 + +typedef mio_uint8_t mio_oob_t; + +/* NOTE: sizeof(mio_oop_t) must be equal to sizeof(mio_oow_t) */ +typedef mio_uintptr_t mio_oow_t; +typedef mio_intptr_t mio_ooi_t; +#define MIO_SIZEOF_OOW_T MIO_SIZEOF_UINTPTR_T +#define MIO_SIZEOF_OOI_T MIO_SIZEOF_INTPTR_T + +typedef mio_ushortptr_t mio_oohw_t; /* half word - half word */ +typedef mio_shortptr_t mio_oohi_t; /* signed half word */ +#define MIO_SIZEOF_OOHW_T MIO_SIZEOF_USHORTPTR_T +#define MIO_SIZEOF_OOHI_T MIO_SIZEOF_SHORTPTR_T + +struct mio_ucs_t +{ + mio_uch_t* ptr; + mio_oow_t len; +}; +typedef struct mio_ucs_t mio_ucs_t; + +struct mio_bcs_t +{ + mio_bch_t* ptr; + mio_oow_t len; +}; +typedef struct mio_bcs_t mio_bcs_t; + +#if defined(MIO_ENABLE_UNICODE) + typedef mio_uch_t mio_ooch_t; + typedef mio_uchu_t mio_oochu_t; + typedef mio_uci_t mio_ooci_t; + typedef mio_ucs_t mio_oocs_t; +# define MIO_OOCH_IS_UCH +# define MIO_SIZEOF_OOCH_T MIO_SIZEOF_UCH_T +#else + typedef mio_bch_t mio_ooch_t; + typedef mio_bchu_t mio_oochu_t; + typedef mio_bci_t mio_ooci_t; + typedef mio_bcs_t mio_oocs_t; +# define MIO_OOCH_IS_BCH +# define MIO_SIZEOF_OOCH_T MIO_SIZEOF_BCH_T +#endif + +/* the maximum number of bch charaters to represent a single uch character */ +#define MIO_BCSIZE_MAX 6 + +/* ========================================================================= + * TIME-RELATED TYPES + * =========================================================================*/ +#define MIO_MSECS_PER_SEC (1000) +#define MIO_MSECS_PER_MIN (MIO_MSECS_PER_SEC * MIO_SECS_PER_MIN) +#define MIO_MSECS_PER_HOUR (MIO_MSECS_PER_SEC * MIO_SECS_PER_HOUR) +#define MIO_MSECS_PER_DAY (MIO_MSECS_PER_SEC * MIO_SECS_PER_DAY) + +#define MIO_USECS_PER_MSEC (1000) +#define MIO_NSECS_PER_USEC (1000) +#define MIO_NSECS_PER_MSEC (MIO_NSECS_PER_USEC * MIO_USECS_PER_MSEC) +#define MIO_USECS_PER_SEC (MIO_USECS_PER_MSEC * MIO_MSECS_PER_SEC) +#define MIO_NSECS_PER_SEC (MIO_NSECS_PER_USEC * MIO_USECS_PER_MSEC * MIO_MSECS_PER_SEC) + +#define MIO_SECNSEC_TO_MSEC(sec,nsec) \ + (((mio_intptr_t)(sec) * MIO_MSECS_PER_SEC) + ((mio_intptr_t)(nsec) / MIO_NSECS_PER_MSEC)) + +#define MIO_SECNSEC_TO_USEC(sec,nsec) \ + (((mio_intptr_t)(sec) * MIO_USECS_PER_SEC) + ((mio_intptr_t)(nsec) / MIO_NSECS_PER_USEC)) + +#define MIO_SECNSEC_TO_NSEC(sec,nsec) \ + (((mio_intptr_t)(sec) * MIO_NSECS_PER_SEC) + (mio_intptr_t)(nsec)) + +#define MIO_SEC_TO_MSEC(sec) ((sec) * MIO_MSECS_PER_SEC) +#define MIO_MSEC_TO_SEC(sec) ((sec) / MIO_MSECS_PER_SEC) + +#define MIO_USEC_TO_NSEC(usec) ((usec) * MIO_NSECS_PER_USEC) +#define MIO_NSEC_TO_USEC(nsec) ((nsec) / MIO_NSECS_PER_USEC) + +#define MIO_MSEC_TO_NSEC(msec) ((msec) * MIO_NSECS_PER_MSEC) +#define MIO_NSEC_TO_MSEC(nsec) ((nsec) / MIO_NSECS_PER_MSEC) + +#define MIO_MSEC_TO_USEC(msec) ((msec) * MIO_USECS_PER_MSEC) +#define MIO_USEC_TO_MSEC(usec) ((usec) / MIO_USECS_PER_MSEC) + +#define MIO_SEC_TO_NSEC(sec) ((sec) * MIO_NSECS_PER_SEC) +#define MIO_NSEC_TO_SEC(nsec) ((nsec) / MIO_NSECS_PER_SEC) + +#define MIO_SEC_TO_USEC(sec) ((sec) * MIO_USECS_PER_SEC) +#define MIO_USEC_TO_SEC(usec) ((usec) / MIO_USECS_PER_SEC) + +typedef struct mio_ntime_t mio_ntime_t; +struct mio_ntime_t +{ + mio_intptr_t sec; + mio_int32_t nsec; /* nanoseconds */ +}; + +#define MIO_INIT_NTIME(c,s,ns) (((c)->sec = (s)), ((c)->nsec = (ns))) +#define MIO_CLEAR_NTIME(c) MIO_INIT_NTIME(c, 0, 0) + +#define MIO_ADD_NTIME(c,a,b) \ + do { \ + (c)->sec = (a)->sec + (b)->sec; \ + (c)->nsec = (a)->nsec + (b)->nsec; \ + while ((c)->nsec >= MIO_NSECS_PER_SEC) { (c)->sec++; (c)->nsec -= MIO_NSECS_PER_SEC; } \ + } while(0) + +#define MIO_ADD_NTIME_SNS(c,a,s,ns) \ + do { \ + (c)->sec = (a)->sec + (s); \ + (c)->nsec = (a)->nsec + (ns); \ + while ((c)->nsec >= MIO_NSECS_PER_SEC) { (c)->sec++; (c)->nsec -= MIO_NSECS_PER_SEC; } \ + } while(0) + +#define MIO_SUB_NTIME(c,a,b) \ + do { \ + (c)->sec = (a)->sec - (b)->sec; \ + (c)->nsec = (a)->nsec - (b)->nsec; \ + while ((c)->nsec < 0) { (c)->sec--; (c)->nsec += MIO_NSECS_PER_SEC; } \ + } while(0) + +#define MIO_SUB_NTIME_SNS(c,a,s,ns) \ + do { \ + (c)->sec = (a)->sec - s; \ + (c)->nsec = (a)->nsec - ns; \ + while ((c)->nsec < 0) { (c)->sec--; (c)->nsec += MIO_NSECS_PER_SEC; } \ + } while(0) -typedef char mio_mchar_t; -typedef int mio_mcint_t; +#define MIO_CMP_NTIME(a,b) (((a)->sec == (b)->sec)? ((a)->nsec - (b)->nsec): ((a)->sec - (b)->sec)) -#define MIO_MT(x) (x) /* ========================================================================= * PRIMITIVE MACROS * ========================================================================= */ +#define MIO_UCI_EOF ((mio_uci_t)-1) +#define MIO_BCI_EOF ((mio_bci_t)-1) +#define MIO_OOCI_EOF ((mio_ooci_t)-1) + #define MIO_SIZEOF(x) (sizeof(x)) #define MIO_COUNTOF(x) (sizeof(x) / sizeof(x[0])) @@ -304,24 +456,6 @@ typedef int mio_mcint_t; #define MIO_ALIGNOF(type) MIO_OFFSETOF(struct { mio_uint8_t d1; type d2; }, d2) /*(sizeof(struct { mio_uint8_t d1; type d2; }) - sizeof(type))*/ -/** - * Round up a positive integer to the nearest multiple of 'align' - */ -#define MIO_ALIGNTO(num,align) ((((num) + (align) - 1) / (align)) * (align)) - -#if 0 -/** - * Round up a number, both positive and negative, to the nearest multiple of 'align' - */ -#define MIO_ALIGNTO(num,align) ((((num) + (num >= 0? 1: -1) * (align) - 1) / (align)) * (align)) -#endif - -/** - * Round up a positive integer to to the nearest multiple of 'align' which - * should be a multiple of a power of 2 - */ -#define MIO_ALIGNTO_POW2(num,align) ((((num) + (align) - 1)) & ~((align) - 1)) - #if defined(__cplusplus) # if (__cplusplus >= 201103L) /* C++11 */ # define MIO_NULL nullptr @@ -344,7 +478,16 @@ typedef int mio_mcint_t; #define MIO_GETBITS(type,value,offset,length) \ ((((type)(value)) >> (offset)) & MIO_LBMASK(type,length)) +#define MIO_CLEARBITS(type,value,offset,length) \ + (((type)(value)) & ~(MIO_LBMASK(type,length) << (offset))) + #define MIO_SETBITS(type,value,offset,length,bits) \ + (value = (MIO_CLEARBITS(type,value,offset,length) | (((bits) & MIO_LBMASK(type,length)) << (offset)))) + +#define MIO_FLIPBITS(type,value,offset,length) \ + (((type)(value)) ^ (MIO_LBMASK(type,length) << (offset))) + +#define MIO_ORBITS(type,value,offset,length,bits) \ (value = (((type)(value)) | (((bits) & MIO_LBMASK(type,length)) << (offset)))) @@ -367,12 +510,12 @@ typedef struct mio_mmgr_t mio_mmgr_t; * allocate a memory chunk of the size \a n. * \return pointer to a memory chunk on success, #MIO_NULL on failure. */ -typedef void* (*mio_mmgr_alloc_t) (mio_mmgr_t* mmgr, mio_size_t n); +typedef void* (*mio_mmgr_alloc_t) (mio_mmgr_t* mmgr, mio_oow_t n); /** * resize a memory chunk pointed to by \a ptr to the size \a n. * \return pointer to a memory chunk on success, #MIO_NULL on failure. */ -typedef void* (*mio_mmgr_realloc_t) (mio_mmgr_t* mmgr, void* ptr, mio_size_t n); +typedef void* (*mio_mmgr_realloc_t) (mio_mmgr_t* mmgr, void* ptr, mio_oow_t n); /** * free a memory chunk pointed to by \a ptr. */ @@ -414,6 +557,36 @@ struct mio_mmgr_t */ #define MIO_MMGR_FREE(mmgr,ptr) ((mmgr)->free(mmgr,ptr)) +/* ========================================================================= + * CMGR + * =========================================================================*/ + +typedef struct mio_cmgr_t mio_cmgr_t; + +typedef mio_oow_t (*mio_cmgr_bctouc_t) ( + const mio_bch_t* mb, + mio_oow_t size, + mio_uch_t* wc +); + +typedef mio_oow_t (*mio_cmgr_uctobc_t) ( + mio_uch_t wc, + mio_bch_t* mb, + mio_oow_t size +); + +/** + * The mio_cmgr_t type defines the character-level interface to + * multibyte/wide-character conversion. This interface doesn't + * provide any facility to store conversion state in a context + * independent manner. This leads to the limitation that it can + * handle a stateless multibyte encoding only. + */ +struct mio_cmgr_t +{ + mio_cmgr_bctouc_t bctouc; + mio_cmgr_uctobc_t uctobc; +}; /* ========================================================================= * MACROS THAT CHANGES THE BEHAVIORS OF THE C COMPILER/LINKER @@ -447,7 +620,6 @@ struct mio_mmgr_t # undef MIO_HAVE_INLINE #endif - /** * The MIO_TYPE_IS_SIGNED() macro determines if a type is signed. * \code @@ -479,14 +651,45 @@ struct mio_mmgr_t #define MIO_TYPE_MIN(type) \ ((MIO_TYPE_IS_SIGNED(type)? MIO_TYPE_SIGNED_MIN(type): MIO_TYPE_UNSIGNED_MIN(type))) +/* round up a positive integer x to the nearst multiple of y */ +#define MIO_ALIGN(x,y) ((((x) + (y) - 1) / (y)) * (y)) + +/* round up a positive integer x to the nearst multiple of y where + * y must be a multiple of a power of 2*/ +#define MIO_ALIGN_POW2(x,y) ((((x) + (y) - 1)) & ~((y) - 1)) + +#define MIO_IS_UNALIGNED_POW2(x,y) ((x) & ((y) - 1)) +#define MIO_IS_ALIGNED_POW2(x,y) (!MIO_IS_UNALIGNED_POW2(x,y)) /* ========================================================================= * COMPILER FEATURE TEST MACROS * =========================================================================*/ -#if defined(__has_builtin) +#if !defined(__has_builtin) && defined(_INTELC32_) + /* intel c code builder 1.0 ended up with an error without this override */ + #define __has_builtin(x) 0 +#endif + +/* +#if !defined(__is_identifier) + #define __is_identifier(x) 0 +#endif + +#if !defined(__has_attribute) + #define __has_attribute(x) 0 +#endif +*/ + + +#if defined(__has_builtin) #if __has_builtin(__builtin_ctz) #define MIO_HAVE_BUILTIN_CTZ #endif + #if __has_builtin(__builtin_ctzl) + #define MIO_HAVE_BUILTIN_CTZL + #endif + #if __has_builtin(__builtin_ctzll) + #define MIO_HAVE_BUILTIN_CTZLL + #endif #if __has_builtin(__builtin_uadd_overflow) #define MIO_HAVE_BUILTIN_UADD_OVERFLOW @@ -525,10 +728,43 @@ struct mio_mmgr_t #if __has_builtin(__builtin_smulll_overflow) #define MIO_HAVE_BUILTIN_SMULLL_OVERFLOW #endif + + #if __has_builtin(__builtin_expect) + #define MIO_HAVE_BUILTIN_EXPECT + #endif + + + #if __has_builtin(__sync_lock_test_and_set) + #define MIO_HAVE_SYNC_LOCK_TEST_AND_SET + #endif + #if __has_builtin(__sync_lock_release) + #define MIO_HAVE_SYNC_LOCK_RELEASE + #endif + + #if __has_builtin(__sync_synchronize) + #define MIO_HAVE_SYNC_SYNCHRONIZE + #endif + #if __has_builtin(__sync_bool_compare_and_swap) + #define MIO_HAVE_SYNC_BOOL_COMPARE_AND_SWAP + #endif + #if __has_builtin(__sync_val_compare_and_swap) + #define MIO_HAVE_SYNC_VAL_COMPARE_AND_SWAP + #endif + #elif defined(__GNUC__) && defined(__GNUC_MINOR__) + #if (__GNUC__ >= 4) + #define MIO_HAVE_SYNC_LOCK_TEST_AND_SET + #define MIO_HAVE_SYNC_LOCK_RELEASE + + #define MIO_HAVE_SYNC_SYNCHRONIZE + #define MIO_HAVE_SYNC_BOOL_COMPARE_AND_SWAP + #define MIO_HAVE_SYNC_VAL_COMPARE_AND_SWAP + #endif + #if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) #define MIO_HAVE_BUILTIN_CTZ + #define MIO_HAVE_BUILTIN_EXPECT #endif #if (__GNUC__ >= 5) @@ -549,21 +785,13 @@ struct mio_mmgr_t #endif -/* -#if !defined(__has_builtin) - #define __has_builtin(x) 0 +#if defined(MIO_HAVE_BUILTIN_EXPECT) +# define MIO_LIKELY(x) (__builtin_expect(!!(x),1)) +# define MIO_UNLIKELY(x) (__builtin_expect(!!(x),0)) +#else +# define MIO_LIKELY(x) (x) +# define MIO_UNLIKELY(x) (x) #endif -#if !defined(__is_identifier) - #define __is_identifier(x) 0 -#endif - -#if !defined(__has_attribute) - #define __has_attribute(x) 0 -#endif -*/ - - - #endif diff --git a/mio/lib/mio-pro.c b/mio/lib/mio-pro.c index 2871fbb..124edec 100644 --- a/mio/lib/mio-pro.c +++ b/mio/lib/mio-pro.c @@ -50,9 +50,9 @@ static mio_dev_pro_slave_t* make_slave (mio_t* mio, slave_info_t* si); struct param_t { - mio_mchar_t* mcmd; - mio_mchar_t* fixed_argv[4]; - mio_mchar_t** argv; + mio_bch_t* mcmd; + mio_bch_t* fixed_argv[4]; + mio_bch_t** argv; }; typedef struct param_t param_t; @@ -64,16 +64,16 @@ static void free_param (mio_t* mio, param_t* param) MIO_MEMSET (param, 0, MIO_SIZEOF(*param)); } -static int make_param (mio_t* mio, const mio_mchar_t* cmd, int flags, param_t* param) +static int make_param (mio_t* mio, const mio_bch_t* cmd, int flags, param_t* param) { int fcnt = 0; - mio_mchar_t* mcmd = MIO_NULL; + mio_bch_t* mcmd = MIO_NULL; MIO_MEMSET (param, 0, MIO_SIZEOF(*param)); if (flags & MIO_DEV_PRO_SHELL) { - mcmd = (mio_mchar_t*)cmd; + mcmd = (mio_bch_t*)cmd; param->argv = param->fixed_argv; param->argv[0] = MIO_MT("/bin/sh"); @@ -84,8 +84,8 @@ static int make_param (mio_t* mio, const mio_mchar_t* cmd, int flags, param_t* p else { int i; - mio_mchar_t** argv; - mio_mchar_t* mcmdptr; + mio_bch_t** argv; + mio_bch_t* mcmdptr; mcmd = mio_mbsdup (mio, cmd); if (!mcmd) goto oops; @@ -122,7 +122,7 @@ static int make_param (mio_t* mio, const mio_mchar_t* cmd, int flags, param_t* p param->argv[i] = MIO_NULL; } - if (mcmd && mcmd != (mio_mchar_t*)cmd) param->mcmd = mcmd; + if (mcmd && mcmd != (mio_bch_t*)cmd) param->mcmd = mcmd; return 0; oops: @@ -777,7 +777,7 @@ static mio_dev_pro_slave_t* make_slave (mio_t* mio, slave_info_t* si) } } -mio_dev_pro_t* mio_dev_pro_make (mio_t* mio, mio_size_t xtnsize, const mio_dev_pro_make_t* info) +mio_dev_pro_t* mio_dev_pro_make (mio_t* mio, mio_oow_t xtnsize, const mio_dev_pro_make_t* info) { return (mio_dev_pro_t*)mio_makedev ( mio, MIO_SIZEOF(mio_dev_pro_t) + xtnsize, diff --git a/mio/lib/mio-pro.h b/mio/lib/mio-pro.h index c69ccc3..da7a2df 100644 --- a/mio/lib/mio-pro.h +++ b/mio/lib/mio-pro.h @@ -58,7 +58,7 @@ struct mio_dev_pro_t mio_dev_pro_on_write_t on_write; mio_dev_pro_on_close_t on_close; - mio_mchar_t* mcmd; + mio_bch_t* mcmd; }; struct mio_dev_pro_slave_t @@ -124,7 +124,7 @@ extern "C" { MIO_EXPORT mio_dev_pro_t* mio_dev_pro_make ( mio_t* mio, - mio_size_t xtnsize, + mio_oow_t xtnsize, const mio_dev_pro_make_t* data ); diff --git a/mio/lib/mio-prv.h b/mio/lib/mio-prv.h index db1cdcb..015bd0f 100644 --- a/mio/lib/mio-prv.h +++ b/mio/lib/mio-prv.h @@ -73,8 +73,8 @@ struct mio_t struct { - mio_size_t capa; - mio_size_t size; + mio_oow_t capa; + mio_oow_t size; mio_tmrjob_t* jobs; } tmr; @@ -105,38 +105,6 @@ struct mio_t #define MIO_SECS_PER_MIN (60) #define MIO_SECS_PER_HOUR (MIO_SECS_PER_MIN*MIO_MINS_PER_HOUR) #define MIO_SECS_PER_DAY (MIO_SECS_PER_MIN*MIO_MINS_PER_DAY) -#define MIO_MSECS_PER_SEC (1000) -#define MIO_MSECS_PER_MIN (MIO_MSECS_PER_SEC*MIO_SECS_PER_MIN) -#define MIO_MSECS_PER_HOUR (MIO_MSECS_PER_SEC*MIO_SECS_PER_HOUR) -#define MIO_MSECS_PER_DAY (MIO_MSECS_PER_SEC*MIO_SECS_PER_DAY) - -#define MIO_USECS_PER_MSEC (1000) -#define MIO_NSECS_PER_USEC (1000) -#define MIO_NSECS_PER_MSEC (MIO_NSECS_PER_USEC*MIO_USECS_PER_MSEC) -#define MIO_USECS_PER_SEC (MIO_USECS_PER_MSEC*MIO_MSECS_PER_SEC) -#define MIO_NSECS_PER_SEC (MIO_NSECS_PER_USEC*MIO_USECS_PER_MSEC*MIO_MSECS_PER_SEC) - -#define MIO_SECNSEC_TO_MSEC(sec,nsec) \ - (((mio_intptr_t)(sec) * MIO_MSECS_PER_SEC) + ((mio_intptr_t)(nsec) / MIO_NSECS_PER_MSEC)) - -#define MIO_SECNSEC_TO_USEC(sec,nsec) \ - (((mio_intptr_t)(sec) * MIO_USECS_PER_SEC) + ((mio_intptr_t)(nsec) / MIO_NSECS_PER_USEC)) - -#define MIO_SEC_TO_MSEC(sec) ((sec) * MIO_MSECS_PER_SEC) -#define MIO_MSEC_TO_SEC(sec) ((sec) / MIO_MSECS_PER_SEC) - -#define MIO_USEC_TO_NSEC(usec) ((usec) * MIO_NSECS_PER_USEC) -#define MIO_NSEC_TO_USEC(nsec) ((nsec) / MIO_NSECS_PER_USEC) - -#define MIO_MSEC_TO_NSEC(msec) ((msec) * MIO_NSECS_PER_MSEC) -#define MIO_NSEC_TO_MSEC(nsec) ((nsec) / MIO_NSECS_PER_MSEC) - -#define MIO_SEC_TO_NSEC(sec) ((sec) * MIO_NSECS_PER_SEC) -#define MIO_NSEC_TO_SEC(nsec) ((nsec) / MIO_NSECS_PER_SEC) - -#define MIO_SEC_TO_USEC(sec) ((sec) * MIO_USECS_PER_SEC) -#define MIO_USEC_TO_SEC(usec) ((usec) / MIO_USECS_PER_SEC) - #ifdef __cplusplus extern "C" { @@ -152,31 +120,31 @@ mio_errnum_t mio_syserrtoerrnum ( ); -mio_mchar_t* mio_mbsdup ( +mio_bch_t* mio_mbsdup ( mio_t* mio, - const mio_mchar_t* src + const mio_bch_t* src ); -mio_size_t mio_mbscpy ( - mio_mchar_t* buf, - const mio_mchar_t* str +mio_oow_t mio_mbscpy ( + mio_bch_t* buf, + const mio_bch_t* str ); int mio_mbsspltrn ( - mio_mchar_t* s, - const mio_mchar_t* delim, - mio_mchar_t lquote, - mio_mchar_t rquote, - mio_mchar_t escape, - const mio_mchar_t* trset + mio_bch_t* s, + const mio_bch_t* delim, + mio_bch_t lquote, + mio_bch_t rquote, + mio_bch_t escape, + const mio_bch_t* trset ); int mio_mbsspl ( - mio_mchar_t* s, - const mio_mchar_t* delim, - mio_mchar_t lquote, - mio_mchar_t rquote, - mio_mchar_t escape + mio_bch_t* s, + const mio_bch_t* delim, + mio_bch_t lquote, + mio_bch_t rquote, + mio_bch_t escape ); void mio_cleartmrjobs ( @@ -186,7 +154,7 @@ void mio_cleartmrjobs ( void mio_firetmrjobs ( mio_t* mio, const mio_ntime_t* tmbase, - mio_size_t* firecnt + mio_oow_t* firecnt ); diff --git a/mio/lib/mio-sck.c b/mio/lib/mio-sck.c index 37cbc1b..f6d1a58 100644 --- a/mio/lib/mio-sck.c +++ b/mio/lib/mio-sck.c @@ -1625,7 +1625,7 @@ static mio_dev_evcb_t dev_sck_event_callbacks_stateless = /* ========================================================================= */ -mio_dev_sck_t* mio_dev_sck_make (mio_t* mio, mio_size_t xtnsize, const mio_dev_sck_make_t* info) +mio_dev_sck_t* mio_dev_sck_make (mio_t* mio, mio_oow_t xtnsize, const mio_dev_sck_make_t* info) { mio_dev_sck_t* rdev; @@ -1685,7 +1685,7 @@ int mio_dev_sck_timedwrite (mio_dev_sck_t* dev, const void* data, mio_iolen_t dl /* ========================================================================= */ -mio_uint16_t mio_checksumip (const void* hdr, mio_size_t len) +mio_uint16_t mio_checksumip (const void* hdr, mio_oow_t len) { mio_uint32_t sum = 0; mio_uint16_t *ptr = (mio_uint16_t*)hdr; diff --git a/mio/lib/mio-sck.h b/mio/lib/mio-sck.h index ae6d0cb..1540572 100644 --- a/mio/lib/mio-sck.h +++ b/mio/lib/mio-sck.h @@ -373,8 +373,8 @@ struct mio_dev_sck_bind_t mio_sckaddr_t localaddr; /* TODO: add device name for BIND_TO_DEVICE */ - const mio_mchar_t* ssl_certfile; - const mio_mchar_t* ssl_keyfile; + const mio_bch_t* ssl_certfile; + const mio_bch_t* ssl_keyfile; mio_ntime_t accept_tmout; }; @@ -526,7 +526,7 @@ MIO_EXPORT void mio_sckaddr_initforeth ( MIO_EXPORT mio_dev_sck_t* mio_dev_sck_make ( mio_t* mio, - mio_size_t xtnsize, + mio_oow_t xtnsize, const mio_dev_sck_make_t* info ); @@ -586,7 +586,7 @@ static MIO_INLINE int mio_dev_sck_read (mio_dev_sck_t* sck, int enabled) MIO_EXPORT mio_uint16_t mio_checksumip ( const void* hdr, - mio_size_t len + mio_oow_t len ); diff --git a/mio/lib/mio-tmr.c b/mio/lib/mio-tmr.c index 8fd2258..ca6c4c3 100644 --- a/mio/lib/mio-tmr.c +++ b/mio/lib/mio-tmr.c @@ -70,7 +70,7 @@ static mio_tmridx_t sift_up (mio_t* mio, mio_tmridx_t index, int notify) static mio_tmridx_t sift_down (mio_t* mio, mio_tmridx_t index, int notify) { - mio_size_t base = mio->tmr.size / 2; + mio_oow_t base = mio->tmr.size / 2; if (index < base) /* at least 1 child is under the 'index' position */ { @@ -135,7 +135,7 @@ mio_tmridx_t mio_instmrjob (mio_t* mio, const mio_tmrjob_t* job) if (index >= mio->tmr.capa) { mio_tmrjob_t* tmp; - mio_size_t new_capa; + mio_oow_t new_capa; MIO_ASSERT (mio->tmr.capa >= 1); new_capa = mio->tmr.capa * 2; @@ -165,11 +165,11 @@ mio_tmridx_t mio_updtmrjob (mio_t* mio, mio_tmridx_t index, const mio_tmrjob_t* return YOUNGER_THAN(job, &item)? sift_up (mio, index, 0): sift_down (mio, index, 0); } -void mio_firetmrjobs (mio_t* mio, const mio_ntime_t* tm, mio_size_t* firecnt) +void mio_firetmrjobs (mio_t* mio, const mio_ntime_t* tm, mio_oow_t* firecnt) { mio_ntime_t now; mio_tmrjob_t tmrjob; - mio_size_t count = 0; + mio_oow_t count = 0; /* if the current time is not specified, get it from the system */ if (tm) now = *tm; diff --git a/mio/lib/mio-utl.c b/mio/lib/mio-utl.c index 45e6b89..66eb598 100644 --- a/mio/lib/mio-utl.c +++ b/mio/lib/mio-utl.c @@ -210,12 +210,12 @@ mio_uint128_t mio_hton128 (mio_uint128_t x) #define IS_MSPACE(x) ((x) == MIO_MT(' ') || (x) == MIO_MT('\t') || (x) == MIO_MT('\n') || (x) == MIO_MT('\r')) -mio_mchar_t* mio_mbsdup (mio_t* mio, const mio_mchar_t* src) +mio_bch_t* mio_mbsdup (mio_t* mio, const mio_bch_t* src) { - mio_mchar_t* dst; - mio_size_t len; + mio_bch_t* dst; + mio_oow_t len; - dst = (mio_mchar_t*)src; + dst = (mio_bch_t*)src; while (*dst != MIO_MT('\0')) dst++; len = dst - src; @@ -230,20 +230,20 @@ mio_mchar_t* mio_mbsdup (mio_t* mio, const mio_mchar_t* src) return dst; } -mio_size_t mio_mbscpy (mio_mchar_t* buf, const mio_mchar_t* str) +mio_oow_t mio_mbscpy (mio_bch_t* buf, const mio_bch_t* str) { - mio_mchar_t* org = buf; + mio_bch_t* org = buf; while ((*buf++ = *str++) != MIO_MT('\0')); return buf - org - 1; } int mio_mbsspltrn ( - mio_mchar_t* s, const mio_mchar_t* delim, - mio_mchar_t lquote, mio_mchar_t rquote, - mio_mchar_t escape, const mio_mchar_t* trset) + mio_bch_t* s, const mio_bch_t* delim, + mio_bch_t lquote, mio_bch_t rquote, + mio_bch_t escape, const mio_bch_t* trset) { - mio_mchar_t* p = s, *d; - mio_mchar_t* sp = MIO_NULL, * ep = MIO_NULL; + mio_bch_t* p = s, *d; + mio_bch_t* sp = MIO_NULL, * ep = MIO_NULL; int delim_mode; int cnt = 0; @@ -251,7 +251,7 @@ int mio_mbsspltrn ( else { delim_mode = 1; - for (d = (mio_mchar_t*)delim; *d != MIO_MT('\0'); d++) + for (d = (mio_bch_t*)delim; *d != MIO_MT('\0'); d++) if (!IS_MSPACE(*d)) delim_mode = 2; } @@ -274,7 +274,7 @@ int mio_mbsspltrn ( { if (trset != MIO_NULL && p[1] != MIO_MT('\0')) { - const mio_mchar_t* ep = trset; + const mio_bch_t* ep = trset; while (*ep != MIO_MT('\0')) { if (p[1] == *ep++) @@ -307,7 +307,7 @@ int mio_mbsspltrn ( else { ep[1] = MIO_MT('\0'); - if (s != (mio_mchar_t*)sp) mio_mbscpy (s, sp); + if (s != (mio_bch_t*)sp) mio_mbscpy (s, sp); cnt++; } } @@ -327,14 +327,14 @@ int mio_mbsspltrn ( else { ep[1] = MIO_MT('\0'); - if (s != (mio_mchar_t*)sp) mio_mbscpy (s, sp); + if (s != (mio_bch_t*)sp) mio_mbscpy (s, sp); cnt++; } } } else if (delim_mode == 1) { - mio_mchar_t* o; + mio_bch_t* o; while (*p) { @@ -354,7 +354,7 @@ int mio_mbsspltrn ( { if (trset != MIO_NULL && p[1] != MIO_MT('\0')) { - const mio_mchar_t* ep = trset; + const mio_bch_t* ep = trset; while (*ep != MIO_MT('\0')) { if (p[1] == *ep++) @@ -401,7 +401,7 @@ int mio_mbsspltrn ( } else /* if (delim_mode == 2) */ { - mio_mchar_t* o; + mio_bch_t* o; int ok; while (*p != MIO_MT('\0')) @@ -422,7 +422,7 @@ int mio_mbsspltrn ( { if (trset != MIO_NULL && p[1] != MIO_MT('\0')) { - const mio_mchar_t* ep = trset; + const mio_bch_t* ep = trset; while (*ep != MIO_MT('\0')) { if (p[1] == *ep++) @@ -450,7 +450,7 @@ int mio_mbsspltrn ( ok = 0; while (IS_MSPACE(*p)) p++; if (*p == MIO_MT('\0')) ok = 1; - for (d = (mio_mchar_t*)delim; *d != MIO_MT('\0'); d++) + for (d = (mio_bch_t*)delim; *d != MIO_MT('\0'); d++) { if (*p == *d) { @@ -477,7 +477,7 @@ int mio_mbsspltrn ( cnt++; break; } - for (d = (mio_mchar_t*)delim; *d != MIO_MT('\0'); d++) + for (d = (mio_bch_t*)delim; *d != MIO_MT('\0'); d++) { if (*p == *d) { @@ -517,8 +517,8 @@ exit_point: } int mio_mbsspl ( - mio_mchar_t* s, const mio_mchar_t* delim, - mio_mchar_t lquote, mio_mchar_t rquote, mio_mchar_t escape) + mio_bch_t* s, const mio_bch_t* delim, + mio_bch_t lquote, mio_bch_t rquote, mio_bch_t escape) { return mio_mbsspltrn (s, delim, lquote, rquote, escape, MIO_NULL); } diff --git a/mio/lib/mio.c b/mio/lib/mio.c index 967a844..e06bcb4 100644 --- a/mio/lib/mio.c +++ b/mio/lib/mio.c @@ -69,23 +69,23 @@ static int kill_and_free_device (mio_dev_t* dev, int force); #define MUX_CMD_UPDATE 2 #define MUX_CMD_DELETE 3 -#define MUX_INDEX_INVALID MIO_TYPE_MAX(mio_size_t) +#define MUX_INDEX_INVALID MIO_TYPE_MAX(mio_oow_t) struct mio_mux_t { struct { - mio_size_t* ptr; - mio_size_t size; - mio_size_t capa; + mio_oow_t* ptr; + mio_oow_t size; + mio_oow_t capa; } map; /* handle to index */ struct { struct pollfd* pfd; mio_dev_t** dptr; - mio_size_t size; - mio_size_t capa; + mio_oow_t size; + mio_oow_t capa; } pd; /* poll data */ }; @@ -120,15 +120,15 @@ static int mux_control (mio_dev_t* dev, int cmd, mio_syshnd_t hnd, int dev_capa) { mio_t* mio; mio_mux_t* mux; - mio_size_t idx; + mio_oow_t idx; mio = dev->mio; mux = (mio_mux_t*)mio->mux; if (hnd >= mux->map.capa) { - mio_size_t new_capa; - mio_size_t* tmp; + mio_oow_t new_capa; + mio_oow_t* tmp; if (cmd != MUX_CMD_INSERT) { @@ -136,9 +136,9 @@ static int mux_control (mio_dev_t* dev, int cmd, mio_syshnd_t hnd, int dev_capa) return -1; } - new_capa = MIO_ALIGNTO_POW2((hnd + 1), 256); + new_capa = MIO_ALIGN_POW2((hnd + 1), 256); - tmp = MIO_MMGR_REALLOC (mio->mmgr, mux->map.ptr, new_capa * MIO_SIZEOF(*tmp)); + tmp = MIO_MMGR_REALLOC(mio->mmgr, mux->map.ptr, new_capa * MIO_SIZEOF(*tmp)); if (!tmp) { mio->errnum = MIO_ENOMEM; @@ -176,13 +176,13 @@ static int mux_control (mio_dev_t* dev, int cmd, mio_syshnd_t hnd, int dev_capa) if (mux->pd.size >= mux->pd.capa) { - mio_size_t new_capa; + mio_oow_t new_capa; struct pollfd* tmp1; mio_dev_t** tmp2; - new_capa = MIO_ALIGNTO_POW2(mux->pd.size + 1, 256); + new_capa = MIO_ALIGN_POW2(mux->pd.size + 1, 256); - tmp1 = MIO_MMGR_REALLOC (mio->mmgr, mux->pd.pfd, new_capa * MIO_SIZEOF(*tmp1)); + tmp1 = MIO_MMGR_REALLOC(mio->mmgr, mux->pd.pfd, new_capa * MIO_SIZEOF(*tmp1)); if (!tmp1) { mio->errnum = MIO_ENOMEM; @@ -333,7 +333,7 @@ static MIO_INLINE int mux_control (mio_dev_t* dev, int cmd, mio_syshnd_t hnd, in /* ========================================================================= */ -mio_t* mio_open (mio_mmgr_t* mmgr, mio_size_t xtnsize, mio_size_t tmrcapa, mio_errnum_t* errnum) +mio_t* mio_open (mio_mmgr_t* mmgr, mio_oow_t xtnsize, mio_oow_t tmrcapa, mio_errnum_t* errnum) { mio_t* mio; @@ -362,7 +362,7 @@ void mio_close (mio_t* mio) MIO_MMGR_FREE (mio->mmgr, mio); } -int mio_init (mio_t* mio, mio_mmgr_t* mmgr, mio_size_t tmrcapa) +int mio_init (mio_t* mio, mio_mmgr_t* mmgr, mio_oow_t tmrcapa) { MIO_MEMSET (mio, 0, MIO_SIZEOF(*mio)); mio->mmgr = mmgr; @@ -862,7 +862,7 @@ int mio_loop (mio_t* mio) return 0; } -mio_dev_t* mio_makedev (mio_t* mio, mio_size_t dev_size, mio_dev_mth_t* dev_mth, mio_dev_evcb_t* dev_evcb, void* make_ctx) +mio_dev_t* mio_makedev (mio_t* mio, mio_oow_t dev_size, mio_dev_mth_t* dev_mth, mio_dev_evcb_t* dev_evcb, void* make_ctx) { mio_dev_t* dev; diff --git a/mio/lib/mio.h b/mio/lib/mio.h index 8e3dbbd..b544612 100644 --- a/mio/lib/mio.h +++ b/mio/lib/mio.h @@ -29,17 +29,6 @@ #include -/** - * The mio_ntime_t type defines a numeric time type expressed in the - * number of milliseconds since the Epoch (00:00:00 UTC, Jan 1, 1970). - */ -typedef struct mio_ntime_t mio_ntime_t; -struct mio_ntime_t -{ - mio_intptr_t sec; - mio_int32_t nsec; /* nanoseconds */ -}; - #if defined(_WIN32) typedef mio_uintptr_t qse_syshnd_t; #define MIO_SYSHND_INVALID (~(mio_uintptr_t)0) @@ -129,7 +118,7 @@ typedef enum mio_stopreq_t mio_stopreq_t; #define MIO_TMRIDX_INVALID ((mio_tmridx_t)-1) -typedef mio_size_t mio_tmridx_t; +typedef mio_oow_t mio_tmridx_t; typedef struct mio_tmrjob_t mio_tmrjob_t; @@ -263,7 +252,7 @@ struct mio_wq_t #define MIO_DEV_HEADERS \ mio_t* mio; \ - mio_size_t dev_size; \ + mio_oow_t dev_size; \ int dev_capa; \ mio_dev_mth_t* dev_mth; \ mio_dev_evcb_t* dev_evcb; \ @@ -329,8 +318,8 @@ extern "C" { MIO_EXPORT mio_t* mio_open ( mio_mmgr_t* mmgr, - mio_size_t xtnsize, - mio_size_t tmrcapa, /**< initial timer capacity */ + mio_oow_t xtnsize, + mio_oow_t tmrcapa, /**< initial timer capacity */ mio_errnum_t* errnum ); @@ -341,7 +330,7 @@ MIO_EXPORT void mio_close ( MIO_EXPORT int mio_init ( mio_t* mio, mio_mmgr_t* mmgr, - mio_size_t tmrcapa + mio_oow_t tmrcapa ); MIO_EXPORT void mio_fini ( @@ -363,7 +352,7 @@ MIO_EXPORT void mio_stop ( MIO_EXPORT mio_dev_t* mio_makedev ( mio_t* mio, - mio_size_t dev_size, + mio_oow_t dev_size, mio_dev_mth_t* dev_mth, mio_dev_evcb_t* dev_evcb, void* make_ctx