Fixed memory consumption for certain WFMO usage patterns
Fixed memory consumption for certain WFMO usage patterns

In cases where WaitForMultipleEvents is called with multiple events
and waitAll is set to false, the WFMO wait objects queued in the
events' RegisteredWaits deque are only removed for the event that
was then signaled as a performance optimization; the WFMO wait
objects queued for other events are cleaned up the next time a call
to WaitForMultipleEvents is made, via the RemoveExpiredWaitHelper
function. (Otherwise we'd have to obtain the mutex for all events
in the array once more before exiting the WFME call).

In certain non-standard usage patterns where WFME() is called with
one or more events that did not trigger (and waitAll is false) and
no subsequent calls were (ever again) made to WFME with the non-
triggered events, the WFMO wait objects would remain allocated
indefinitely.

This commit addresses this issue by explicitly calling the
RemoveExpiredWaitHelper() function on calls to DestroyEvent(), at
the cost of obtaining a mutex lock for the event. As DestroyEvent()
should never be called on events being waited on, the mutex should
always be available leading to a hopefully negligible delay in
obtaining the mutex before ultimately destroying it.

Credit to Giang Nguyen <GiangND@fsoft.com.vn> for pointing out the
memory consumption issue.

neosmart/pevents,neosmart/pevents