Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(661)

Unified Diff: src/IceThreading.h

Issue 1804133002: Subzero. Uses unique_ptrs in the emit queue. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Addresses comments. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/IceGlobalContext.cpp ('k') | src/IceThreading.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/IceThreading.h
diff --git a/src/IceThreading.h b/src/IceThreading.h
index ecc350e0d5cd31ebe486bafec6d5ffe9c4962242..40ada47c1622d4780cfe7fd3b5b5f83301795910 100644
--- a/src/IceThreading.h
+++ b/src/IceThreading.h
@@ -18,7 +18,9 @@
#include "IceDefs.h"
#include <condition_variable>
+#include <memory>
#include <mutex>
+#include <utility>
namespace Ice {
@@ -55,18 +57,18 @@ class BoundedProducerConsumerQueue {
public:
BoundedProducerConsumerQueue(bool Sequential, size_t MaxSize = MaxStaticSize)
: MaxSize(std::min(MaxSize, MaxStaticSize)), Sequential(Sequential) {}
- void blockingPush(T *Item) {
+ void blockingPush(std::unique_ptr<T> Item) {
{
std::unique_lock<GlobalLockType> L(Lock);
// If the work queue is already "full", wait for a consumer to grab an
// element and shrink the queue.
Shrunk.wait(L, [this] { return size() < MaxSize || Sequential; });
- push(Item);
+ push(std::move(Item));
}
GrewOrEnded.notify_one();
}
- T *blockingPop() {
- T *Item = nullptr;
+ std::unique_ptr<T> blockingPop() {
+ std::unique_ptr<T> Item;
bool ShouldNotifyProducer = false;
{
std::unique_lock<GlobalLockType> L(Lock);
@@ -95,7 +97,7 @@ private:
ICE_CACHELINE_BOUNDARY;
/// WorkItems and Lock are read/written by all.
- T *WorkItems[MaxStaticSize];
+ std::unique_ptr<T> WorkItems[MaxStaticSize];
ICE_CACHELINE_BOUNDARY;
/// Lock guards access to WorkItems, Front, Back, and IsEnded.
GlobalLockType Lock;
@@ -131,13 +133,13 @@ private:
/// The lock must be held when the following methods are called.
bool empty() const { return Front == Back; }
size_t size() const { return Back - Front; }
- void push(T *Item) {
- WorkItems[Back++ & MaxStaticSizeMask] = Item;
+ void push(std::unique_ptr<T> Item) {
+ WorkItems[Back++ & MaxStaticSizeMask] = std::move(Item);
assert(size() <= MaxStaticSize);
}
- T *pop() {
+ std::unique_ptr<T> pop() {
assert(!empty());
- return WorkItems[Front++ & MaxStaticSizeMask];
+ return std::move(WorkItems[Front++ & MaxStaticSizeMask]);
}
};
@@ -174,11 +176,11 @@ public:
/// Constructor for a WI_Nop work item.
explicit EmitterWorkItem(uint32_t Seq);
/// Constructor for a WI_GlobalInits work item.
- EmitterWorkItem(uint32_t Seq, VariableDeclarationList *D);
+ EmitterWorkItem(uint32_t Seq, std::unique_ptr<VariableDeclarationList> D);
/// Constructor for a WI_Asm work item.
- EmitterWorkItem(uint32_t Seq, Assembler *A);
+ EmitterWorkItem(uint32_t Seq, std::unique_ptr<Assembler> A);
/// Constructor for a WI_Cfg work item.
- EmitterWorkItem(uint32_t Seq, Cfg *F);
+ EmitterWorkItem(uint32_t Seq, std::unique_ptr<Cfg> F);
uint32_t getSequenceNumber() const { return Sequence; }
ItemKind getKind() const { return Kind; }
void setGlobalInits(std::unique_ptr<VariableDeclarationList> GloblInits);
« no previous file with comments | « src/IceGlobalContext.cpp ('k') | src/IceThreading.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698