| 366 | } |
| 367 | |
| 368 | Status Write(const void* data, int64_t nbytes) { |
| 369 | CHECK_CLOSED(); |
| 370 | if (nbytes == 0) { |
| 371 | return Status::OK(); |
| 372 | } |
| 373 | |
| 374 | if (buffer_size_ > 0) { |
| 375 | if (nbytes + buffer_position_ >= buffer_size_) { |
| 376 | // Reach end of buffer, write everything |
| 377 | RETURN_NOT_OK(Flush()); |
| 378 | RETURN_NOT_OK(context_->CopyHostToDevice(address_ + position_, data, nbytes)); |
| 379 | } else { |
| 380 | // Write bytes to buffer |
| 381 | std::memcpy(host_buffer_data_ + buffer_position_, data, nbytes); |
| 382 | buffer_position_ += nbytes; |
| 383 | } |
| 384 | } else { |
| 385 | // Unbuffered write |
| 386 | RETURN_NOT_OK(context_->CopyHostToDevice(address_ + position_, data, nbytes)); |
| 387 | } |
| 388 | position_ += nbytes; |
| 389 | return Status::OK(); |
| 390 | } |
| 391 | |
| 392 | Status WriteAt(int64_t position, const void* data, int64_t nbytes) { |
| 393 | std::lock_guard<std::mutex> guard(lock_); |
nothing calls this directly
no test coverage detected