| // Copyright 2019 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "msd_img_semaphore.h" |
| |
| std::unique_ptr<MsdImgSemaphore> |
| MsdImgSemaphore::Import(uint32_t handle) |
| { |
| auto platform_semaphore = magma::PlatformSemaphore::Import(handle); |
| if (!platform_semaphore) |
| return DRETP(nullptr, "MsdImgSemaphore::Create: Could not create platform semaphore from token"); |
| |
| return std::make_unique<MsdImgSemaphore>(std::move(platform_semaphore)); |
| } |
| |
| std::unique_ptr<MsdImgSemaphore> |
| MsdImgSemaphore::Create() |
| { |
| auto platform_semaphore = magma::PlatformSemaphore::Create(); |
| if (!platform_semaphore) |
| return DRETP(nullptr, "MsdImgSemaphore::Create: Could not create platform semaphore"); |
| |
| return std::make_unique<MsdImgSemaphore>(std::move(platform_semaphore)); |
| } |
| |
| MsdImgSemaphore::MsdImgSemaphore(std::unique_ptr<magma::PlatformSemaphore> platform_semaphore) |
| : platform_semaphore_(std::move(platform_semaphore)) |
| { |
| } |
| |
| MsdImgSemaphore::~MsdImgSemaphore() = default; |
| |
| ////////////////////////////////////////////////////////////////////////////// |
| |
| magma_status_t |
| msd_semaphore_import(uint32_t handle, msd_semaphore_t** semaphore_out) |
| { |
| auto semaphore = MsdImgSemaphore::Import(handle); |
| if (!semaphore) |
| { |
| return DRET(MAGMA_STATUS_INVALID_ARGS); |
| } |
| *semaphore_out = new MsdImgAbiSemaphore(std::move(semaphore)); |
| return MAGMA_STATUS_OK; |
| } |
| |
| void |
| msd_semaphore_release(msd_semaphore_t* semaphore) |
| { |
| delete MsdImgAbiSemaphore::cast(semaphore); |
| } |