diff --git a/harbour/ChangeLog b/harbour/ChangeLog index bc6cf6ba2f..c7314febf1 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,9 @@ +2000-11-27 18:55 UTC+0100 Ryszard Glab + *source/rtl/idle.c + *source/rtl/inkey.c + * Added support for CPU releasing in U*ix + + 2000-11-27 17:14 GMT+1 Maurilio Longo * source/rtl/tbrowse.prg * changed ::RelativePos into ::LastRetrieved (seems more descriptive to me) diff --git a/harbour/source/rtl/idle.c b/harbour/source/rtl/idle.c index 5d8cab3b43..1052040cf6 100644 --- a/harbour/source/rtl/idle.c +++ b/harbour/source/rtl/idle.c @@ -53,6 +53,9 @@ #include "hbapiitm.h" #include "hbvm.h" #include "error.ch" +#if defined(HB_OS_UNIX) + #include +#endif /* list of background tasks */ static HB_ITEM_PTR s_pIdleTasks = NULL; @@ -116,6 +119,11 @@ static void hb_releaseCPU( void ) } #elif defined(HB_OS_UNIX) + { + static struct timespec nanosecs = { 0, 1000 }; + /* NOTE: it will sleep at least 10 miliseconds (forced by kernel) */ + nanosleep( &nanosecs, NULL ); + } #else #endif } diff --git a/harbour/source/rtl/inkey.c b/harbour/source/rtl/inkey.c index 3ab7d0c976..421dac90ed 100644 --- a/harbour/source/rtl/inkey.c +++ b/harbour/source/rtl/inkey.c @@ -57,6 +57,9 @@ #include "inkey.ch" #include +#if defined( HB_OS_UNIX ) + #include +#endif static int * s_inkeyBuffer = 0; /* Harbour keyboard buffer (empty if head == tail) */ static int s_inkeyHead; /* Harbour keyboard buffer head pointer (next insert) */ @@ -104,9 +107,20 @@ int hb_inkey( BOOL bWait, double dSeconds, HB_inkey_enum event_mask ) } else { +#if defined( HB_OS_UNIX ) + /* NOTE: clock() returns a time used by a program - if it is suspended + * then this time will be zero + */ + clock_t end_clock; + struct tms tm; + + end_clock = times( &tm ) + ( clock_t ) ( dSeconds * 100 ); + while( hb_inkeyNext() == 0 && (times( &tm ) < end_clock) ) +#else clock_t end_clock = clock() + ( clock_t ) ( dSeconds * CLOCKS_PER_SEC ); - + while( hb_inkeyNext() == 0 && clock() < end_clock ) +#endif { hb_idleState(); }