Files
llvm-project/parallel-libs/streamexecutor/lib/Stream.cpp
Jason Henline 18ea094df1 [SE] Remove Platform*Handle classes
Summary:
As pointed out by jprice, these classes don't serve a purpose. Instead,
we stay consistent with the way memory is managed and let the Stream and
Kernel classes directly hold opaque handles to device Stream and Kernel
instances, respectively.

Reviewers: jprice, jlebar

Subscribers: parallel_libs-commits

Differential Revision: https://reviews.llvm.org/D24213

llvm-svn: 280719
2016-09-06 17:07:22 +00:00

55 lines
1.8 KiB
C++

//===-- Stream.cpp - General stream implementation ------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// This file contains the implementation details for a general stream object.
///
//===----------------------------------------------------------------------===//
#include <cassert>
#include "streamexecutor/Stream.h"
namespace streamexecutor {
Stream::Stream(PlatformDevice *D, const void *PlatformStreamHandle)
: PDevice(D), PlatformStreamHandle(PlatformStreamHandle),
ErrorMessageMutex(llvm::make_unique<llvm::sys::RWMutex>()) {
assert(D != nullptr &&
"cannot construct a stream object with a null platform device");
assert(PlatformStreamHandle != nullptr &&
"cannot construct a stream object with a null platform stream handle");
}
Stream::Stream(Stream &&Other)
: PDevice(Other.PDevice), PlatformStreamHandle(Other.PlatformStreamHandle),
ErrorMessageMutex(std::move(Other.ErrorMessageMutex)),
ErrorMessage(std::move(Other.ErrorMessage)) {
Other.PDevice = nullptr;
Other.PlatformStreamHandle = nullptr;
}
Stream &Stream::operator=(Stream &&Other) {
PDevice = Other.PDevice;
PlatformStreamHandle = Other.PlatformStreamHandle;
ErrorMessageMutex = std::move(Other.ErrorMessageMutex);
ErrorMessage = std::move(Other.ErrorMessage);
Other.PDevice = nullptr;
Other.PlatformStreamHandle = nullptr;
return *this;
}
Stream::~Stream() {
if (PlatformStreamHandle)
// TODO(jhen): Handle error condition here.
consumeError(PDevice->destroyStream(PlatformStreamHandle));
}
} // namespace streamexecutor