mutex.h

Go to the documentation of this file.
00001 /*
00002  * File Name: mutex.h
00003  */
00004 
00005 /*
00006  * This file is part of uds-plugin-pdf.
00007  *
00008  * uds-plugin-pdf is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * uds-plugin-pdf is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00022 /**
00023  * Copyright (C) 2008 iRex Technologies B.V.
00024  * All rights reserved.
00025  */
00026 
00027 #ifndef MUTEX_H
00028 #define MUTEX_H
00029 
00030 #include <glib.h>
00031 
00032 namespace pdf
00033 {
00034 
00035 class Mutex
00036 {
00037 public:
00038     Mutex() { mutex_ = g_mutex_new(); }
00039     ~Mutex() { g_mutex_free(mutex_); }
00040 
00041     void lock() { g_mutex_lock(mutex_); }
00042     void unlock() { g_mutex_unlock(mutex_); }
00043 
00044     GMutex* get_gmutex() { return mutex_; }
00045 
00046 private:
00047     GMutex *mutex_;
00048 };
00049 
00050 class ScopeMutex
00051 {
00052 public:
00053     ScopeMutex(Mutex *m)
00054         : mutex_(m)
00055     {
00056         mutex_->lock();
00057     }
00058     ~ScopeMutex()
00059     {
00060         mutex_->unlock();
00061     }
00062 
00063 private:
00064     Mutex* mutex_;
00065 };
00066 
00067 };
00068 #endif
00069 
Generated by  doxygen 1.6.2-20100208