mirror of
https://github.com/VincentWei/MiniGUI.git
synced 2026-09-24 17:44:19 +08:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4ae46a4b94 | ||
|
|
2791dc99ef | ||
|
|
b7525f3001 | ||
|
|
4c55f2eac3 |
@@ -55,6 +55,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
@@ -141,12 +142,31 @@ BOOL mg_InitDesktop (void)
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
static IDLEHANDLER std_idle_handler;
|
||||
|
||||
/* According to a bug report, we use sem_timedwait() instead of
|
||||
calling std_idle_handler for desktop thread.
|
||||
Otherwise, the desktop might not handle the request from other GUI threads
|
||||
as soon as possible. */
|
||||
static BOOL idle_handler_for_desktop_thread (MSGQUEUE *msg_queue, BOOL wait)
|
||||
{
|
||||
int retv, n = 0;
|
||||
|
||||
__mg_update_tick_count (msg_queue);
|
||||
return std_idle_handler (msg_queue, wait);
|
||||
|
||||
if (wait) {
|
||||
struct timespec ts;
|
||||
if (clock_gettime (CLOCK_REALTIME, &ts) != -1) {
|
||||
ts.tv_nsec += 10 * 1000 * 1000L; // 10ms
|
||||
if (ts.tv_nsec >= 1000 * 1000 * 1000L) {
|
||||
ts.tv_sec += 1;
|
||||
ts.tv_nsec -= 1000 * 1000 * 1000L;
|
||||
}
|
||||
|
||||
if (sem_timedwait (&msg_queue->wait, &ts) == 0)
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return n > 0;
|
||||
}
|
||||
|
||||
void* __kernel_desktop_main (void* data)
|
||||
@@ -162,7 +182,6 @@ void* __kernel_desktop_main (void* data)
|
||||
|
||||
/* For bug reported in Issue #116, under threads mode, the idle handler
|
||||
for the desktop thread should call __mg_update_tick_count () */
|
||||
std_idle_handler = __mg_dsk_msg_queue->OnIdle;
|
||||
__mg_dsk_msg_queue->OnIdle = idle_handler_for_desktop_thread;
|
||||
|
||||
/* init desktop window */
|
||||
|
||||
+7
-7
@@ -562,6 +562,13 @@ int GUIAPI InitGUI (int args, const char *agr[])
|
||||
|
||||
_is_minigui_running = 1;
|
||||
|
||||
/* init timer for tick counter */
|
||||
step++;
|
||||
if (!mg_InitTimer()) {
|
||||
_ERR_PRINTF ("KERNEL>InitGUI: failed to start time counter\n");
|
||||
goto failure;
|
||||
}
|
||||
|
||||
step++;
|
||||
if (!SystemThreads()) {
|
||||
_ERR_PRINTF ("KERNEL>InitGUI: failed to init system threads!\n");
|
||||
@@ -575,13 +582,6 @@ int GUIAPI InitGUI (int args, const char *agr[])
|
||||
goto failure;
|
||||
}
|
||||
|
||||
/* init timer for tick counter */
|
||||
step++;
|
||||
if (!mg_InitTimer()) {
|
||||
_ERR_PRINTF ("KERNEL>InitGUI: failed to start time counter\n");
|
||||
goto failure;
|
||||
}
|
||||
|
||||
SetKeyboardLayout ("default");
|
||||
|
||||
SetCursor (GetSystemCursor (IDC_ARROW));
|
||||
|
||||
+5
-5
@@ -100,14 +100,14 @@ DWORD __mg_update_tick_count (MSGQUEUE* msg_queue)
|
||||
/* Since 5.0.0, the desktop only handles caret blinking in MSG_TIMEOUT
|
||||
message, and the interval for the timer of desktop changes to 0.05s.
|
||||
*/
|
||||
if (msg_queue == __mg_dsk_msg_queue) {
|
||||
if (ticks > __mg_dsk_msg_queue->last_ticks +
|
||||
if (msg_queue == __mg_dsk_msg_queue &&
|
||||
ticks > __mg_dsk_msg_queue->old_tick_count +
|
||||
DESKTOP_TIMER_INERTVAL) {
|
||||
__mg_dsk_msg_queue->dwState |= QS_DESKTIMER;
|
||||
__mg_dsk_msg_queue->dwState |= QS_DESKTIMER;
|
||||
#ifdef _MGRM_THREADS /* only wake up desktop for threads mode */
|
||||
POST_MSGQ (__mg_dsk_msg_queue);
|
||||
POST_MSGQ (__mg_dsk_msg_queue);
|
||||
#endif
|
||||
}
|
||||
__mg_dsk_msg_queue->old_tick_count = ticks;
|
||||
}
|
||||
|
||||
msg_queue->last_ticks = ticks;
|
||||
|
||||
@@ -495,28 +495,6 @@ DWORD __mg_os_get_time_ticks (void)
|
||||
return (current - startup_time_win32) / 10;
|
||||
}
|
||||
|
||||
#if 0 /* deprecated code */
|
||||
DWORD __mg_os_get_elapsed_ms (void)
|
||||
{
|
||||
static DWORD last;
|
||||
DWORD current = timeGetTime();
|
||||
DWORD elapsed;
|
||||
|
||||
if (current >= last) {
|
||||
elapsed = current - last;
|
||||
return elapsed;
|
||||
}
|
||||
else {
|
||||
/* overflowed */
|
||||
elapsed = BITMASK_DWORD - last;
|
||||
elapsed += current;
|
||||
}
|
||||
|
||||
last = current;
|
||||
return elapsed;
|
||||
}
|
||||
#endif /* deprecated code */
|
||||
|
||||
#elif defined (HAVE_CLOCK_GETTIME)
|
||||
|
||||
static struct timespec timeval_startup;
|
||||
@@ -573,68 +551,6 @@ DWORD __mg_os_get_time_ticks (void)
|
||||
return ds * 100 + dms;
|
||||
}
|
||||
|
||||
#if 0 /* deprecated code */
|
||||
DWORD __mg_os_get_elapsed_ms (void)
|
||||
{
|
||||
static struct timespec last;
|
||||
DWORD ds, dms;
|
||||
struct timespec current;
|
||||
|
||||
clock_gettime (CLOCK_MONOTONIC, ¤t);
|
||||
ds = (current.tv_sec - last.tv_sec);
|
||||
|
||||
if (current.tv_sec == last.tv_sec) {
|
||||
dms = (current.tv_nsec - last.tv_nsec) / 1000000L;
|
||||
}
|
||||
else if (current.tv_nsec >= last.tv_nsec) {
|
||||
dms = (current.tv_nsec - last.tv_nsec) / 1000000L;
|
||||
}
|
||||
else {
|
||||
assert (ds > 0);
|
||||
|
||||
ds--;
|
||||
dms = 1000L - (last.tv_nsec - current.tv_nsec) / 1000000L;
|
||||
}
|
||||
|
||||
last = current;
|
||||
return ds * 1000 + dms;
|
||||
}
|
||||
|
||||
#include <unistd.h>
|
||||
#include <poll.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
static struct timeval timeval_startup;
|
||||
void __mg_os_start_time(void)
|
||||
{
|
||||
gettimeofday(&timeval_startup, NULL);
|
||||
}
|
||||
|
||||
DWORD __mg_os_get_time_ms(void)
|
||||
{
|
||||
DWORD ds, dms;
|
||||
struct timeval current;
|
||||
|
||||
gettimeofday(¤t, NULL);
|
||||
ds = (current.tv_sec - timeval_startup.tv_sec);
|
||||
|
||||
if (current.tv_sec == timeval_startup.tv_sec) {
|
||||
dms = (current.tv_usec - timeval_startup.tv_usec) / 1000L;
|
||||
}
|
||||
else if (current.tv_usec >= timeval_startup.tv_usec) {
|
||||
dms = (current.tv_usec - timeval_startup.tv_usec) / 1000L;
|
||||
}
|
||||
else {
|
||||
assert(ds > 0);
|
||||
|
||||
ds--;
|
||||
dms = 1000L - (timeval_startup.tv_usec - current.tv_usec) / 1000L;
|
||||
}
|
||||
|
||||
return ds * 1000 + dms;
|
||||
}
|
||||
#endif /* deprecated code */
|
||||
|
||||
#else /* defined HAVE_CLOCK_GETTIME */
|
||||
|
||||
#error "Please implement __mg_os_start_time and __mg_os_get_time_ticks for your OS"
|
||||
|
||||
Reference in New Issue
Block a user