mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-06-24 06:00:05 +01:00
The benefit of making this function asynchronious ranges from 2%-25% (real time) during fast forward on dual core/hyperthreading-enabled CPUs; 8bpp improvements are, in my test cases, significantly smaller than 32bpp improvements. On single core non-hyperthreading-enabled CPUs the extra locking/scheduling costs up to 1% extra realtime in fast forward. You can use -v sdl:no_threads to disable threading and undo this loss. During normal non-fast-forwarded games the benefit/costs are negligable except when the gameloop takes more than about 90% of the time of a tick. Note that allegro's performance does not improve with this system, likely due to their way of getting data to the video card. It is not implemented for the OS X/Windows video backends, unless (ofcourse) SDL is used there. Funny is that the performance of the 32bpp(-anim) blitter is, at least in some test cases, significantly faster (more than 10%) than the 8bpp(-optimized) blitter when looking at real time in fast forward on a dual core CPU; it was slower. The idea comes from a paper/report by Idar Borlaug and Knut Imar Hagen.
87 lines
2.1 KiB
C++
87 lines
2.1 KiB
C++
/* $Id$ */
|
|
|
|
/*
|
|
* This file is part of OpenTTD.
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
/** @file thread.h Base of all threads. */
|
|
|
|
#ifndef THREAD_H
|
|
#define THREAD_H
|
|
|
|
typedef void (*OTTDThreadFunc)(void *);
|
|
|
|
class OTTDThreadExitSignal { };
|
|
|
|
/**
|
|
* A Thread Object which works on all our supported OSes.
|
|
*/
|
|
class ThreadObject {
|
|
public:
|
|
/**
|
|
* Virtual destructor to allow 'delete' operator to work properly.
|
|
*/
|
|
virtual ~ThreadObject() {};
|
|
|
|
/**
|
|
* Exit this thread.
|
|
*/
|
|
virtual bool Exit() = 0;
|
|
|
|
/**
|
|
* Join this thread.
|
|
*/
|
|
virtual void Join() = 0;
|
|
|
|
/**
|
|
* Create a thread; proc will be called as first function inside the thread,
|
|
* with optinal params.
|
|
* @param proc The procedure to call inside the thread.
|
|
* @param param The params to give with 'proc'.
|
|
* @param thread Place to store a pointer to the thread in. May be NULL.
|
|
* @return True if the thread was started correctly.
|
|
*/
|
|
static bool New(OTTDThreadFunc proc, void *param, ThreadObject **thread = NULL);
|
|
};
|
|
|
|
/**
|
|
* Cross-platform Mutex
|
|
*/
|
|
class ThreadMutex {
|
|
public:
|
|
static ThreadMutex *New();
|
|
|
|
/**
|
|
* Virtual Destructor to avoid compiler warnings.
|
|
*/
|
|
virtual ~ThreadMutex() {};
|
|
|
|
/**
|
|
* Begin the critical section
|
|
*/
|
|
virtual void BeginCritical() = 0;
|
|
|
|
/**
|
|
* End of the critical section
|
|
*/
|
|
virtual void EndCritical() = 0;
|
|
|
|
/**
|
|
* Wait for a signal to be send.
|
|
* @pre You must be in the critical section.
|
|
* @note While waiting the critical section is left.
|
|
* @post You will be in the critical section.
|
|
*/
|
|
virtual void WaitForSignal() = 0;
|
|
|
|
/**
|
|
* Send a signal and wake the 'thread' that was waiting for it.
|
|
*/
|
|
virtual void SendSignal() = 0;
|
|
};
|
|
|
|
#endif /* THREAD_H */
|