blob: fe9beefe151c372c8bae2243938ea9f030c5978f [file] [log] [blame]
// 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.
#ifndef MSD_IMG_SEMAPHORE_H
#define MSD_IMG_SEMAPHORE_H
#include "magma_util/macros.h"
#include "msd.h"
#include "platform_semaphore.h"
class MsdImgSemaphore
{
public:
static std::unique_ptr<MsdImgSemaphore> Import(uint32_t handle);
static std::unique_ptr<MsdImgSemaphore> Create();
MsdImgSemaphore(std::unique_ptr<magma::PlatformSemaphore> platform_semaphore);
~MsdImgSemaphore();
magma::PlatformSemaphore* platform_semaphore()
{
DASSERT(platform_semaphore_);
return platform_semaphore_.get();
}
private:
std::unique_ptr<magma::PlatformSemaphore> platform_semaphore_;
};
class MsdImgAbiSemaphore : public msd_semaphore_t
{
public:
MsdImgAbiSemaphore(std::shared_ptr<MsdImgSemaphore> ptr) : base_ptr_(std::move(ptr)) { magic_ = kMagic; }
static MsdImgAbiSemaphore* cast(msd_semaphore_t* sema)
{
DASSERT(sema);
DASSERT(sema->magic_ == kMagic);
return static_cast<MsdImgAbiSemaphore*>(sema);
}
std::shared_ptr<MsdImgSemaphore> base_ptr() { return base_ptr_; }
private:
std::shared_ptr<MsdImgSemaphore> base_ptr_;
static const uint32_t kMagic = 'sema';
};
#endif // MSD_IMG_SEMAPHORE_H