log4cplus  1.1.0
lockfile.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 //  Copyright (C) 2012, Vaclav Zeman. All rights reserved.
00004 //
00005 //  Redistribution and use in source and binary forms, with or without modifica-
00006 //  tion, are permitted provided that the following conditions are met:
00007 //
00008 //  1. Redistributions of  source code must  retain the above copyright  notice,
00009 //     this list of conditions and the following disclaimer.
00010 //
00011 //  2. Redistributions in binary form must reproduce the above copyright notice,
00012 //     this list of conditions and the following disclaimer in the documentation
00013 //     and/or other materials provided with the distribution.
00014 //
00015 //  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
00016 //  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
00017 //  FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
00018 //  APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
00019 //  INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
00020 //  DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
00021 //  OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
00022 //  ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
00023 //  (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
00024 //  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025 
00026 #if ! defined (LOG4CPLUS_HELPERS_LOCKFILE_H)
00027 #define LOG4CPLUS_HELPERS_LOCKFILE_H
00028 
00029 #include <log4cplus/config.hxx>
00030 
00031 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
00032 #pragma once
00033 #endif
00034 
00035 #include <log4cplus/tstring.h>
00036 #include <log4cplus/thread/syncprims.h>
00037 
00038 
00039 namespace log4cplus { namespace helpers {
00040 
00041 
00042 class LOG4CPLUS_EXPORT LockFile
00043 {
00044 public:
00045     LockFile (tstring const & lock_file);
00046     ~LockFile ();
00047 
00048     void lock () const;
00049     void unlock () const;
00050 
00051 private:
00052     void open (int) const;
00053     void close () const;
00054 
00055     struct Impl;
00056 
00057     tstring lock_file_name;
00058     Impl * data;
00059 };
00060 
00061 
00062 typedef log4cplus::thread::SyncGuard<LockFile> LockFileGuard;
00063 
00064 
00065 } } // namespace log4cplus { namespace helpers {
00066 
00067 
00068 #endif // LOG4CPLUS_HELPERS_LOCKFILE_H