8000 Call git_threads_shutdown() after last handle get disposed by jbialobr · Pull Request #358 · libgit2/libgit2sharp · GitHub
[go: up one dir, main page]

Skip to content

Call git_threads_shutdown() after last handle get disposed #358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 20 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
a309c19
Call git_threads_shutdown() after last handle get disposed
jbialobr Mar 1, 2013
79d4def
Corrected due to review comments
jbialobr Mar 1, 2013
9b864cd
Reverted changes done to SafeHandleBase.Dispose
jbialobr Mar 1, 2013
bdd45ed
Decrement when removing
jbialobr Mar 1, 2013
cd70dbc
Seal ReleaseHandle
jbialobr Mar 1, 2013
cbf5c69
InternalReleaseHandle -> ReleaseHandleImpl
jbialobr Mar 1, 2013
f90a967
Only call AddHandle when we know the handle is valid (i.e. ReleaseHan…
sharwell Mar 1, 2013
05d23bb
Remove handle when dispose is called for the first time
jbialobr Mar 1, 2013
d2d5b41
Revert "Remove handle when dispose is called for the first time"
jbialobr Mar 1, 2013
bbf738f
Merge pull request #1 from sharwell/jbialobr_vNext
jbialobr Mar 1, 2013
3e4cb0f
Handle the case when IsInvalid will be called for the first time afte…
jbialobr Mar 1, 2013
be73756
Make sure handles get registered, and also clean up invalid handles
sharwell Mar 1, 2013
3715ec2
Unregister handle from finalizer either Dispose
jbialobr Mar 2, 2013
858f084
Make sure the debugger doesn't evaluate the SafeHandleBase.IsInvalid …
sharwell Mar 2, 2013
ab6c594
Safe and clearly documented global cleanup in SafeHandleBase
sharwell Mar 2, 2013
ccef7be
Update code for execution in a contrained execution region
sharwell Mar 2, 2013
093fca9
Add ReliabilityContract attributes.
jbialobr Mar 3, 2013
5ca8226
Revert "Add ReliabilityContract attributes."
jbialobr Mar 4, 2013
fb02cac
Revert "Unregister handle from finalizer either Dispose"
jbialobr Mar 4, 2013
3c02129
Merge branch 'pr/n2_sharwell' into vNext
jbialobr Mar 4, 2013
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
Prev Previous commit
Next Next commit
Handle the case when IsInvalid will be called for the first time afte…
…r call to ~LibraryLifetimeObject
  • Loading branch information
jbialobr committed Mar 1, 2013
commit 3e4cb0f18b700a1364a344da4a3dbd1f26f3f55d
19 changes: 18 additions & 1 deletion LibGit2Sharp/Core/Handles/SafeHandleBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace LibGit2Sharp.Core.Handles
{
internal abstract class SafeHandleBase : SafeHandle
{
private int isInvalidCallCount = 0;
#if LEAKS
private readonly string trace;
#endif
Expand All @@ -21,6 +22,7 @@ internal abstract class SafeHandleBase : SafeHandle
protected SafeHandleBase()
: base(IntPtr.Zero, true)
{
NativeMethods.AddHandle();
#if LEAKS
trace = new StackTrace(2, true).ToString();
#endif
Expand All @@ -47,12 +49,27 @@ public override sealed bool IsInvalid
get
{
bool invalid = IsInvalidImpl();
bool firstTimeCall = false;

if (Interlocked.Increment(ref isInvalidCallCount) == 1)
{
//remove handle if it is invalid
//it will be added if it becomes valid
if(invalid)
NativeMethods.RemoveHandle();

firstTimeCall = true;
}

if (!invalid && Interlocked.CompareExchange(ref registered, 1, 0) == 0)
{
// Call AddHandle at most 1 time for this handle, and only after
// we know that the handle is valid (i.e. ReleaseHandle will eventually
// be called).
NativeMethods.AddHandle();
//if this is the first time call, don't add it
//it was already added in constructor
if (!firstTimeCall)
NativeMethods.AddHandle();
}

return invalid;
Expand Down
0