[ofw] NDv2 provider patch

Fab Tillier ftillier at microsoft.com
Tue Jul 27 08:52:00 PDT 2010


Hefty, Sean wrote on Mon, 26 Jul 2010 at 10:30:19

> auto-reference obscurity...

Write it correctly once, and you don't have to worry about it further.

>> +class CNDBase
>> +{

<snip...>

>> +       static LONG ObjCount(){ return m_nObj; }
> 
> What is this for?

DllCanUnloadNow uses it.  If there are any objects, it returns E_FALSE.

>> +__inline void* __cdecl operator new(size_t, void* p)
> 
> What's the purpose of this call?  The user passes in a pointer, and the
> function returns it.

Placement new operator, don't want to go use the CRT new operator for this should it get used in the future.  C++ lets you allocate memory, and invoke the constructor of objects on existing memory - you do this by specifying the address of the object to construct.

>> Index: user/nd_base.cpp
>> ===================================================================
>> --- user/nd_base.cpp    (revision 2848)
>> +++ user/nd_base.cpp    (working copy)
>> @@ -1,5 +1,6 @@
>>  /*
>>   * Copyright (c) 2009-2010 Intel Corporation. All rights reserved. + *
>>   Copyright (c) 2010 Microsoft Corporation.  All rights reserved. * *
>>   This software is available to you under the OpenIB.org BSD license *
>>   below: @@ -27,18 +28,45 @@ * SOFTWARE. */
>> +#include "precomp.h"
>>  #include "nd_base.h"
>> -#include <ndstatus.h>
>> 
>> -CNDBase::CNDBase()
>> +
>> +namespace WinVerbs {
>> +namespace NetworkDirect {
>> +
>> +volatile LONG CNDBase::m_nObj = 0;
>> +
>> +CNDBase::CNDBase() :
>> +       m_nRef( 1 )
>>  {
>> -       m_nRef = 1;
>> +       ::InterlockedIncrement( &m_nObj );
> 
> The object is being created here.  Just assign the value 1 - no need
> for an interlocked operation.

m_Obj is interlocked because it's a global count of all objects created.

>> +CNDBase::~CNDBase()
>> +{
>> +       ::InterlockedDecrement( &m_nObj );
> 
> We're in the destructor here.  The reference count should be 0 before
> the destructor is called, not go to 0 in it.

Again, global count, gets decremented once the object is destroyed.



More information about the ofw mailing list