-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCallbackLock.cs
More file actions
44 lines (38 loc) · 1.36 KB
/
CallbackLock.cs
File metadata and controls
44 lines (38 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// -----------------------------------------------------------------------
// <copyright file="CallbackLock.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
namespace Microsoft.Kinect.Toolkit
{
using System;
using System.Threading;
/// <summary>
/// Utility class that encapsulates critical section-like locking
/// and an event that gets fired after we exit the lock. It's
/// purpose in life is to delay calling event handlers until after
/// we exit the lock. If you call event handlers while you hold a
/// lock it's easy to deadlock. Those event handlers could
/// choose to block on something on a diffrent thread that's
/// waiting on our lock.
/// </summary>
internal class CallbackLock : IDisposable
{
private readonly object lockObject;
public CallbackLock(object lockObject)
{
this.lockObject = lockObject;
Monitor.Enter(lockObject);
}
public delegate void LockExitEventHandler();
public event LockExitEventHandler LockExit;
public void Dispose()
{
Monitor.Exit(lockObject);
if (LockExit != null)
{
LockExit();
}
}
}
}