Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Add Public implementation RemoveEventHandler in EventRegistrationTokenTable #18671

Merged
merged 3 commits into from
Jun 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,6 @@ private EventRegistrationToken AddEventHandlerNoLock(T handler)
return token;
}

// Get the delegate associated with an event registration token if it exists. Additionally,
// remove the registration from the table at the same time. If the token is not registered,
// Extract returns null and does not modify the table.
// [System.Runtime.CompilerServices.FriendAccessAllowed]
internal T ExtractHandler(EventRegistrationToken token)
{
T handler = null;
lock (m_tokens)
{
if (m_tokens.TryGetValue(token, out handler))
{
RemoveEventHandlerNoLock(token);
}
}

return handler;
}

// Generate a token that may be used for a particular event handler. We will frequently be called
// upon to look up a token value given only a delegate to start from. Therefore, we want to make
// an initial token value that is easily determined using only the delegate instance itself. Although
Expand Down Expand Up @@ -169,6 +151,23 @@ private static EventRegistrationToken GetPreferredToken(T handler)
return new EventRegistrationToken(tokenValue);
}

// Remove the event handler from the table and
// Get the delegate associated with an event registration token if it exists
// If the event registration token is not registered, returns false
public bool RemoveEventHandler(EventRegistrationToken token, out T handler)
{
lock (m_tokens)
{
if (m_tokens.TryGetValue(token, out handler))
{
RemoveEventHandlerNoLock(token);
return true;
}
}

return false;
}

public void RemoveEventHandler(EventRegistrationToken token)
{
// The 0 token is assigned to null handlers, so there's nothing to do
Expand Down