// vi:set ft=cpp: -*- Mode: C++ -*-
/*
 * Copyright (C) 2015, 2020-2021 Kernkonzept GmbH.
 * Author(s): Sarah Hoffmann <sarah.hoffmann@kernkonzept.com>
 *
 * This file is distributed under the terms of the GNU General Public
 * License, version 2.  Please see the COPYING-GPL-2 file for details.
 */
#pragma once

#include <thread>
#include <pthread-l4.h>

namespace std { namespace L4 {

/**
 * Return the L4 thread capability for a given std::thread.
 *
 * If the std::thread is not joinable, the invalid capability (#L4_INVALID_CAP)
 * is returned.
 */
inline ::L4::Cap< ::L4::Thread> thread_cap(std::thread &t)
{
  if (t.joinable())
    return Pthread::L4::cap(t.native_handle());
  return ::L4::Cap< ::L4::Thread>();
}

/// Return a pointer to the UTCB of this thread.
inline l4_utcb_t * thread_utcb(std::thread &t)
{ return Pthread::L4::utcb(t.native_handle()); }

}} // namespace L4, namespace std
