[PATCH v3 0/3] MR11440: comsvcs: Exit resource lookup loop when perfect match is found in AllocResource.
-- v3: comsvcs: Remove the FIXME message since pool purging is implemented. https://gitlab.winehq.org/wine/wine/-/merge_requests/11440
From: Piotr Caban <piotr@codeweavers.com> --- dlls/comsvcs/main.c | 7 ++++++- dlls/comsvcs/tests/comsvcs.c | 27 +++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/dlls/comsvcs/main.c b/dlls/comsvcs/main.c index 08b5e323076..cbaa36b29af 100644 --- a/dlls/comsvcs/main.c +++ b/dlls/comsvcs/main.c @@ -159,10 +159,13 @@ static HRESULT WINAPI holder_AllocResource(IHolder *iface, const RESTYPID typeid { if (res->timestamp == RESOURCE_IN_USE) continue; hr = IDispenserDriver_RateResource(This->driver, typeid, res->resid, FALSE, &rating); - if (SUCCEEDED(hr) && rating && rating >= best_rating) + if (SUCCEEDED(hr) && rating && rating > best_rating) { best_rating = rating; best = res; + + if (rating >= 100) + break; } } if (best) @@ -239,6 +242,8 @@ static HRESULT WINAPI holder_FreeResource(IHolder *iface, const RESID resid) } res->timestamp = GetTickCount64(); + list_remove(&res->entry); + list_add_head(&This->pool, &res->entry); LeaveCriticalSection(&This->cs); return hr; } diff --git a/dlls/comsvcs/tests/comsvcs.c b/dlls/comsvcs/tests/comsvcs.c index 171259d5e0f..1416bb4c3d2 100644 --- a/dlls/comsvcs/tests/comsvcs.c +++ b/dlls/comsvcs/tests/comsvcs.c @@ -29,7 +29,7 @@ #include "wine/test.h" #define DEFINE_EXPECT(func) \ - static BOOL expect_ ## func = FALSE, called_ ## func = FALSE + static BOOL expect_ ## func = FALSE; static unsigned int called_ ## func = 0 #define SET_EXPECT(func) \ called_ ## func = FALSE, expect_ ## func = TRUE @@ -37,13 +37,21 @@ #define CHECK_CALLED(func) \ do { \ ok(called_ ## func, "expected " #func "\n"); \ - expect_ ## func = called_ ## func = FALSE; \ + expect_ ## func = FALSE; \ + called_ ## func = 0; \ + }while(0) + +#define CHECK_CALLEDN(func, n) \ + do { \ + ok(called_ ## func == n, "expected " #func " called %u times, got %u\n", n, called_ ## func); \ + expect_ ## func = FALSE; \ + called_ ## func = 0; \ }while(0) #define CHECK_EXPECT2(func) \ do { \ ok(expect_ ##func, "unexpected call " #func "\n"); \ - called_ ## func = TRUE; \ + called_ ## func++; \ }while(0) #define CHECK_CALLED_BROKEN(func) \ @@ -276,7 +284,18 @@ static void create_dispenser(void) hr = IHolder_AllocResource(holder1, (RESTYPID)str, &resid); ok(hr == S_OK, "got 0x%08lx\n", hr); ok(resid == 10, "got %Id\n", resid); - CHECK_CALLED(driver_RateResource); + CHECK_CALLEDN(driver_RateResource, 2); + + SET_EXPECT(driver_ResetResource); + hr = IHolder_FreeResource(holder1, resid); + ok(hr == S_OK, "got 0x%08lx\n", hr); + CHECK_CALLED(driver_ResetResource); + + SET_EXPECT(driver_RateResource); + hr = IHolder_AllocResource(holder1, (RESTYPID)str, &resid); + ok(hr == S_OK, "got 0x%08lx\n", hr); + ok(resid == 10, "got %Id\n", resid); + CHECK_CALLEDN(driver_RateResource, 1); SET_EXPECT(driver_DestroyResource); SET_EXPECT(driver_Release); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/11440
From: Piotr Caban <piotr@codeweavers.com> --- dlls/comsvcs/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dlls/comsvcs/main.c b/dlls/comsvcs/main.c index cbaa36b29af..c5b55e156c1 100644 --- a/dlls/comsvcs/main.c +++ b/dlls/comsvcs/main.c @@ -460,7 +460,7 @@ static DWORD WINAPI purge_expired_resources(void *arg) EnterCriticalSection(&hold->cs); LIST_FOR_EACH_ENTRY_SAFE(res, tmp, &hold->pool, resource, entry) { - if (res->timestamp == RESOURCE_IN_USE) continue; + if (res->timestamp == RESOURCE_IN_USE) break; if (!res->ttl) continue; if (res->timestamp + res->ttl * 1000 > ticks) continue; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/11440
From: Piotr Caban <piotr@codeweavers.com> --- dlls/comsvcs/main.c | 1 - 1 file changed, 1 deletion(-) diff --git a/dlls/comsvcs/main.c b/dlls/comsvcs/main.c index c5b55e156c1..2bb50c857d3 100644 --- a/dlls/comsvcs/main.c +++ b/dlls/comsvcs/main.c @@ -193,7 +193,6 @@ static HRESULT WINAPI holder_AllocResource(IHolder *iface, const RESTYPID typeid free(res); return hr; } - if (res->ttl) FIXME("ignoring maximum idle time\n"); EnterCriticalSection(&This->cs); if (!This->driver) -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/11440
participants (2)
-
Piotr Caban -
Piotr Caban (@piotr)