Index: parallel-libs/trunk/streamexecutor/examples/Example.cpp =================================================================== --- parallel-libs/trunk/streamexecutor/examples/Example.cpp +++ parallel-libs/trunk/streamexecutor/examples/Example.cpp @@ -121,13 +121,13 @@ getOrDie(Device->allocateDeviceMemory(ArraySize)); // Run operations on a stream. - std::unique_ptr Stream = getOrDie(Device->createStream()); - Stream->thenCopyH2D(HostX, X) + se::Stream Stream = getOrDie(Device->createStream()); + Stream.thenCopyH2D(HostX, X) .thenCopyH2D(HostY, Y) .thenLaunch(ArraySize, 1, *Kernel, A, X, Y) .thenCopyD2H(X, HostX); // Wait for the stream to complete. - se::dieIfError(Stream->blockHostUntilDone()); + se::dieIfError(Stream.blockHostUntilDone()); // Process output data in HostX. std::vector ExpectedX = {4, 47, 90, 133}; Index: parallel-libs/trunk/streamexecutor/include/streamexecutor/Device.h =================================================================== --- parallel-libs/trunk/streamexecutor/include/streamexecutor/Device.h +++ parallel-libs/trunk/streamexecutor/include/streamexecutor/Device.h @@ -50,7 +50,8 @@ std::move(*MaybeKernelHandle)); } - Expected> createStream(); + /// Creates a stream object for this device. + Expected createStream(); /// Allocates an array of ElementCount entries of type T in device memory. template Index: parallel-libs/trunk/streamexecutor/include/streamexecutor/Stream.h =================================================================== --- parallel-libs/trunk/streamexecutor/include/streamexecutor/Stream.h +++ parallel-libs/trunk/streamexecutor/include/streamexecutor/Stream.h @@ -61,19 +61,22 @@ public: explicit Stream(std::unique_ptr PStream); + Stream(Stream &&Other) = default; + Stream &operator=(Stream &&Other) = default; + ~Stream(); /// Returns whether any error has occurred while entraining work on this /// stream. bool isOK() const { - llvm::sys::ScopedReader ReaderLock(ErrorMessageMutex); + llvm::sys::ScopedReader ReaderLock(*ErrorMessageMutex); return !ErrorMessage; } /// Returns the status created by the first error that occurred while /// entraining work on this stream. Error getStatus() const { - llvm::sys::ScopedReader ReaderLock(ErrorMessageMutex); + llvm::sys::ScopedReader ReaderLock(*ErrorMessageMutex); if (ErrorMessage) return make_error(*ErrorMessage); else @@ -315,7 +318,7 @@ /// Does not overwrite the error if it is already set. void setError(Error &&E) { if (E) { - llvm::sys::ScopedWriter WriterLock(ErrorMessageMutex); + llvm::sys::ScopedWriter WriterLock(*ErrorMessageMutex); if (!ErrorMessage) ErrorMessage = consumeAndGetMessage(std::move(E)); } @@ -325,7 +328,7 @@ /// /// Does not overwrite the error if it is already set. void setError(llvm::Twine Message) { - llvm::sys::ScopedWriter WriterLock(ErrorMessageMutex); + llvm::sys::ScopedWriter WriterLock(*ErrorMessageMutex); if (!ErrorMessage) ErrorMessage = Message.str(); } @@ -337,9 +340,7 @@ std::unique_ptr ThePlatformStream; /// Mutex that guards the error state flags. - /// - /// Mutable so that it can be obtained via const reader lock. - mutable llvm::sys::RWMutex ErrorMessageMutex; + std::unique_ptr ErrorMessageMutex; /// First error message for an operation in this stream or empty if there have /// been no errors. Index: parallel-libs/trunk/streamexecutor/lib/Device.cpp =================================================================== --- parallel-libs/trunk/streamexecutor/lib/Device.cpp +++ parallel-libs/trunk/streamexecutor/lib/Device.cpp @@ -27,7 +27,7 @@ Device::~Device() = default; -Expected> Device::createStream() { +Expected Device::createStream() { Expected> MaybePlatformStream = PDevice->createStream(); if (!MaybePlatformStream) { @@ -35,7 +35,7 @@ } assert((*MaybePlatformStream)->getDevice() == PDevice && "an executor created a stream with a different stored executor"); - return llvm::make_unique(std::move(*MaybePlatformStream)); + return Stream(std::move(*MaybePlatformStream)); } } // namespace streamexecutor Index: parallel-libs/trunk/streamexecutor/lib/Stream.cpp =================================================================== --- parallel-libs/trunk/streamexecutor/lib/Stream.cpp +++ parallel-libs/trunk/streamexecutor/lib/Stream.cpp @@ -17,7 +17,8 @@ namespace streamexecutor { Stream::Stream(std::unique_ptr PStream) - : PDevice(PStream->getDevice()), ThePlatformStream(std::move(PStream)) {} + : PDevice(PStream->getDevice()), ThePlatformStream(std::move(PStream)), + ErrorMessageMutex(llvm::make_unique()) {} Stream::~Stream() = default;