Commit 2926e966 by Maxime Grégoire

Use of std::mutex instead of Resources in Devices

Change-Id: Ib276cae0b196949a91dd13f436dfe853e1cf1b25 Reviewed-on: https://swiftshader-review.googlesource.com/3712Reviewed-by: 's avatarMaxime Grégoire <mgregoire@google.com> Tested-by: 's avatarMaxime Grégoire <mgregoire@google.com>
parent bc26e7ce
......@@ -24,7 +24,7 @@
using namespace Devices;
CPUDevice::CPUDevice()
: DeviceInterface(), p_num_events(0), p_stop(false)
: DeviceInterface(), p_num_events(0), p_stop(false), initialized(false)
{
}
......@@ -33,7 +33,6 @@ void CPUDevice::init()
{
// Initialize the locking machinery
p_events_cond = new sw::Event();
eventListResource = new sw::Resource(0);
//TODO CHANGE pcore value to real
p_cpu_mhz = 3200;
......@@ -43,12 +42,21 @@ void CPUDevice::init()
{
p_workers[i] = new sw::Thread(worker, this);
}
initialized = true;
}
CPUDevice::~CPUDevice()
{
if(!initialized)
return;
p_events_cond->signal();
p_stop = true;
delete p_events_cond;
for(int thread = 0; thread < sw::CPUID::coreCount(); thread++)
{
if(p_workers[thread])
......@@ -58,14 +66,7 @@ CPUDevice::~CPUDevice()
delete p_workers[thread];
p_workers[thread] = 0;
}
}
p_events_cond->signal();
delete p_events_cond;
eventListResource->lock(sw::DESTRUCT);
eventListResource->unlock();
eventListResource->destruct();
}
}
DeviceBuffer *CPUDevice::createDeviceBuffer(MemObject *buffer, cl_int *rs)
......@@ -167,27 +168,27 @@ void CPUDevice::freeEventDeviceData(Event *event)
void CPUDevice::pushEvent(Event *event)
{
eventListResource->lock(sw::PRIVATE);
eventListResource.lock();
p_events.push_back(event);
p_num_events++;
p_events_cond->signal();
eventListResource->unlock();
eventListResource.unlock();
}
Event *CPUDevice::getEvent(bool &stop)
{
eventListResource->lock(sw::PRIVATE);
// Return the first event in the list, if any. Remove it if it is a
// single-shot event.
while(p_num_events == 0 && !p_stop)
p_events_cond->wait();
eventListResource.lock();
if(p_stop)
{
eventListResource->unlock();
eventListResource.unlock();
stop = true;
return 0;
}
......@@ -210,7 +211,7 @@ Event *CPUDevice::getEvent(bool &stop)
p_events.pop_front();
}
eventListResource->unlock();
eventListResource.unlock();
return event;
}
......
......@@ -7,6 +7,7 @@
#define MAX_THREAD_AMOUNT 16
#include <list>
#include <mutex>
#include "opencl.h"
#include "device_interface.h"
......@@ -51,10 +52,10 @@ private:
unsigned int p_num_events;
float p_cpu_mhz;
sw::Thread *p_workers[MAX_THREAD_AMOUNT];
sw::Resource *eventListResource;
std::mutex eventListResource;
sw::Event *p_events_cond;
std::list<Event *> p_events;
bool p_stop;
bool p_stop, initialized;
};
//class GPUDevice : public DeviceInterface
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment