]> granicus.if.org Git - libevent/commitdiff
Remove redundant checks for lock!=NULL before calling EVLOCK_LOCK
authorNick Mathewson <nickm@torproject.org>
Wed, 28 Apr 2010 19:16:32 +0000 (15:16 -0400)
committerNick Mathewson <nickm@torproject.org>
Wed, 28 Apr 2010 19:16:32 +0000 (15:16 -0400)
The EVLOCK_LOCK and EVLOCK_UNLOCK macros already check to make sure
that the lock is present before messing with it, so there's no point
in checking the lock before calling them.

A good compiler should be able to simplify code like
  if (lock) {
     if (lock)
        acquire(lock);
  }
, but why count on it?

bufferevent-internal.h

index 1b56c4322e9dba4304586b9663810d4b794d4fbd..71800f7927c5144b465737e4fb2d7467eba168bd 100644 (file)
@@ -352,15 +352,13 @@ int _bufferevent_generic_adj_timeouts(struct bufferevent *bev);
 /** Internal: Grab the lock (if any) on a bufferevent */
 #define BEV_LOCK(b) do {                                               \
                struct bufferevent_private *locking =  BEV_UPCAST(b);   \
-               if (locking->lock)                                      \
-                       EVLOCK_LOCK(locking->lock, 0);                  \
+               EVLOCK_LOCK(locking->lock, 0);                          \
        } while (0)
 
 /** Internal: Release the lock (if any) on a bufferevent */
 #define BEV_UNLOCK(b) do {                                             \
                struct bufferevent_private *locking =  BEV_UPCAST(b);   \
-               if (locking->lock)                                      \
-                       EVLOCK_UNLOCK(locking->lock, 0);                \
+               EVLOCK_UNLOCK(locking->lock, 0);                        \
        } while (0)
 
 /* ==== For rate-limiting. */