Commit Graph

17 Commits

Author SHA1 Message Date
Jonathan Li c2e21fa30e gsdx: Don't use atomic for exit variable
All accesses are protected by locks, so there's no need for it to be
atomic.
2017-01-07 13:54:45 +01:00
Jonathan Li cb2c9ce4e6 gsdx: Don't use separate count variable
It's only ever updated after the queue is updated, so its state will
always lag slightly behind it. It's sufficient to just use empty().

This seems to fix some caching issues that were noticeable on Skylake
CPUs (#998).
2017-01-07 13:54:45 +01:00
Jonathan Li a583fafa37 gsdx: Use lock instead of loop to terminate threads 2017-01-07 13:54:45 +01:00
Jonathan Li b244de73ca gsdx: Use separate mutex for waiting
In the previous code, the worker thread would notify the MTGS thread
while the mutex is still locked, which could cause the MTGS thread to
wake up and immediately go back to sleep again since it can't lock the
mutex.

Use a separate mutex for waiting, which avoids the issue.
2017-01-07 13:54:45 +01:00
Gregory Hainaut 9d1b27cde8 miss a ;
I don't know what I compiled for my previous push !
2016-12-31 17:42:38 +01:00
Gregory Hainaut 1be3f48017 gsdx sw: minor fix on the thread management
* Upgrade the counter to signed 32 bits. 16 bits is too small to contains the 64K value.
* Read ThreadProc/m_count when the mutex is locked
* Use old value of the fetch instead to read back the new value
2016-12-31 16:59:38 +01:00
Jonathan Li ac78688a32 gsdx: Make GSJobQueue non-inheritable
In the previous code, the threads were created and destroyed in the base
class constructor and destructor, so the threads could potentially be
active while the object is in a partially constructed or destroyed state.
The thread however, relies on a virtual function to process the queue
items, and the vtable might not be in the desired state when the object
is partially constructed or destroyed.

This probably only matters during object destruction - no items are in
the queue during object construction so the virtual function won't be
called, but items may still be queued up when the destructor is called,
so the virtual function can be called. It wasn't an issue because all
uses of the thread explicitly waited for the queues to be empty before
invoking the destructor.

Adjust the constructor to take a std::function parameter, which the
thread will use instead to process queue items, and avoid inheriting
from the GSJobQueue class. This will also eliminate the need to
explicitly wait for all jobs to finish (unless there are other external
factors, of course), which would probably make future code safer.
2016-12-08 01:18:17 +00:00
Jonathan Li cdeed349e3 gsdx: Replace platform-specific threads with std::thread
GSThread now doesn't seem to have a purpose, so it's been removed.
2016-12-08 00:36:32 +00:00
Gregory Hainaut d855bc5ca8 gsdx sw: improve exit condition of SW extra thread
Use a relaxed atomic to read the exit variable in the hot path

Wait that exit is deasserted in the destructor, so we are sure the
thread will "soon" return
2016-07-14 18:29:22 +02:00
Jonathan Li 93dc772565 GSdx: Missed a _WINDOWS usage...
Visual Studio Find and Replace can only be trusted if all the files are
included in the project. I suppose it's time to add any missing files
to the relevant projects...
2016-02-04 19:12:46 +00:00
Gregory Hainaut 19c9a0b441 gsdx: remove aggressive threading
http://wiki.pcsx2.net/index.php/PCSX2_Documentation/Threading_Basics
2015-11-20 17:36:03 +01:00
Gregory Hainaut a4d6722b26 gsdx-thread: add a CAPACITY parameter to GSJobQueue 2015-05-18 17:08:18 +02:00
Gregory Hainaut 012f1b4f05 gsdx-thread: remove deprecated boost code 2015-05-18 16:55:49 +02:00
Gregory Hainaut e605ed1d09 gsdx-queue: add a comment for the future 2015-04-17 19:12:36 +02:00
Gregory Hainaut 84b33d2ddb gsdx-queue: plug the new queue as a drop-off replacement of previous boost queue 2015-04-17 19:12:36 +02:00
Gregory Hainaut 0aac47ca59 gsdx-queue: add a new option "spin_thread" to select the queue behavior at runtime
If someone has a more elegant solution, feel free to share it

spin_thread = 0
spin_thread = 1 // the faster but GS thread will never stop, very bad for laptop
2015-04-17 19:03:21 +02:00
Gregory Hainaut 9682061472 gsdx-queue:add a new job dispatcher queue based on boost and C++11
It is faster on linux, it requires less code, and it is "portable"

It requires boost (only hpp files) + MSVC 2013 (for atomic) (seem doable by 2012 too)

Actually there are several queues that either use spinlock or full sleep
2015-04-17 19:03:21 +02:00