summaryrefslogtreecommitdiff
path: root/parallel-libs/streamexecutor/lib/Stream.cpp
blob: fe135b4d0af6acd71265520f9da4fbc7f79e041a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//===-- 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) noexcept
    : 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) noexcept {
  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