#ifndef _LOCKER_H_
#define _LOCKER_H_
#include <pthread.h>

namespace jf {

class Locker {
   public:
    Locker();
    virtual ~Locker();

    virtual void lock(int type = 0);
    virtual void unlock();

   private:
    pthread_mutex_t m_mutex;
};

class RWLocker : public Locker {
   public:
    RWLocker();
    virtual ~RWLocker();

    virtual void lock(int type);
    virtual void unlock();

   private:
    pthread_rwlock_t m_mutex;
};

class AutoLock {
   private:
    Locker& m_locker;

   public:
    AutoLock(Locker& m, int type = 0) : m_locker(m) { m_locker.lock(type); }

    ~AutoLock() { m_locker.unlock(); }
};

}  // namespace jf

#endif  //_LOCKER_H_