From e610e8a45df41b4cea04da71c793c17bc2a8ea7e Mon Sep 17 00:00:00 2001 From: yuqing Date: Wed, 15 Jul 2015 14:26:39 +0800 Subject: [PATCH] OS macro defines put in _os_define.h --- HISTORY | 5 +++++ libfastcommon.spec | 2 +- make.sh | 50 +++++++++++++++++++++++++++++++-------------- src/Makefile.in | 2 +- src/_os_bits.h | 7 ------- src/common_define.h | 3 ++- src/ioevent.h | 1 + src/sched_thread.c | 9 +++++++- src/shared_func.c | 10 +++++++-- 9 files changed, 61 insertions(+), 28 deletions(-) delete mode 100644 src/_os_bits.h diff --git a/HISTORY b/HISTORY index 1b07d8d..385eb2d 100644 --- a/HISTORY +++ b/HISTORY @@ -1,4 +1,9 @@ +Version 1.18 2015-07-15 + * OS macro defines put in _os_define.h + * remove file _os_bits.h + * schedule task support second field + Version 1.17 2015-07-14 * ini_file_reader.c change PJWHash to Time33Hash and increase capacity * ini_file_reader.c realloc change to malloc and memcpy diff --git a/libfastcommon.spec b/libfastcommon.spec index 62cf1f0..ec9a512 100644 --- a/libfastcommon.spec +++ b/libfastcommon.spec @@ -2,7 +2,7 @@ %define LibFastcommonDevel libfastcommon-devel Name: libfastcommon -Version: 1.0.17 +Version: 1.0.18 Release: 1%{?dist} Summary: c common functions library extracted from my open source projects FastDFS License: GPL diff --git a/make.sh b/make.sh index f06c755..5cd0e10 100755 --- a/make.sh +++ b/make.sh @@ -46,16 +46,6 @@ else OFF_BITS=32 fi -cat < src/_os_bits.h -#ifndef _OS_BITS_H -#define _OS_BITS_H - -#define OS_BITS $OS_BITS -#define OFF_BITS $OFF_BITS - -#endif -EOF - DEBUG_FLAG=1 CFLAGS='-Wall -D_FILE_OFFSET_BITS=64' @@ -67,24 +57,54 @@ fi LIBS='' uname=`uname` + if [ "$uname" = "Linux" ]; then - CFLAGS="$CFLAGS -DOS_LINUX -DIOEVENT_USE_EPOLL" + OS_NAME=OS_LINUX + IOEVENT_USE=IOEVENT_USE_EPOLL elif [ "$uname" = "FreeBSD" ] || [ "$uname" = "Darwin" ]; then - CFLAGS="$CFLAGS -DOS_FREEBSD -DIOEVENT_USE_KQUEUE" + OS_NAME=OS_FREEBSD + IOEVENT_USE=IOEVENT_USE_KQUEUE if [ "$uname" = "Darwin" ]; then CFLAGS="$CFLAGS -DDARWIN" fi elif [ "$uname" = "SunOS" ]; then - CFLAGS="$CFLAGS -DOS_SUNOS -D_THREAD_SAFE -DIOEVENT_USE_PORT" + OS_NAME=OS_SUNOS + IOEVENT_USE=IOEVENT_USE_PORT + CFLAGS="$CFLAGS -D_THREAD_SAFE" LIBS="$LIBS -lsocket -lnsl -lresolv" export CC=gcc elif [ "$uname" = "AIX" ]; then - CFLAGS="$CFLAGS -DOS_AIX -D_THREAD_SAFE" + OS_NAME=OS_AIX + IOEVENT_USE=IOEVENT_USE_NONE + CFLAGS="$CFLAGS -D_THREAD_SAFE" export CC=gcc elif [ "$uname" = "HP-UX" ]; then - CFLAGS="$CFLAGS -DOS_HPUX" + OS_NAME=OS_HPUX + IOEVENT_USE=IOEVENT_USE_NONE +else + OS_NAME=OS_UNKOWN + IOEVENT_USE=IOEVENT_USE_NONE fi +cat < src/_os_define.h +#ifndef _OS_DEFINE_H +#define _OS_DEFINE_H + +#define OS_BITS $OS_BITS +#define OFF_BITS $OFF_BITS + +#ifndef $OS_NAME +#define $OS_NAME 1 +#endif + +#ifndef $IOEVENT_USE +#define $IOEVENT_USE 1 +#endif + +#endif +EOF + + if [ -f /usr/lib/libpthread.so ] || [ -f /usr/local/lib/libpthread.so ] || [ -f /usr/lib64/libpthread.so ] || [ -f /usr/lib/libpthread.a ] || [ -f /usr/local/lib/libpthread.a ] || [ -f /usr/lib64/libpthread.a ]; then LIBS="$LIBS -lpthread" elif [ -f /usr/lib/libc_r.so ]; then diff --git a/src/Makefile.in b/src/Makefile.in index 7222bb3..f452868 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -19,7 +19,7 @@ FAST_STATIC_OBJS = hash.o chain.o shared_func.o ini_file_reader.o \ connection_pool.o fast_mpool.o HEADER_FILES = common_define.h hash.h chain.h logger.h base64.h \ - shared_func.h pthread_func.h ini_file_reader.h _os_bits.h \ + shared_func.h pthread_func.h ini_file_reader.h _os_define.h \ sockopt.h sched_thread.h http_func.h md5.h local_ip_func.h \ avl_tree.h ioevent.h ioevent_loop.h fast_task_queue.h \ fast_timer.h process_ctrl.h fast_mblock.h \ diff --git a/src/_os_bits.h b/src/_os_bits.h deleted file mode 100644 index 81e1626..0000000 --- a/src/_os_bits.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef _OS_BITS_H -#define _OS_BITS_H - -#define OS_BITS 64 -#define OFF_BITS 64 - -#endif diff --git a/src/common_define.h b/src/common_define.h index 0632515..837cf9f 100644 --- a/src/common_define.h +++ b/src/common_define.h @@ -52,7 +52,7 @@ extern int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int kind); #define PTHREAD_MUTEX_ERRORCHECK PTHREAD_MUTEX_ERRORCHECK_NP #endif -#include "_os_bits.h" +#include "_os_define.h" #ifdef OS_BITS #if OS_BITS == 64 @@ -124,6 +124,7 @@ typedef struct { byte hour; byte minute; + byte second; } TimeInfo; typedef struct diff --git a/src/ioevent.h b/src/ioevent.h index 5d4630e..823a3a5 100644 --- a/src/ioevent.h +++ b/src/ioevent.h @@ -4,6 +4,7 @@ #include #include #include +#include "_os_define.h" #define IOEVENT_TIMEOUT 0x8000 diff --git a/src/sched_thread.c b/src/sched_thread.c index 808dcc7..0c668ea 100644 --- a/src/sched_thread.c +++ b/src/sched_thread.c @@ -81,7 +81,14 @@ static int sched_init_entries(ScheduleArray *pScheduleArray) tm_base.tm_hour = pEntry->time_base.hour; tm_base.tm_min = pEntry->time_base.minute; - tm_base.tm_sec = 0; + if (pEntry->time_base.second >= 0 && pEntry->time_base.second <= 59) + { + tm_base.tm_sec = pEntry->time_base.second; + } + else + { + tm_base.tm_sec = 0; + } time_base = mktime(&tm_base); pEntry->next_call_time = g_current_time + \ diff --git a/src/shared_func.c b/src/shared_func.c index e9b4fac..74c2ddf 100644 --- a/src/shared_func.c +++ b/src/shared_func.c @@ -1819,6 +1819,8 @@ int get_time_item_from_conf(IniContext *pIniContext, \ char *pValue; int hour; int minute; + int second; + int count; pValue = iniGetStrValue(NULL, item_name, pIniContext); if (pValue == NULL) @@ -1828,7 +1830,9 @@ int get_time_item_from_conf(IniContext *pIniContext, \ return 0; } - if (sscanf(pValue, "%d:%d", &hour, &minute) != 2) + second = 0; + count = sscanf(pValue, "%d:%d:%d", &hour, &minute, &second); + if (count != 2 && count != 3) { logError("file: "__FILE__", line: %d, " \ "item \"%s\" 's value \"%s\" is not an valid time", \ @@ -1836,7 +1840,8 @@ int get_time_item_from_conf(IniContext *pIniContext, \ return EINVAL; } - if ((hour < 0 || hour > 23) || (minute < 0 || minute > 59)) + if ((hour < 0 || hour > 23) || (minute < 0 || minute > 59) + || (second < 0 || second > 59)) { logError("file: "__FILE__", line: %d, " \ "item \"%s\" 's value \"%s\" is not an valid time", \ @@ -1846,6 +1851,7 @@ int get_time_item_from_conf(IniContext *pIniContext, \ pTimeInfo->hour = (byte)hour; pTimeInfo->minute = (byte)minute; + pTimeInfo->second = (byte)second; return 0; }