#ifndef __GUARDEDSTACK_HPP #define __GUARDEDSTACK_HPP #include "boundedstack.hpp" #include "unboundedstack.hpp" template class GuardedBoundedStack : public BoundedStack { public: void lock() { guard.lock(); } void unlock() { guard.unlock(); } class Lock { GuardedBoundedStack *stack; public: Lock(GuardedBoundedStack *s) : stack(s) { stack->lock(); } ~Lock() { stack->unlock(); } }; protected: Guard guard; }; template class GuardedUnboundedStack : public UnboundedStack { public: void lock() { guard.lock(); } void unlock() { guard.unlock(); } class Lock { GuardedUnbundedStack *stack; public: Lock(GuardedUnbundedStack *s) : stack(s) { stack->lock(); } ~Lock() { stack->unlock(); } }; protected: Guard guard; }; #endif