//
// Copyright (C) 2000, 2001 Andrey Slepuhin <pooh@msu.ru>
//
// libp++ is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// libp++ is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with libp++; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// $Source$
// $Revision$
// $Date$
// Author: Andrey Slepuhin <pooh@msu.ru>

#ifndef __pxx_sync_hh__
#define __pxx_sync_hh__

namespace pxx
{

template <typename lockT>
class Sync
{

private:

  lockT& lock ;

public:

  inline Sync (lockT& _lock) :
    lock (_lock)
  {
    lock.lock();
  }

  inline ~Sync ()
  {
    lock.unlock();
  }

};

template <typename lockP>
class PSync
{

private:

  lockP lock ;

public:

  inline PSync (lockP _lock) :
    lock (_lock)
  {
    lock->lock();
  }

  inline ~PSync ()
  {
    lock->unlock();
  }

};

#define synchronize(type, x) pxx::Sync<type> __sync (x)
#define psynchronize(type, x) pxx::PSync<type> __sync (x)

}

#endif // __pxx_sync_hh__
