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

Unified Diff: src/IceDefs.h

Issue 1838753002: Subzero: Remove IceString. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Code review changes 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/IceConverter.cpp ('k') | src/IceELFObjectWriter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/IceDefs.h
diff --git a/src/IceDefs.h b/src/IceDefs.h
index 5893ef43d8408fe6f4b79bdf9707d39ba20b197b..2055990c593087329086fb12175c3f12f7df5b9d 100644
--- a/src/IceDefs.h
+++ b/src/IceDefs.h
@@ -119,7 +119,6 @@ static std::unique_ptr<T> makeUnique(Args &&... TheArgs) {
#define ENABLE_MAKE_UNIQUE friend struct ::Ice::Internal::MakeUniqueEnabler
-using IceString = std::string;
using InstList = llvm::ilist<Inst>;
// Ideally PhiList would be llvm::ilist<InstPhi>, and similar for AssignList,
// but this runs into issues with SFINAE.
@@ -357,6 +356,32 @@ using Fdstream = llvm::raw_fd_ostream;
using GlobalLockType = std::mutex;
+/// LockedPtr is an RAII wrapper that allows automatically locked access to a
+/// given pointer, automatically unlocking it when when the LockedPtr goes out
+/// of scope.
+template <typename T> class LockedPtr {
+ LockedPtr() = delete;
+ LockedPtr(const LockedPtr &) = delete;
+ LockedPtr &operator=(const LockedPtr &) = delete;
+
+public:
+ LockedPtr(T *Value, GlobalLockType *Lock) : Value(Value), Lock(Lock) {
+ Lock->lock();
+ }
+ LockedPtr(LockedPtr &&Other) : Value(Other.Value), Lock(Other.Lock) {
+ Other.Value = nullptr;
+ Other.Lock = nullptr;
+ }
+ ~LockedPtr() { Lock->unlock(); }
+ T *operator->() const { return Value; }
+ T &operator*() const { return *Value; }
+ T *get() { return Value; }
+
+private:
+ T *Value;
+ GlobalLockType *Lock;
+};
+
enum ErrorCodes { EC_None = 0, EC_Args, EC_Bitcode, EC_Translation };
/// Wrapper around std::error_code for allowing multiple errors to be folded
« no previous file with comments | « src/IceConverter.cpp ('k') | src/IceELFObjectWriter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698