win32_timer_impl.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2008 by Kutumov Alexey                                  *
00003  *   ru.pixel@gmail.com                                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00033 #include "gpucalc/win32_timer_impl.h"
00034 
00035 //#define WIN32_LEAN_AND_MEAN
00036 #include <windows.h>
00037 
00038 namespace gpucalc
00039 {
00040 
00041 
00042  template<> Timer * Singleton<Timer>::mSingleton = 0;
00043 
00044 
00045  Timer * Timer::getSingletonPtr()
00046  {
00047   return mSingleton;
00048  }
00049 
00050 
00051  Timer & Timer::getSingleton()
00052  {
00053   assert(mSingleton);
00054   return(* mSingleton);
00055  }
00056  
00057  
00058  Timer::Timer(): Singleton<Timer>(_Win32TimerName)
00059  {
00060   LARGE_INTEGER start;
00061   LARGE_INTEGER freq;
00062   QueryPerformanceCounter(&start); //�������� ��������� �������� ��� ������ �������.
00063   QueryPerformanceFrequency(&freq); //��������� ������� �������� ����������.
00064   mStartTime = start.QuadPart;
00065   mFrequency = freq.QuadPart;
00066   GetProcessAffinityMask(GetCurrentProcess(), &mProcAffinity, &mSysAffinity);
00067   mThread = GetCurrentThread();
00068  }
00069 
00070 
00071  Timer::~Timer()
00072  {
00073  }
00074 
00075 
00076  double Timer::getTime()
00077  {
00078   return static_cast<double>(getCounter()) / static_cast<double>(mFrequency);
00079  }
00080 
00081  __int64 Timer::getCounter()
00082  {
00083   SetProcessAffinityMask(mThread, 1);
00084   LARGE_INTEGER c;
00085   QueryPerformanceCounter(&c); //gets current timestamp value
00086   SetProcessAffinityMask(mThread, mProcAffinity);
00087   return c.QuadPart;
00088  }
00089 }

Generated on Thu Mar 5 22:36:42 2009 for gpucalc by  doxygen 1.5.6