* fhandler.h (refcnt): Add i interlocked. Explain why.

* winbase.h (ilockadd): New function.
	(InterlockedAdd): Define as ilockadd.
This commit is contained in:
Corinna Vinschen
2012-05-23 13:13:56 +00:00
parent 420b3469a7
commit 2ca9ed527e
3 changed files with 29 additions and 2 deletions

View File

@ -185,7 +185,11 @@ class fhandler_base
long refcnt(long i = 0)
{
debug_only_printf ("%p, %s, i %d, refcnt %ld", this, get_name (), i, _refcnt + i);
return _refcnt += i;
/* This MUST be an interlocked operation. If multiple threads access the
same descriptor in quick succession, a context switch can interrupt
the += operation and we wrongly end up with a refcnt of 0 in the
cygheap_fdget destructor. */
return i ? InterlockedAdd (&_refcnt, i) : _refcnt;
}
class fhandler_base *archetype;
int usecount;