[ofw] PATCH: [mlx4] Add support for multiple use/loose operations.

Tzachi Dar tzachid at mellanox.co.il
Thu Feb 12 14:06:27 PST 2009


--- Q:/projinf2/trunk/hw/mlx4/kernel/inc/shutter.h (revision 3954)
+++ Q:/projinf2/trunk/hw/mlx4/kernel/inc/shutter.h (revision 3955)
@@ -48,14 +48,29 @@
  KeInitializeEvent( &p_shutter->event, SynchronizationEvent, FALSE );
 }
 
-// if RC > 0, one can proceed
-static inline int shutter_use(shutter_t * p_shutter)
+
+static inline void shutter_sub(shutter_t * p_shutter,long Val)
 {
- long res = InterlockedIncrement( &p_shutter->cnt ); 
+    long res = 0;
+    ASSERT(Val < 0);
+ res = InterlockedExchangeAdd( &p_shutter->cnt,Val );
+ if ((res+Val) == -MAX_OPERATIONS)
+  KeSetEvent( &p_shutter->event, 0, FALSE );
+}
+
+// if RC == true, one can proceed
+static inline BOOLEAN shutter_add(shutter_t * p_shutter,long Val)
+{
+    long res = 0;
+    ASSERT(Val > 0);
+ res = InterlockedExchangeAdd(&p_shutter->cnt,Val); 
  ASSERT(res <= MAX_OPERATIONS);
- if (res <= 0 ) 
-  InterlockedDecrement( &p_shutter->cnt ); // The object is in shutdown
- return res;
+ if (res < 0 )
+ {        
+  shutter_sub(p_shutter, -Val);
+  return FALSE;
+ }
+ return TRUE;
 }
 
 static inline void shutter_loose(shutter_t * p_shutter)
@@ -65,14 +80,38 @@
   KeSetEvent( &p_shutter->event, 0, FALSE );
 }
 
+// if RC > 0, one can proceed
+static inline int shutter_use(shutter_t * p_shutter)
+{
+ long res = InterlockedIncrement( &p_shutter->cnt ); 
+ ASSERT(res <= MAX_OPERATIONS);
+ if (res <= 0 ) 
+  shutter_loose( p_shutter ); // The object is in shutdown
+ return res;
+}
+
+
 static inline void shutter_shut(shutter_t * p_shutter)
 {
- long res;
+    //
+    //  ASSERT not calling shu twice.
+    //
+    ASSERT(p_shutter->cnt - MAX_OPERATIONS >=  (-MAX_OPERATIONS));
+    
  // Mark the counter as locked
- res = InterlockedExchangeAdd(&p_shutter->cnt, -MAX_OPERATIONS);
+ long res = InterlockedExchangeAdd(&p_shutter->cnt, -MAX_OPERATIONS);
  ASSERT(res >= 0);
  if (res) 
   // We are now waiting for the object to reach -MAX_OPERATIONS
   KeWaitForSingleObject( &p_shutter->event, Executive, KernelMode,
FALSE, NULL );
 }
 
+static inline void shutter_alive(shutter_t * p_shutter)
+{
+    ASSERT(p_shutter->cnt == -MAX_OPERATIONS);
+ // Mark the counter as locked
+ long res = InterlockedExchangeAdd(&p_shutter->cnt, MAX_OPERATIONS);
+ ASSERT(res < 0);
+}
+
+

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openfabrics.org/pipermail/ofw/attachments/20090213/1dceab4e/attachment.html>


More information about the ofw mailing list