I am reading the source code of leveldb, esp. regarding mutexlock.
I found this declaration:
class SCOPED_LOCKABLE MutexLock {
public:
explicit MutexLock(port::Mutex *mu) EXCLUSIVE_LOCK_FUNCTION(mu)
: mu_(mu) {
this->mu_->Lock();
}
~MutexLock() UNLOCK_FUNCTION() { this->mu_->Unlock(); }
private:
port::Mutex *const mu_;
// No copying allowed
MutexLock(const MutexLock&);
void operator=(const MutexLock&);
};
and I found that SCOPED_LOCKABLE
is defined as empty, so why use it in the class declaration?
In class or function definitions if developer need to attach extra characteristic it uses MACROS than hard coding in each class or function definitions. This is a good practice for programming. because one day if you need to change this characteristic you have to change in only one place not everywhere of the code.
Some usage of macros in class definition
#ifdef CONTROLLER_EXPORTS
#define CONTROLLER_API __declspec(dllexport)
#else
#define CONTROLLER_API __declspec(dllimport)
#endif
class CONTROLLER_API CConfiguration{
} ;
You can get some more windows related useful clues here. http://msdn.microsoft.com/en-us/library/dabb5z75(v=vs.80).aspx
Even you can use access modifiers also like this, because some time for testing you may need to change the access level temporary.
#define PRIVATE private
#define PUBLIC public
class A{
PRIVATE:
int m_a;
PUBLIC:
int m_b;
}
Then what is exact your issue? it can be any useful characteristic define like above. here is one example i got from git
#define SCOPED_LOCKABLE __attribute__ ((scoped_lockable))
__attribute__
check here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With