cgma
CubitConcurrentApi.cpp
Go to the documentation of this file.
00001 
00002 
00003 #include "CubitConcurrentApi.h"
00004 
00005 #ifdef _WIN32
00006 #include <windows.h>
00007 #else
00008 #include <pthread.h>
00009 #endif
00010 
00011 #ifdef _WIN32
00012   // struct for working with mutexes
00013   class RealMutex : public CubitConcurrent::Mutex
00014   {
00015   public:
00016     RealMutex()
00017     {
00018       InitializeCriticalSection(&mCriticalSection);
00019     }
00020     ~RealMutex()
00021     {
00022       DeleteCriticalSection(&mCriticalSection);
00023     }
00024     virtual void lock()
00025     {
00026       EnterCriticalSection(&mCriticalSection);
00027     }
00028     virtual void unlock()
00029     {
00030       LeaveCriticalSection(&mCriticalSection);
00031     }
00032   protected:
00033     CRITICAL_SECTION mCriticalSection;
00034   };
00035 
00036 #else
00037   // struct for working with mutexes
00038   class RealMutex : public CubitConcurrent::Mutex
00039   {
00040   public:
00041     RealMutex()
00042     {
00043       pthread_mutex_init(&mMutex, NULL);
00044     }
00045     ~RealMutex()
00046     {
00047       pthread_mutex_destroy(&mMutex);
00048     }
00049     virtual void lock()
00050     {
00051       pthread_mutex_lock(&mMutex);
00052     }
00053     virtual void unlock()
00054     {
00055       pthread_mutex_unlock(&mMutex);
00056     }
00057   protected:
00058     pthread_mutex_t mMutex;
00059   };
00060 #endif
00061 
00062 CubitConcurrent *CubitConcurrent::mInstance = 0;
00063 
00064 
00065 CubitConcurrent::CubitConcurrent()
00066 {
00067 }
00068 
00069 CubitConcurrent::~CubitConcurrent()
00070 {
00071 }
00072 
00073 const char* CubitConcurrent::get_base_type() const
00074 { 
00075     return "ConcurrentApi";
00076 }
00077 
00078 CubitConcurrent::Mutex* CubitConcurrent::create_mutex()
00079 {
00080   return new RealMutex;
00081 }
00082 
00083 void CubitConcurrent::destroy_mutex(CubitConcurrent::Mutex* m)
00084 {
00085   delete m;
00086 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines