Make SCOPED_LOCK use RAII_VAR.
authorJason Parker <jparker@digium.com>
Tue, 9 Jul 2013 21:40:38 +0000 (21:40 +0000)
committerJason Parker <jparker@digium.com>
Tue, 9 Jul 2013 21:40:38 +0000 (21:40 +0000)
This fixes an issue with requiring SCOPED_LOCK to be the last variable
declaration and removes duplicate code in the process.

Review: https://reviewboard.asterisk.org/r/2665/

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393919 65c4cc65-6c06-0410-ace0-fbb531ad65f3

include/asterisk/lock.h

index 4b1752c..6ede7de 100644 (file)
@@ -600,9 +600,7 @@ static void  __attribute__((destructor)) fini_##rwlock(void) \
  * \param unlockfunc The function to call to unlock the lock
  */
 #define SCOPED_LOCK(varname, lock, lockfunc, unlockfunc) \
-       auto void _dtor_ ## varname (typeof((lock)) * v); \
-       auto void _dtor_ ## varname (typeof((lock)) * v) { unlockfunc(*v); } \
-       typeof((lock)) varname __attribute__((cleanup(_dtor_ ## varname))) = lock; lockfunc((lock))
+       RAII_VAR(typeof((lock)), varname, ({lockfunc((lock)); (lock); }), unlockfunc)
 
 /*!
  * \brief scoped lock specialization for mutexes