usleep() on win32

From: Date: Fri, 27 Jan 2006 01:07:15 +0000
Subject: usleep() on win32
Groups: php.internals 
Request: Send a blank email to internals+get-21695@lists.php.net to get a copy of this message
Hi Here is a small change to usleep so it will work with win32. It is very useful for tight while loops when using socket functions and reduces cpu load from 100% to 0%-2% (on my win2k box) by just adding usleep(1000); after the while(). (Code snippet was taken from pgsql) Diff is from php-4.4 cvs RCS file: /repository/php-src/ext/standard/basic_functions.c,v retrieving revision 1.543.2.51.2.6 diff -u -w -b -r1.543.2.51.2.6 basic_functions.c --- basic_functions.c 1 Jan 2006 13:46:57 -0000 1.543.2.51.2.6 +++ basic_functions.c 27 Jan 2006 00:52:10 -0000 @@ -1677,14 +1677,20 @@ Delay for a given number of micro seconds */ PHP_FUNCTION(usleep) { -#if HAVE_USLEEP pval **num; if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_long_ex(num); +#if HAVE_USLEEP usleep(Z_LVAL_PP(num)); +#else +#ifdef PHP_WIN32 + do { + SleepEx((Z_LVAL_PP(num) < 500 ? 1 : (Z_LVAL_PP(num) + 500) / 1000), TRUE); + } while(0); +#endif #endif } /* }}} */ -- Tom

« previous php.internals (#21695) next »