Cygwin: open_shared: always bump next_address
The new loop in open_shared has a subtil performance problem.
Next_address is bumped only if mapping at this address
failed. Every subsequent call to open_shared has a high probability
having to call MapViewOfFileEx twice, because next_address is still
set to the address of the last successful mapping.
Avoid this by bumping next_address every time.
While at it, fix a comment.
Fixes: dc0fe7742b
("Cygwin: open_shared: try harder allocating a shared region")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
parent
e18743072b
commit
7e332208a0
|
@ -159,25 +159,21 @@ open_shared (const WCHAR *name, int n, HANDLE& shared_h, DWORD size,
|
||||||
|
|
||||||
/* Locate shared regions in the area between SHARED_REGIONS_ADDRESS_LOW
|
/* Locate shared regions in the area between SHARED_REGIONS_ADDRESS_LOW
|
||||||
and SHARED_REGIONS_ADDRESS_HIGH, retrying until we have a slot.
|
and SHARED_REGIONS_ADDRESS_HIGH, retrying until we have a slot.
|
||||||
Don't use MapViewOfFile3 (loader deadlock during fork. */
|
Don't use MapViewOfFile3 (STATUS_DLL_INIT_FAILED during fork). */
|
||||||
bool loop = false;
|
bool loop = false;
|
||||||
|
|
||||||
addr = (void *) next_address;
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
addr = (void *) next_address;
|
||||||
shared = MapViewOfFileEx (shared_h, FILE_MAP_READ | FILE_MAP_WRITE,
|
shared = MapViewOfFileEx (shared_h, FILE_MAP_READ | FILE_MAP_WRITE,
|
||||||
0, 0, 0, addr);
|
0, 0, 0, addr);
|
||||||
if (!shared)
|
next_address += wincap.allocation_granularity ();
|
||||||
|
if (next_address >= SHARED_REGIONS_ADDRESS_HIGH)
|
||||||
{
|
{
|
||||||
next_address += wincap.allocation_granularity ();
|
if (!shared && loop)
|
||||||
if (next_address >= SHARED_REGIONS_ADDRESS_HIGH)
|
break;
|
||||||
{
|
next_address = SHARED_REGIONS_ADDRESS_LOW;
|
||||||
if (loop)
|
loop = true;
|
||||||
break;
|
|
||||||
next_address = SHARED_REGIONS_ADDRESS_LOW;
|
|
||||||
loop = true;
|
|
||||||
}
|
|
||||||
addr = (void *) next_address;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (!shared);
|
while (!shared);
|
||||||
|
|
Loading…
Reference in New Issue