php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #8728 Patch: usleep() working on win32 platforms
Submitted: 2001-01-15 18:22 UTC Modified: 2002-04-04 05:35 UTC
From: christophe at winamp dot com Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.0.4pl1 OS: Any Windows OS
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: christophe at winamp dot com
New email:
PHP Version: OS:

 

 [2001-01-15 18:22 UTC] christophe at winamp dot com
usleep exists on Win32 as the Sleep command (it takes a millisecond value as parameter) so here is the patch for making the usleep() php function to work on win32 platforms:

in main/win95nt.h, line 27:

#define php_sleep(t)	Sleep(t*1000)

add the following line so it looks like:
#define php_sleep(t)	Sleep(t*1000)
#define usleep(t)  Sleep(t)

and in config.w32.h, line 93:

/* Define if you have the usleep function.  */
#undef HAVE_USLEEP

change it to:

/* Define if you have the usleep function.  */
#define HAVE_USLEEP 1

-Christophe Thibault
Nullsoft (www.nullsoft.com/www.winamp.com)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-01-15 18:40 UTC] christophe at winamp dot com
oops... my previous patch was incorrect, let me start over:

in main/config.w32.h, line 93:

/* Define if you have the usleep function.  */
#undef HAVE_USLEEP

change it to:

/* Define if you have the usleep function.  */
#define HAVE_USLEEP 1

in win32/time.c, line 53:

void usleep(unsigned int useconds)
{
	__int64 mstimer, freq;
	long now, then;
	if (QueryPerformanceFrequency((LARGE_INTEGER *) & freq)) {
		QueryPerformanceCounter((LARGE_INTEGER *) & mstimer);
		now = (long) (((__int64) (mstimer * .8)) % 0x0FFFFFFF);
		then = now + useconds;
		while (now < then) {
			QueryPerformanceCounter((LARGE_INTEGER *) & mstimer);
			now = (long) (((__int64) (mstimer * .8)) % 0x0FFFFFFF);
		}
	} else {
		/*workaround for systems without performance counter
		   this is actualy a millisecond sleep */
		Sleep((int) (useconds / 1000));
	}
}

change it to:

void usleep(unsigned int useconds)
{
#if 0
	__int64 mstimer, freq;
	long now, then;
	if (QueryPerformanceFrequency((LARGE_INTEGER *) & freq)) {
		QueryPerformanceCounter((LARGE_INTEGER *) & mstimer);
		now = (long) (((__int64) (mstimer * .8)) % 0x0FFFFFFF);
		then = now + useconds;
		while (now < then) {
			QueryPerformanceCounter((LARGE_INTEGER *) & mstimer);
			now = (long) (((__int64) (mstimer * .8)) % 0x0FFFFFFF);
		}
	} else {
		/*workaround for systems without performance counter
		   this is actualy a millisecond sleep */
		Sleep((int) (useconds / 1000));
	}
#else
  Sleep((DWORD) useconds);
#endif
}

and now it works great :)
can someone reflect this patch in the cvs tree?

-Christophe Thibault
Nullsoft (www.nullsoft.com/www.winamp.com)

 [2002-04-04 05:35 UTC] sniper@php.net
This is fixed already. Please try PHP 4.2.0RC2 from
http://www.php.net/~derick/

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu May 08 00:01:29 2025 UTC