Scopira 20080306

mutex_qtthreads.h

00001 
00002 /*
00003  *  Copyright (c) 2009    National Research Council
00004  *
00005  *  All rights reserved.
00006  *
00007  *  This material is confidential and proprietary information of
00008  *  National Research Council Canada ("Confidential Information").
00009  *  This Confidential Information may only be used and reproduced
00010  *  in accordance with the terms of the license agreement.
00011  *
00012  */
00013 
00014 #ifndef __INCLUDED_SCOPIRA_TOOL_MUTEX_QTTHREADS_H__
00015 #define __INCLUDED_SCOPIRA_TOOL_MUTEX_QTTHREADS_H__
00016 
00017 #include <QMutex>
00018 
00019 #include <scopira/tool/platform.h>
00020 #include <scopira/tool/export.h>
00021 
00022 namespace scopira
00023 {
00024   namespace tool
00025   {
00026     class mutex;
00027     class locker;
00028   }
00029 }
00030 
00038 class scopira::tool::mutex
00039 {
00040   protected:
00041     QMutex dm_mut;
00042 
00043   public:
00045     SCOPIRA_EXPORT mutex(void);
00046     SCOPIRA_EXPORT ~mutex(void);
00047 
00053     SCOPIRA_EXPORT void lock(void) { dm_mut.lock(); }
00054 
00061     SCOPIRA_EXPORT void unlock(void) { dm_mut.unlock(); }
00062 
00073     SCOPIRA_EXPORT bool try_lock(void) { return dm_mut.tryLock(); }
00074 
00079     SCOPIRA_EXPORT inline QMutex * get_os_mutex(void) { return &dm_mut; }
00080 };
00081 
00090 class scopira::tool::locker
00091 {
00092   private:
00093     mutex &dm_mut;
00094   public:
00099     locker(mutex &mut) : dm_mut(mut) { dm_mut.lock(); }
00104     ~locker() { dm_mut.unlock(); }
00105 };
00106 
00107 #endif
00108