From 8040f7abd587183291fff756df831052e5b57f54 Mon Sep 17 00:00:00 2001 From: Vincent Wei Date: Sun, 14 Jul 2019 14:21:40 +0800 Subject: [PATCH] __mg_time -> mg_os_time; __mg_mktime -> __mg_os_mktime; __mg_localtime -> __mg_os_localtime; use clock_gettime for tick count instead of gettimeofday --- ChangeLog | 4 +- configure.ac | 2 +- include/common.h | 2 +- include/window.h | 116 ++++++++++++----- src/ex_ctrl/monthcalendar.c | 6 +- src/ex_ctrl/monthcalendar_impl.h | 6 +- src/font/devfont.c | 2 +- src/include/internals.h | 3 +- src/include/misc.h | 29 +++-- src/include/msgstr.h | 73 +++++------ src/kernel/desktop-comm.c | 43 ++++--- src/kernel/timer.c | 89 +++++-------- src/kernel/timer_posix.c | 46 +++---- src/misc/misc.c | 6 +- src/misc/nposix.c | 206 ++++++++++++++++++------------- src/standalone/standalone.c | 8 +- 16 files changed, 360 insertions(+), 281 deletions(-) diff --git a/ChangeLog b/ChangeLog index 63ae7016..52cec91b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4984,11 +4984,11 @@ provide the function whether the file exist or not.(xwyan) * src/server/request.c 10/24. MODIFICATION: Use 1980/01/01 00:00:00 to return the default local time -for __mg_localtime. +for __mg_os_localtime. * src/misc/nposix.c 10/24. MODIFICATION: Use HAVE_TIME, HAVE_MKTIME, and HAVE_LOCALTIME to define -__mg_time, __mg_mktime, and __mg_localtime functions. +__mg_os_time, __mg_os_mktime, and __mg_os_localtime functions. * configure.in * src/misc/nposix.c diff --git a/configure.ac b/configure.ac index 1d59d1f5..facca5a4 100644 --- a/configure.ac +++ b/configure.ac @@ -76,7 +76,7 @@ AC_FUNC_ALLOCA AC_FUNC_MEMCMP AC_FUNC_MMAP AC_FUNC_VPRINTF -AC_CHECK_FUNCS(time mktime localtime strdup strcasecmp strncasecmp strerror setlocale) +AC_CHECK_FUNCS(time mktime localtime clock_gettime strdup strcasecmp strncasecmp strerror setlocale) AC_CHECK_FUNCS(posix_memalign memalign valloc) dnl ======================================================================== diff --git a/include/common.h b/include/common.h index b62a4414..61b26f06 100644 --- a/include/common.h +++ b/include/common.h @@ -1991,7 +1991,7 @@ extern "C" { #endif #ifndef HAVE_TIME -typedef unsigned int time_t; +typedef unsigned long time_t; struct tm { int tm_sec; /* seconds [0,61] */ diff --git a/include/window.h b/include/window.h index 23338cb2..67e89e06 100644 --- a/include/window.h +++ b/include/window.h @@ -2041,7 +2041,7 @@ extern DWORD __mg_interval_time; * should be erase. The rectangle is in client coordinates system. * If it is NULL, the whole client area should be erased. */ -#define MSG_ERASEBKGND 0x00B0 /* this is an async message */ +#define MSG_ERASEBKGND 0x00B0 /* this is an async message */ /** * \def MSG_PAINT @@ -2087,7 +2087,7 @@ extern DWORD __mg_interval_time; */ #define MSG_SYNCPAINT 0x00B4 -#define MSG_LASTPAINTMSG 0x00CF +#define MSG_LASTPAINTMSG 0x00BF /** @} end of paint_msgs */ @@ -2096,18 +2096,18 @@ extern DWORD __mg_interval_time; * @{ */ -/* Group 6 from 0x00D0 to 0x00EF, the internal desktop messages. */ -#define MSG_FIRSTSESSIONMSG 0x00D0 +/* Group 6 from 0x00C0 to 0x00EF, the internal desktop messages. */ +#define MSG_FIRSTSESSIONMSG 0x00C0 -#define MSG_STARTSESSION 0x00D0 -#define MSG_QUERYENDSESSION 0x00D1 -#define MSG_ENDSESSION 0x00D2 -#define MSG_REINITSESSION 0x00D3 +#define MSG_STARTSESSION 0x00C0 +#define MSG_QUERYENDSESSION 0x00C1 +#define MSG_ENDSESSION 0x00C2 +#define MSG_REINITSESSION 0x00C3 -#define MSG_ERASEDESKTOP 0x00DE -#define MSG_PAINTDESKTOP 0x00DF +#define MSG_ERASEDESKTOP 0x00CE +#define MSG_PAINTDESKTOP 0x00CF -#define MSG_DT_MOUSEOFF 0x00E0 +#define MSG_DT_MOUSEOFF 0x00D0 /** * \def MSG_DT_LBUTTONDOWN @@ -2126,7 +2126,7 @@ extern DWORD __mg_interval_time; * * \sa MSG_DT_LBUTTONUP, MSG_LBUTTONDOWN */ -#define MSG_DT_LBUTTONDOWN 0x00E1 +#define MSG_DT_LBUTTONDOWN 0x00D1 /** * \def MSG_DT_LBUTTONUP @@ -2145,7 +2145,7 @@ extern DWORD __mg_interval_time; * * \sa MSG_DT_LBUTTONDOWN, MSG_LBUTTONUP */ -#define MSG_DT_LBUTTONUP 0x00E2 +#define MSG_DT_LBUTTONUP 0x00D2 /** * \def MSG_DT_LBUTTONDBLCLK @@ -2164,7 +2164,7 @@ extern DWORD __mg_interval_time; * * \sa MSG_RBUTTONDBLCLK */ -#define MSG_DT_LBUTTONDBLCLK 0x00E3 +#define MSG_DT_LBUTTONDBLCLK 0x00D3 /** * \def MSG_DT_MOUSEMOVE @@ -2183,7 +2183,7 @@ extern DWORD __mg_interval_time; * * \sa MSG_MOUSEMOVE */ -#define MSG_DT_MOUSEMOVE 0x00E4 +#define MSG_DT_MOUSEMOVE 0x00D4 /** * \def MSG_DT_RBUTTONDOWN @@ -2203,7 +2203,7 @@ extern DWORD __mg_interval_time; * \sa MSG_DT_RBUTTONUP, MSG_RBUTTONDOWN * */ -#define MSG_DT_RBUTTONDOWN 0x00E5 +#define MSG_DT_RBUTTONDOWN 0x00D5 /** * \def MSG_DT_RBUTTONUP @@ -2222,7 +2222,7 @@ extern DWORD __mg_interval_time; * * \sa MSG_DT_RBUTTONDOWN, MSG_RBUTTONUP */ -#define MSG_DT_RBUTTONUP 0x00E6 +#define MSG_DT_RBUTTONUP 0x00D6 /** * \def MSG_DT_RBUTTONDBLCLK @@ -2241,9 +2241,67 @@ extern DWORD __mg_interval_time; * * \sa MSG_LBUTTONDBLCLK */ -#define MSG_DT_RBUTTONDBLCLK 0x00E7 +#define MSG_DT_RBUTTONDBLCLK 0x00D7 -#define MSG_DT_KEYOFF 0x00D8 +/** + * \def MSG_DT_MBUTTONDOWN + * \brief Right mouse button down message on the desktop. + * + * This message is posted to the desktop window when the user presses down + * the right button of the mouse in the area of the desktop window. + * + * \code + * MSG_DT_MBUTTONDOWN + * int x_pos = LOSWORD (lParam); + * int y_pos = HISWORD (lParam); + * \endcode + * + * \param x_pos,y_pos The position of the mouse in desktop coordinates. + * + * \sa MSG_DT_MBUTTONUP, MSG_RBUTTONDOWN + * + */ +#define MSG_DT_MBUTTONDOWN 0x00D8 + +/** + * \def MSG_DT_MBUTTONUP + * \brief Right mouse button up message on the desktop. + * + * This message is posted to the desktop window when the user releases up + * the right button of the mouse in the area of the desktop window. + * + * \code + * MSG_DT_MBUTTONUP + * int x_pos = LOSWORD (lParam); + * int y_pos = HISWORD (lParam); + * \endcode + * + * \param x_pos,y_pos The position of the mouse in desktop coordinates. + * + * \sa MSG_DT_MBUTTONDOWN, MSG_RBUTTONUP + */ +#define MSG_DT_MBUTTONUP 0x00D9 + +/** + * \def MSG_DT_MBUTTONDBLCLK + * \brief Right mouse button double clicked message on the desktop. + * + * This message is posted to the desktop window when the user double clicks + * the right button of the mouse in the area of the desktop window. + * + * \code + * MSG_DT_MBUTTONDBLCLK + * int x_pos = LOSWORD (lParam); + * int y_pos = HISWORD (lParam); + * \endcode + * + * \param x_pos,y_pos The position of the mouse in desktop coordinates. + * + * \sa MSG_LBUTTONDBLCLK + */ +#define MSG_DT_MBUTTONDBLCLK 0x00DA + +#define MSG_DT_KEYOFF 0x00CB /** * \def MSG_DT_KEYDOWN @@ -2262,7 +2320,9 @@ extern DWORD __mg_interval_time; * \sa MSG_DT_KEYUP * */ -#define MSG_DT_KEYDOWN 0x00E8 +#define MSG_DT_KEYDOWN 0x00E0 + +#define MSG_DT_CHAR 0x00E1 /** * \def MSG_DT_KEYUP @@ -2280,18 +2340,16 @@ extern DWORD __mg_interval_time; * * \sa MSG_DT_KEYDOWN */ -#define MSG_DT_KEYUP 0x00EA +#define MSG_DT_KEYUP 0x00E2 -#define MSG_DT_SYSKEYDOWN 0x00EB -#define MSG_DT_SYSKEYUP 0x00ED +#define MSG_DT_SYSKEYDOWN 0x00E3 +#define MSG_DT_SYSCHAR 0x00E4 +#define MSG_DT_SYSKEYUP 0x00E5 -#define MSG_DT_SYSCHAR 0x00EC -#define MSG_DT_CHAR 0x00E9 +#define MSG_DT_KEYLONGPRESS 0x00E6 +#define MSG_DT_KEYALWAYSPRESS 0x00E7 -#define MSG_DT_KEYLONGPRESS 0x00EE -#define MSG_DT_KEYALWAYSPRESS 0x00EF - -#define MSG_LASTSESSIONMSG 0x00EF +#define MSG_LASTSESSIONMSG 0x00EF /** @} end of desktop_msgs */ diff --git a/src/ex_ctrl/monthcalendar.c b/src/ex_ctrl/monthcalendar.c index def54fed..38b3c9ed 100644 --- a/src/ex_ctrl/monthcalendar.c +++ b/src/ex_ctrl/monthcalendar.c @@ -234,7 +234,7 @@ static int GetWeekDay (int year, int month, int day) nowday.tm_mon = month-1; nowday.tm_year = year-1900; - if (__mg_mktime(&nowday) == -1) { + if (__mg_os_mktime(&nowday) == -1) { return -1; } else @@ -746,8 +746,8 @@ static BOOL mcInitMonthCalendarData (HWND hWnd, MONCALDDATA* mc_data) RECT rcClient, rcMDay; PMCCOLORINFO pmcci; - __mg_time(&nowtime); - pnt = (struct tm *)__mg_localtime(&nowtime); + __mg_os_time(&nowtime); + pnt = (struct tm *)__mg_os_localtime(&nowtime); mc_data->sys_year = mc_data->cur_year = pnt->tm_year + 1900; mc_data->sys_month = mc_data->cur_month = pnt->tm_mon + 1; mc_data->sys_day = mc_data->cur_day = pnt->tm_mday; diff --git a/src/ex_ctrl/monthcalendar_impl.h b/src/ex_ctrl/monthcalendar_impl.h index bbb314fd..c2d34e57 100644 --- a/src/ex_ctrl/monthcalendar_impl.h +++ b/src/ex_ctrl/monthcalendar_impl.h @@ -102,9 +102,9 @@ typedef MONCALDDATA* PMONCALDDATA; BOOL RegisterMonthCalendarControl (void); -time_t __mg_time (time_t * timer); -time_t __mg_mktime (struct tm * timeptr); -struct tm *__mg_localtime (const time_t * timer); +time_t __mg_os_time (time_t * timer); +time_t __mg_os_mktime (struct tm * timeptr); +struct tm *__mg_os_localtime (const time_t * timer); #ifdef __cplusplus } diff --git a/src/font/devfont.c b/src/font/devfont.c index 3dda883d..d3605fe3 100644 --- a/src/font/devfont.c +++ b/src/font/devfont.c @@ -1059,7 +1059,7 @@ static BOOL init_or_term_specifical_fonts (char* etc_section, BOOL is_unload) * first to load from sytem res path, else load it directly(relative or absolute path).*/ if ((add_dev_font (font_name, font_file, TRUE)) == TRUE) added_num++; - else if ((0 == mg_path_joint(font_path, MAX_PATH + 1, + else if ((0 == __mg_path_joint(font_path, MAX_PATH + 1, sysres_get_system_res_path(), font_file)) && ((add_dev_font (font_name, font_path, TRUE)) == TRUE)) added_num++; diff --git a/src/include/internals.h b/src/include/internals.h index f26f629c..16d4698e 100644 --- a/src/include/internals.h +++ b/src/include/internals.h @@ -617,8 +617,7 @@ SetDesktopTimerFlag (void) static inline void AlertDesktopTimerEvent (void) { - if(__mg_dsk_msg_queue) - { + if (__mg_dsk_msg_queue) { __mg_dsk_msg_queue->TimerMask = 1; POST_MSGQ(__mg_dsk_msg_queue); } diff --git a/src/include/misc.h b/src/include/misc.h index 9492ff17..92ff7ff6 100644 --- a/src/include/misc.h +++ b/src/include/misc.h @@ -1,33 +1,33 @@ /* - * This file is part of MiniGUI, a mature cross-platform windowing + * This file is part of MiniGUI, a mature cross-platform windowing * and Graphics User Interface (GUI) support system for embedded systems * and smart IoT devices. - * + * * Copyright (C) 2002~2018, Beijing FMSoft Technologies Co., Ltd. * Copyright (C) 1998~2002, WEI Yongming - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * + * * Or, - * + * * As this program is a library, any link to this program must follow * GNU General Public License version 3 (GPLv3). If you cannot accept * GPLv3, you need to be licensed from FMSoft. - * + * * If you have got a commercial license of this program, please use it * under the terms and conditions of the commercial license. - * + * * For more information about the commercial license, please refer to * . */ @@ -65,6 +65,11 @@ struct timezone { unsigned int __mg_os_get_random_seed (void); void __mg_os_time_delay (int ms); +void __mg_os_start_time_ms(void); +DWORD __mg_os_get_time_ms(void); +time_t __mg_os_time (time_t* timep); +time_t __mg_os_mktime (struct tm *tmp); +struct tm *__mg_os_localtime (const time_t * timep); #define NR_KEYS_INIT_ALLOC 8 #define NR_KEYS_INC_ALLOC 4 @@ -90,8 +95,10 @@ int __mg_lookfor_unused_slot (unsigned char* bitmap, int len_bmp, int set); void __mg_slot_set_use (unsigned char* bitmap, int index); int __mg_slot_clear_use (unsigned char* bitmap, int index); -BOOL mg_is_abs_path(const char* path); -int mg_path_joint(char* dst, int dst_size, const char* abs_path, const char* sub_path); +BOOL __mg_is_abs_path(const char* path); +int __mg_path_joint(char* dst, int dst_size, const char* abs_path, + const char* sub_path); + #if defined (__VXWORKS__) || defined(WIN32) || defined (__NUCLEUS_MNT__) || defined (_EM86_IAL) || defined (_EM85_IAL) double cbrt(double x); #endif diff --git a/src/include/msgstr.h b/src/include/msgstr.h index e9ad4885..5733d926 100644 --- a/src/include/msgstr.h +++ b/src/include/msgstr.h @@ -234,7 +234,7 @@ char * __mg_msgstr2 [] = "", // 0x00AE "", // 0x00AF - "MSG_ERASEBKGND", // 0x00B0 // this is an async message. + "MSG_ERASEBKGND", // 0x00B0 "MSG_PAINT", // 0x00B1 "MSG_NCPAINT", // 0x00B2 "MSG_NCACTIVATE", // 0x00B3 @@ -250,10 +250,11 @@ char * __mg_msgstr2 [] = "", // 0x00BD "", // 0x00BE "", // 0x00BF - "", // 0x00C0 - "", // 0x00C1 - "", // 0x00C2 - "", // 0x00C3 + + "MSG_STARTSESSION", // 0x00C0 + "MSG_QUERYENDSESSION", // 0x00C1 + "MSG_ENDSESSION", // 0x00C2 + "MSG_REINITSESSION", // 0x00C3 "", // 0x00C4 "", // 0x00C5 "", // 0x00C6 @@ -264,42 +265,42 @@ char * __mg_msgstr2 [] = "", // 0x00CB "", // 0x00CC "", // 0x00CD - "", // 0x00CE - "", // 0x00CF + "MSG_ERASEDESKTOP", // 0x00CE + "MSG_PAINTDESKTOP", // 0x00CF - "MSG_STARTSESSION", // 0x00D0 - "MSG_QUERYENDSESSION", // 0x00D1 - "MSG_ENDSESSION", // 0x00D2 - "MSG_REINITSESSION", // 0x00D3 - "", // 0x00D4 - "", // 0x00D5 - "", // 0x00D6 - "", // 0x00D7 - "", // 0x00D8 - "", // 0x00D9 - "", // 0x00DA + "", // 0x00D0 + "MSG_DT_LBUTTONDOWN", // 0x00D1 + "MSG_DT_LBUTTONUP", // 0x00D2 + "MSG_DT_LBUTTONDBLCLK", // 0x00D3 + "MSG_DT_MOUSEMOVE", // 0x00D4 + "MSG_DT_RBUTTONDOWN", // 0x00D5 + "MSG_DT_RBUTTONUP", // 0x00D6 + "MSG_DT_RBUTTONDBLCLK", // 0x00D7 + "MSG_DT_MBUTTONDOWN", // 0x00D8 + "MSG_DT_MBUTTONUP", // 0x00D9 + "MSG_DT_MBUTTONDBLCLK", // 0x00DA "", // 0x00DB "", // 0x00DC "", // 0x00DD - "MSG_ERASEDESKTOP", // 0x00DE - "MSG_PAINTDESKTOP", // 0x00DF + "", // 0x00DE + "", // 0x00DF - "MSG_DT_LBUTTONDOWN", // 0x00E0 - "MSG_DT_LBUTTONUP", // 0x00E1 - "MSG_DT_LBUTTONDBLCLK", // 0x00E2 - "MSG_DT_MOUSEMOVE", // 0x00E3 - "MSG_DT_RBUTTONDOWN", // 0x00E4 - "MSG_DT_RBUTTONUP", // 0x00E5 - "MSG_DT_RBUTTONDBLCLK", // 0x00E6 - "", // 0x00E7 - "MSG_DT_KEYDOWN", // 0x00E8 - "MSG_DT_CHAR", // 0x00E9 - "MSG_DT_KEYUP", // 0x00EA - "MSG_DT_SYSKEYDOWN", // 0x00EB - "MSG_DT_SYSCHAR", // 0x00EC - "MSG_DT_SYSKEYUP", // 0x00ED - "MSG_DT_KEYLONGPRESS", // 0x00EE - "MSG_DT_KEYALWAYSPRESS", // 0x00EF + "MSG_DT_KEYDOWN", // 0x00E0 + "MSG_DT_CHAR", // 0x00E1 + "MSG_DT_KEYUP", // 0x00E2 + "MSG_DT_SYSKEYDOWN", // 0x00E3 + "MSG_DT_SYSCHAR", // 0x00E4 + "MSG_DT_SYSKEYUP", // 0x00E5 + "MSG_DT_KEYLONGPRESS", // 0x00E6 + "MSG_DT_KEYALWAYSPRESS", // 0x00E7 + "", // 0x00E8 + "", // 0x00E9 + "", // 0x00EA + "", // 0x00EB + "", // 0x00EC + "", // 0x00ED + "", // 0x00EE + "", // 0x00EF "MSG_ADDNEWMAINWIN", // 0x00F0 "MSG_REMOVEMAINWIN", // 0x00F1 diff --git a/src/kernel/desktop-comm.c b/src/kernel/desktop-comm.c index cfd1f003..ad5dc82c 100644 --- a/src/kernel/desktop-comm.c +++ b/src/kernel/desktop-comm.c @@ -104,8 +104,8 @@ void mg_TerminateDesktop (void) DestroyFreeClipRectList (&sg_FreeInvRectList); mg_TerminateSystemRes (); - //dongjunjie avoid double free - __mg_dsk_win = 0; + //dongjunjie avoid double free + __mg_dsk_win = 0; } static PMAINWIN dskGetActiveWindow (void) @@ -532,7 +532,7 @@ static int dskScrollMainWindow (PMAINWIN pWin, PSCROLLWINDOWINFO pswi) if (pWin->dwExStyle & WS_EX_TRANSPARENT) { /* set invalidate rect. */ - InvalidateRect ((HWND)pWin, &rcMove, TRUE); + InvalidateRect ((HWND)pWin, &rcMove, TRUE); inved = TRUE; } else { @@ -619,7 +619,7 @@ static int dskScrollMainWindow (PMAINWIN pWin, PSCROLLWINDOWINFO pswi) */ if(bNeedInvalidate) { - InvalidateRect ((HWND)pWin, &rcInvalid, TRUE); + InvalidateRect ((HWND)pWin, &rcInvalid, TRUE); rcInvalid = rcMove; //restore the invalidate area bNeedInvalidate = FALSE; //resotre the inved value inved = TRUE; @@ -636,7 +636,7 @@ static int dskScrollMainWindow (PMAINWIN pWin, PSCROLLWINDOWINFO pswi) if (bNeedInvalidate) { - InvalidateRect ((HWND)pWin, &rcInvalid, TRUE); + InvalidateRect ((HWND)pWin, &rcInvalid, TRUE); inved = TRUE; } @@ -1696,7 +1696,7 @@ static int dskDesktopCommand (HMENU hDesktopMenu, int id) && (pWin->pHosting == NULL) #endif ) - PostMessage ((HWND)pWin, MSG_CLOSE, 0, 0); + PostMessage ((HWND)pWin, MSG_CLOSE, 0, 0); } slot = __mg_zorder_info->first_normal; @@ -1978,7 +1978,7 @@ static int dskGetIMEStatus (int iIMEStatusCode) void GUIAPI DesktopUpdateAllWindow(void) { - SendMessage(HWND_DESKTOP, MSG_PAINT, 0, 0); + SendMessage(HWND_DESKTOP, MSG_PAINT, 0, 0); } #ifndef _MG_ENABLE_SCREENSAVER @@ -2087,7 +2087,7 @@ LRESULT DesktopWinProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) if(dsk_ops->init) dt_context = dsk_ops->init(); #ifdef _MGHAVE_MENU - sg_DesktopMenu = dskCreateDesktopMenu (); + sg_DesktopMenu = dskCreateDesktopMenu (); #endif break; @@ -2097,12 +2097,12 @@ LRESULT DesktopWinProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) __mg_init_local_sys_text (); #ifdef _MGHAVE_MENU - if (sg_DesktopMenu) { - DestroyMenu (sg_DesktopMenu); - sg_DesktopMenu = 0; - } + if (sg_DesktopMenu) { + DestroyMenu (sg_DesktopMenu); + sg_DesktopMenu = 0; + } - sg_DesktopMenu = dskCreateDesktopMenu (); + sg_DesktopMenu = dskCreateDesktopMenu (); #endif SendMessage (HWND_DESKTOP, MSG_ERASEDESKTOP, 0, 0); @@ -2242,6 +2242,9 @@ LRESULT DesktopWinProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case MSG_DT_MOUSEMOVE: case MSG_DT_RBUTTONDOWN: case MSG_DT_RBUTTONDBLCLK: + case MSG_DT_MBUTTONDOWN: + case MSG_DT_MBUTTONDBLCLK: + case MSG_DT_MBUTTONUP: if(dsk_ops->mouse_handler) dsk_ops->mouse_handler(dt_context, message, wParam, lParam); break; @@ -2264,8 +2267,10 @@ LRESULT DesktopWinProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) uCounter += (__mg_timer_counter - blink_counter) * 10; blink_counter = __mg_timer_counter; - #else + static DWORD blink_counter = 0; + static DWORD sg_old_counter = 0; + if (__mg_quiting_stage < 0) { int slot; PMSGQUEUE pMsgQueue; @@ -2307,12 +2312,16 @@ LRESULT DesktopWinProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } } - mg_dispatch_timer_message (1); + if (MG_UNLIKELY(sg_old_counter == 0)) + sg_old_counter = __mg_timer_counter; + mg_dispatch_timer_message (__mg_timer_counter - sg_old_counter); + sg_old_counter = __mg_timer_counter; - if (__mg_timer_counter % 10 != 0) + if (__mg_timer_counter < (blink_counter + 10)) break; - uCounter += 100; + uCounter += (__mg_timer_counter - blink_counter) * 10; + blink_counter = __mg_timer_counter; #endif if (sg_hCaretWnd != 0 && gui_GetMainWindowPtrOfControl (sg_hCaretWnd) == dskGetActiveWindow() diff --git a/src/kernel/timer.c b/src/kernel/timer.c index 00d0db85..37dba15a 100644 --- a/src/kernel/timer.c +++ b/src/kernel/timer.c @@ -1,33 +1,33 @@ /* - * This file is part of MiniGUI, a mature cross-platform windowing + * This file is part of MiniGUI, a mature cross-platform windowing * and Graphics User Interface (GUI) support system for embedded systems * and smart IoT devices. - * + * * Copyright (C) 2002~2018, Beijing FMSoft Technologies Co., Ltd. * Copyright (C) 1998~2002, WEI Yongming - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * + * * Or, - * + * * As this program is a library, any link to this program must follow * GNU General Public License version 3 (GPLv3). If you cannot accept * GPLv3, you need to be licensed from FMSoft. - * + * * If you have got a commercial license of this program, please use it * under the terms and conditions of the commercial license. - * + * * For more information about the commercial license, please refer to * . */ @@ -37,7 +37,7 @@ ** Current maintainer: Wei Yongming. ** ** Create date: 1999/04/21 -*/ +*/ #include #include @@ -78,40 +78,17 @@ static pthread_mutex_t timerLock; #define TIMER_UNLOCK() #endif -#if defined(__LINUX__) && defined(_MGRM_THREADS) -# define _MG_USE_BETTER_TIMER -#endif /* __LINUX__ */ - -#ifdef _MG_USE_BETTER_TIMER -#ifdef _MGRM_THREADS -#include -static clock_t g_timer_started; -#endif -static clock_t g_last_tick; -#endif - /* timer action for minigui timers */ static void __mg_timer_action (void *data) { -#ifdef _MGRM_PROCESSES - SHAREDRES_TIMER_COUNTER += 1; -#else - -#if defined(_MGRM_STANDALONE) - __mg_timer_counter += 10; -#else -# ifdef _MG_USE_BETTER_TIMER - __mg_timer_counter = times(NULL) - g_timer_started; -# else /* _MG_USE_BETTER_TIMER */ - __mg_timer_counter ++; -# endif /* _MG_USE_BETTER_TIMER */ -#endif - -#endif - -#ifdef _MGRM_THREADS +#if defined(_MGRM_PROCESSES) + SHAREDRES_TIMER_COUNTER = __mg_os_get_time_ms()/10; +#elif defined(_MGRM_THREADS) + __mg_timer_counter = __mg_os_get_time_ms()/10; /* alert desktop */ AlertDesktopTimerEvent (); +#else /* _MGRM_STANDALONE */ + // do nothing #endif } @@ -129,11 +106,6 @@ static void* TimerEntry (void* data) { sem_post ((sem_t*)data); -#ifdef _MG_USE_BETTER_TIMER - g_timer_started = times(NULL); - g_last_tick = 0; -#endif /* _MG_USE_BETTER_TIMER */ - while (__mg_quiting_stage > _MG_QUITING_STAGE_TIMER) { __mg_os_time_delay (10); __mg_timer_action (NULL); @@ -152,8 +124,8 @@ int __mg_timer_init (void) } #ifdef __AOS__ - __mg_os_timer = tp_os_timer_create ("mgtimer", __mg_timer_action, - NULL, AOS_TIMER_TICKT, + __mg_os_timer = tp_os_timer_create ("mgtimer", __mg_timer_action, + NULL, AOS_TIMER_TICKT, OS_AUTO_ACTIVATE | OS_AUTO_LOAD); #else /* NOT __AOS__ */ { @@ -195,7 +167,7 @@ BOOL mg_InstallIntervalTimer (void) { struct itimerval timerv; struct sigaction siga; - + sigaction (SIGALRM, NULL, &old_alarm_handler); siga = old_alarm_handler; @@ -243,6 +215,8 @@ BOOL mg_UninstallIntervalTimer (void) BOOL mg_InitTimer (void) { + __mg_os_start_time_ms(); + #ifdef _MGRM_THREADS pthread_mutex_init (&timerLock, NULL); __mg_timer_counter = 0; @@ -287,12 +261,8 @@ void mg_dispatch_timer_message (DWORD inter) { int i; -#ifdef _MG_USE_BETTER_TIMER - clock_t now = __mg_timer_counter; - - inter = now - g_last_tick; - g_last_tick = now; -#endif /* _MG_USE_BETTER_TIMER */ + if (inter == 0) + return; TIMER_LOCK (); @@ -306,7 +276,7 @@ void mg_dispatch_timer_message (DWORD inter) timerstr[i]->tick_count = __mg_timer_counter; #endif /* setting timer flag is simple, we do not need to lock msgq, - or else we may encounter dead lock here */ + or else we may encounter dead lock here */ SetMsgQueueTimerFlag (timerstr[i]->msg_queue, i); timerstr[i]->count -= timerstr[i]->speed; } @@ -377,7 +347,7 @@ void __mg_move_timer_last (TIMER* timer, int slot) } #endif -BOOL GUIAPI SetTimerEx (HWND hWnd, LINT id, DWORD speed, +BOOL GUIAPI SetTimerEx (HWND hWnd, LINT id, DWORD speed, TIMERPROC timer_proc) { int i; @@ -438,7 +408,7 @@ BOOL GUIAPI SetTimerEx (HWND hWnd, LINT id, DWORD speed, TIMER_UNLOCK (); return TRUE; - + badret: TIMER_UNLOCK (); return FALSE; @@ -519,7 +489,7 @@ int GUIAPI KillTimer (HWND hWnd, LINT id) TIMER_LOCK (); for (i = 0; i < DEF_NR_TIMERS; i++) { - if ((timerstr [i] && timerstr [i]->hWnd == hWnd) && + if ((timerstr [i] && timerstr [i]->hWnd == hWnd) && (id == 0 || timerstr [i]->id == id)) { RemoveMsgQueueTimerFlag (pMsgQueue, i); free (timerstr[i]); @@ -539,7 +509,7 @@ int GUIAPI KillTimer (HWND hWnd, LINT id) return killed; } -BOOL GUIAPI ResetTimerEx (HWND hWnd, LINT id, DWORD speed, +BOOL GUIAPI ResetTimerEx (HWND hWnd, LINT id, DWORD speed, TIMERPROC timer_proc) { int i; @@ -616,8 +586,7 @@ DWORD GUIAPI GetTickCount (void) #ifdef _MGRM_PROCESSES return SHAREDRES_TIMER_COUNTER; #elif defined(_MGRM_STANDALONE) - extern DWORD __mg_os_get_time(void); - __mg_timer_counter = __mg_os_get_time() / 10; + __mg_timer_counter = __mg_os_get_time_ms()/10; return __mg_timer_counter; #else return __mg_timer_counter; diff --git a/src/kernel/timer_posix.c b/src/kernel/timer_posix.c index fe5a32fe..fa6fcf4b 100644 --- a/src/kernel/timer_posix.c +++ b/src/kernel/timer_posix.c @@ -1,33 +1,33 @@ /* - * This file is part of MiniGUI, a mature cross-platform windowing + * This file is part of MiniGUI, a mature cross-platform windowing * and Graphics User Interface (GUI) support system for embedded systems * and smart IoT devices. - * + * * Copyright (C) 2002~2018, Beijing FMSoft Technologies Co., Ltd. * Copyright (C) 1998~2002, WEI Yongming - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * + * * Or, - * + * * As this program is a library, any link to this program must follow * GNU General Public License version 3 (GPLv3). If you cannot accept * GPLv3, you need to be licensed from FMSoft. - * + * * If you have got a commercial license of this program, please use it * under the terms and conditions of the commercial license. - * + * * For more information about the commercial license, please refer to * . */ @@ -36,7 +36,7 @@ static timer_t mytimer; static struct sigaction old_alarm_handler; -void timer_handler (int sig, siginfo_t *extra, void *cruft) +static void timer_handler (int sig, siginfo_t *extra, void *cruft) { int sem_value; int noverflow; @@ -82,24 +82,24 @@ BOOL mg_InitTimer (void) /* create a timer based upon the CLOCK_REALTIME clock */ - it.it_interval.tv_sec=0; - + it.it_interval.tv_sec=0; + /* set resolution to one-tenth of the maximum allowed */ - it.it_interval.tv_nsec=resolution.tv_nsec; - //it.it_interval.tv_nsec=10000000; - it.it_value=it.it_interval; + it.it_interval.tv_nsec=resolution.tv_nsec; + //it.it_interval.tv_nsec=10000000; + it.it_value=it.it_interval; - timer_event.sigev_notify=SIGEV_SIGNAL; - timer_event.sigev_signo= SIGRTMIN; - timer_event.sigev_value.sival_ptr = (void *)&mytimer; + timer_event.sigev_notify=SIGEV_SIGNAL; + timer_event.sigev_signo= SIGRTMIN; + timer_event.sigev_value.sival_ptr = (void *)&mytimer; - if (timer_create(CLOCK_REALTIME, &timer_event, &mytimer) < 0){ + if (timer_create(CLOCK_REALTIME, &timer_event, &mytimer) < 0){ perror("timer create error"); return FALSE; - } - - /* relative timer, go off at the end of the interval*/ + } + + /* relative timer, go off at the end of the interval*/ if (timer_settime(mytimer, 0 , &it, NULL) < 0){ perror("settimer"); return FALSE; @@ -119,7 +119,7 @@ void mg_TerminateTimer (void) if (sigaction (SIGRTMIN, &old_alarm_handler, NULL) == -1) { fprintf (stderr, "KERNEL>Timer: sigaction call failed!\n"); perror ("sigaction"); - return; + return; } for (i=0; i= strlen(abs_path) + strlen(sub_path) + 2/* size of split '/' and terminator '\0' */) { sprintf(dst, "%s/%s", abs_path, sub_path); diff --git a/src/misc/nposix.c b/src/misc/nposix.c index abf381f9..3dd7d6d7 100644 --- a/src/misc/nposix.c +++ b/src/misc/nposix.c @@ -1,39 +1,39 @@ /* - * This file is part of MiniGUI, a mature cross-platform windowing + * This file is part of MiniGUI, a mature cross-platform windowing * and Graphics User Interface (GUI) support system for embedded systems * and smart IoT devices. - * + * * Copyright (C) 2002~2018, Beijing FMSoft Technologies Co., Ltd. * Copyright (C) 1998~2002, WEI Yongming - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * + * * Or, - * + * * As this program is a library, any link to this program must follow * GNU General Public License version 3 (GPLv3). If you cannot accept * GPLv3, you need to be licensed from FMSoft. - * + * * If you have got a commercial license of this program, please use it * under the terms and conditions of the commercial license. - * + * * For more information about the commercial license, please refer to * . */ /* -** nposix.c: This file include some miscelleous functions not -** provided by POSIX. +** nposix.c: This file includes some miscelleous functions should be +** implemented for different operating systems. ** ** Create date: 2003/11/22 ** @@ -104,7 +104,7 @@ int strncasecmp (const char *s1, const char *s2, unsigned int n) #ifdef WIN32 int fread_long_win32(char* buff, size_t size, int count, FILE* fp) { - char *tmp; + char *tmp; size_t ret, rest = size * count; int len; @@ -116,7 +116,7 @@ int fread_long_win32(char* buff, size_t size, int count, FILE* fp) tmp = buff; ret = 0; while(rest > 0) - { + { if((len = fread(tmp, 1, 1024, fp)) != 1024) { ret += len; @@ -140,7 +140,7 @@ double hypot(double x, double y) #if defined (__VXWORKS__) ||defined(WIN32) || defined (__NUCLEUS_MNT__) || defined (_EM86_IAL) || defined (_EM85_IAL) -/* +/* * Implementation of cbrt(x) for Win32 platform. * cbrt(x): Return cube root of x */ @@ -218,7 +218,7 @@ do { \ } while (0) -static const Uint32 +static const Uint32 B1 = 715094163, /* B1 = (682-0.03306235651)*2**20 */ B2 = 696219795; /* B2 = (664-0.03306235651)*2**20 */ @@ -229,7 +229,7 @@ E = 1.41428571428571436819e+00, /* 99/70 = 0x3FF6A0EA, 0x0EA0EA0F */ F = 1.60714285714285720630e+00, /* 45/28 = 0x3FF9B6DB, 0x6DB6DB6E */ G = 3.57142857142857150787e-01; /* 5/14 = 0x3FD6DB6D, 0xB6DB6DB7 */ -double cbrt (double x) +double cbrt (double x) { Sint32 hx; double r,s,t=0.0,w; @@ -241,7 +241,7 @@ double cbrt (double x) hx ^=sign; if(hx>=0x7ff00000) return(x+x); /* cbrt(NaN,INF) is itself */ GET_LOW_WORD(low,x); - if((hx|low)==0) + if((hx|low)==0) return(x); /* cbrt(0) is itself */ SET_HIGH_WORD(x,hx); /* x <- |x| */ @@ -257,9 +257,9 @@ double cbrt (double x) /* new cbrt to 23 bits, may be implemented in single precision */ r=t*t/x; s=C+r*t; - t*=G+F/(s+E+D/s); + t*=G+F/(s+E+D/s); - /* chopped to 20 bits and make it larger than cbrt(x) */ + /* chopped to 20 bits and make it larger than cbrt(x) */ GET_HIGH_WORD(high,t); INSERT_WORDS(t,high+0x00000001,0); @@ -284,7 +284,7 @@ double cbrt (double x) double x1, x2; double x3; - if (x <= 1E-6) + if (x <= 1E-6) return 0.0; x2 = x; @@ -292,7 +292,7 @@ double cbrt (double x) x1 = x2; x2 = (2.0 * x1 + x / (x1 *x1)) /3.0; x3 = (x2 - x1) / x1; - if (x3 < 0.0) + if (x3 < 0.0) x3 = -x3; if (x3 < 1E-6) break; } @@ -354,9 +354,9 @@ int shmdt(const void *shmaddr) } */ -#endif +#endif /* __CYGWIN__ */ -/* ------------------------------ time delay -------------------------------- */ +/* ------------------------------ time and delay-------------------------------- */ #ifndef __NOUNIX__ #include @@ -411,7 +411,7 @@ void __mg_os_time_delay (int ms) while (select (0, NULL, NULL, NULL, &timeout) < 0); #elif defined (__UCOSII__) OSTimeDly (OS_TICKS_PER_SEC * ms / 1000); -#elif defined (__VXWORKS__) +#elif defined (__VXWORKS__) taskDelay (sysClkRateGet() * ms / 1000); #elif defined (__PSOS__) || defined (__ECOS__) struct timespec ts; @@ -430,19 +430,65 @@ void __mg_os_time_delay (int ms) #endif } -#ifndef __NOUNIX__ +#if defined (WIN32) +#include + +#pragma comment(lib, "winmm.lib") + +void __mg_os_start_time_ms(void) +{ + // do nothing +} + +DWORD __mg_os_get_time_ms(void) { + return timeGetTime(); +} + +#elif defined (HAVE_CLOCK_GETTIME) + +static struct timespec timeval_startup; +void __mg_os_start_time_ms(void) +{ + clock_gettime(CLOCK_MONOTONIC, &timeval_startup); +} + +DWORD __mg_os_get_time_ms(void) +{ + DWORD ds, dms; + struct timespec current; + + clock_gettime(CLOCK_MONOTONIC, ¤t); + ds = (current.tv_sec - timeval_startup.tv_sec); + + if (current.tv_sec == timeval_startup.tv_sec) { + dms = (current.tv_nsec - timeval_startup.tv_nsec) / 1000000L; + } + else if (current.tv_nsec >= timeval_startup.tv_nsec) { + dms = (current.tv_nsec - timeval_startup.tv_nsec) / 1000000L; + } + else { + assert(ds > 0); + + ds--; + dms = 1000L - (timeval_startup.tv_nsec - current.tv_nsec) / 1000000L; + } + + return ds * 1000 + dms; +} + +#if 0 #include #include #include static struct timeval timeval_startup; -void __mg_os_start_time(void) +void __mg_os_start_time_ms(void) { gettimeofday(&timeval_startup, NULL); } -DWORD __mg_os_get_time(void) +DWORD __mg_os_get_time_ms(void) { DWORD ds, dms; struct timeval current; @@ -465,28 +511,56 @@ DWORD __mg_os_get_time(void) return ds * 1000 + dms; } - -#elif defined(WIN32) - -#include - -#pragma comment(lib, "winmm.lib") - -void __mg_os_start_time(void) -{ - // do nothing -} - -DWORD __mg_os_get_time(void) { - return timeGetTime(); -} +#endif #else -#error "Please implement __mg_os_start_time and __mg_os_get_time for your OS" +#error "Please implement __mg_os_start_time_ms and __mg_os_get_time_ms for your OS" #endif +time_t __mg_os_time (time_t * timer) +{ +#if defined (HAVE_TIME) + return time (timer); +#else +#warn "Please implement __mg_os_time for your OS" + return 0; +#endif +} + +time_t __mg_os_mktime (struct tm * timeptr) +{ +#if defined (HAVE_MKTIME) + return mktime (timeptr); +#else +#warn "Please implement __mg_os_mktime for your OS" + return 0; +#endif +} + +struct tm *__mg_os_localtime (const time_t * timer) +{ +#if defined (HAVE_LOCALTIME) + return localtime (timer); +#else +#warn "Please implement __mg_os_localtime for your OS" + static struct tm _19800101_tm = { + 0, /* tm_sec: seconds */ + 0, /* tm_min: minutes */ + 0, /* tm_hour: hours */ + 1, /* tm_mday: day of the month (1st) */ + 0, /* tm_mon: month (Jan) */ + 80, /* tm_year: year (1980) */ + 2, /* tm_wday: day of the week (1980/01/01 is Tuesday) */ + 0, /* tm_yday: day in the year */ + 0, /* tm_isdst daylight saving time */ + }; + + return &_19800101_tm; +#endif +} + /* ------------------------------ I/O -------------------------------- */ void __mg_rewind (FILE *fp) { @@ -515,6 +589,7 @@ int __mg_close_tmpfile (FILE *tmp_fp) return fclose (tmp_fp); } +/* ------------------------------ Misc -------------------------------- */ #ifdef __TARGET_C33L05__ #undef HAVE_TIME @@ -538,48 +613,9 @@ int snprintf( char *s, size_t size, const char *format, ... ) int __modsi3 (int numer, int denom) { - int quot = numer / denom; - return numer - (quot * denom); + int quot = numer / denom; + return numer - (quot * denom); } -#endif - -time_t __mg_time (time_t * timer) -{ -#if defined (HAVE_TIME) - return time (timer); -#else - return 0; -#endif -} - -time_t __mg_mktime (struct tm * timeptr) -{ -#if defined (HAVE_MKTIME) - return mktime (timeptr); -#else - return 0; -#endif -} - -struct tm *__mg_localtime (const time_t * timer) -{ -#if defined (HAVE_LOCALTIME) - return localtime (timer); -#else - static struct tm _19800101_tm = { - 0, /* tm_sec: seconds */ - 0, /* tm_min: minutes */ - 0, /* tm_hour: hours */ - 1, /* tm_mday: day of the month (1st) */ - 0, /* tm_mon: month (Jan) */ - 80, /* tm_year: year (1980) */ - 2, /* tm_wday: day of the week (1980/01/01 is Tuesday) */ - 0, /* tm_yday: day in the year */ - 0, /* tm_isdst daylight saving time */ - }; - - return &_19800101_tm; -#endif -} +#endif /* __TARGET_C33L05__ */ diff --git a/src/standalone/standalone.c b/src/standalone/standalone.c index 72d1fc5e..76d2a96b 100644 --- a/src/standalone/standalone.c +++ b/src/standalone/standalone.c @@ -159,8 +159,8 @@ static void ParseEvent (PMSGQUEUE msg_que, int event) } } -extern void __mg_os_start_time(void); -extern DWORD __mg_os_get_time(void); +extern void __mg_os_start_time_ms(void); +extern DWORD __mg_os_get_time_ms(void); BOOL GUIAPI salone_StandAloneStartup (void) { @@ -171,7 +171,7 @@ BOOL GUIAPI salone_StandAloneStartup (void) mg_InstallIntervalTimer (); #endif - __mg_os_start_time(); + __mg_os_start_time_ms(); return TRUE; } @@ -244,7 +244,7 @@ BOOL salone_IdleHandler4StandAlone (PMSGQUEUE msg_queue) n = IAL_WaitEvent (mg_maxfd, &rset, wsetptr, esetptr, msg_queue?&sel_timeout:&sel_timeout_nd, &extra); /* update __mg_timer_counter */ - __mg_timer_counter = __mg_os_get_time()/10; + __mg_timer_counter = __mg_os_get_time_ms()/10; #endif if (msg_queue == NULL)