Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: test/Thread.cpp

Issue 10105002: Add Sleep and Lock utilities (Closed)
Patch Set: Created April 4, 2013, 5:34 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/Thread.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/Thread.cpp
===================================================================
--- a/test/Thread.cpp
+++ b/test/Thread.cpp
@@ -6,13 +6,6 @@
namespace
{
-#ifndef WIN32
- void Sleep(const int millis)
- {
- usleep(millis * 1000);
- }
-#endif
-
class Mock : public AdblockPlus::Thread
{
public:
@@ -25,10 +18,9 @@
void Run()
{
- Sleep(5);
- mutex.Lock();
+ AdblockPlus::Sleep(5);
+ AdblockPlus::Lock lock(mutex);
timesCalled++;
- mutex.Unlock();
}
};
@@ -45,9 +37,8 @@
void Run()
{
- logMutex.Lock();
+ AdblockPlus::Lock lock(logMutex);
log.push_back(name);
- logMutex.Unlock();
}
private:
@@ -67,10 +58,9 @@
void Run()
{
- queueMutex.Lock();
+ AdblockPlus::Lock lock(queueMutex);
queue.push(1);
notEmpty.Signal();
- queueMutex.Unlock();
}
private:
@@ -90,11 +80,10 @@
void Run()
{
- queueMutex.Lock();
+ AdblockPlus::Lock lock(queueMutex);
if (!queue.size())
notEmpty.Wait(queueMutex);
queue.pop();
- queueMutex.Unlock();
}
private:
@@ -123,7 +112,7 @@
LockingMock mock1("mock1", log, logMutex);
LockingMock mock2("mock2", log, logMutex);
mock1.Start();
- Sleep(5);
+ AdblockPlus::Sleep(5);
mock2.Start();
mock1.Join();
mock2.Join();
@@ -139,7 +128,7 @@
Dequeuer dequeuer(queue, queueMutex, notEmpty);
Enqueuer enqueuer(queue, queueMutex, notEmpty);
dequeuer.Start();
- Sleep(5);
+ AdblockPlus::Sleep(5);
enqueuer.Start();
enqueuer.Join();
dequeuer.Join();
« no previous file with comments | « src/Thread.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld