thread2-r0drv-haiku.c revision 2b3dc93fedb4e72ac5b3cbaa89a9fc2f559be550
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/* $Id$ */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/** @file
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * IPRT - Threads (Part 2), Ring-0 Driver, Haiku.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/*
34ee2570b5979d1e4ac39b4da8e453a9c99600a6vboxsync * Copyright (C) 2012 Oracle Corporation
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync *
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * available from http://www.virtualbox.org. This file is free software;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * you can redistribute it and/or modify it under the terms of the GNU
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * General Public License (GPL) as published by the Free Software
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync *
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * The contents of this file may alternatively be used under the terms
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync * of the Common Development and Distribution License Version 1.0
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync * VirtualBox OSE distribution, in which case the provisions of the
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync * CDDL are applicable instead of those of the GPL.
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync *
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync * You may elect to license modified versions of this file under the
1ce069685b24d243eb0464f46d4c56b250c64445vboxsync * terms and conditions of either the GPL or the CDDL or both.
a55af63ead2dcca370bfc0dfe49771d9dcc61b93vboxsync */
e0778e583cb4a0bdc9bcc48f5957e00a01108388vboxsync
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync
a55af63ead2dcca370bfc0dfe49771d9dcc61b93vboxsync/*******************************************************************************
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync* Header Files *
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync*******************************************************************************/
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync#include "the-haiku-kernel.h"
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync#include "internal/iprt.h"
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync#include <iprt/thread.h>
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync#include <iprt/asm-amd64-x86.h>
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync#endif
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync#include <iprt/assert.h>
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync#include <iprt/err.h>
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync#include "internal/thread.h"
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsyncint rtThreadNativeInit(void)
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync{
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync /* No TLS in Ring-0. :-/ */
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync return VINF_SUCCESS;
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync}
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync
23777a84b3e56937722404214b6064a797daf7b6vboxsync
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncRTDECL(RTTHREAD) RTThreadSelf(void)
229a63857c5fd2e441a62206eacce4156d0b2a26vboxsync{
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync return rtThreadGetByNative((RTNATIVETHREAD)find_thread(NULL));
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync}
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncint rtThreadNativeSetPriority(PRTTHREADINT pThread, RTTHREADTYPE enmType)
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync{
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync int32 iPriority;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync status_t status;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync /*
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * Convert the priority type to native priorities.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * (This is quite naive but should be ok.)
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync switch (enmType)
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync {
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsync case RTTHREADTYPE_INFREQUENT_POLLER: iPriority = B_LOWEST_ACTIVE_PRIORITY; break;
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsync case RTTHREADTYPE_EMULATION: iPriority = B_LOW_PRIORITY; break;
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsync case RTTHREADTYPE_DEFAULT: iPriority = B_NORMAL_PRIORITY; break;
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsync case RTTHREADTYPE_MSG_PUMP: iPriority = B_DISPLAY_PRIORITY; break;
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsync case RTTHREADTYPE_IO: iPriority = B_URGENT_DISPLAY_PRIORITY; break;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync case RTTHREADTYPE_TIMER: iPriority = B_REAL_TIME_DISPLAY_PRIORITY; break;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync default:
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync AssertMsgFailed(("enmType=%d\n", enmType));
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync return VERR_INVALID_PARAMETER;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync }
a2d9f81753c129b5e3bbe3769627dcd25a3724bdvboxsync
a2d9f81753c129b5e3bbe3769627dcd25a3724bdvboxsync status = set_thread_priority((thread_id)pThread->Core.Key, iPriority);
a2d9f81753c129b5e3bbe3769627dcd25a3724bdvboxsync
a2d9f81753c129b5e3bbe3769627dcd25a3724bdvboxsync return RTErrConvertFromHaikuKernReturn(status);
a2d9f81753c129b5e3bbe3769627dcd25a3724bdvboxsync}
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync
23777a84b3e56937722404214b6064a797daf7b6vboxsync
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncint rtThreadNativeAdopt(PRTTHREADINT pThread)
229a63857c5fd2e441a62206eacce4156d0b2a26vboxsync{
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync return VERR_NOT_IMPLEMENTED;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync}
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsync
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncvoid rtThreadNativeDestroy(PRTTHREADINT pThread)
a2d9f81753c129b5e3bbe3769627dcd25a3724bdvboxsync{
23777a84b3e56937722404214b6064a797daf7b6vboxsync NOREF(pThread);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync}
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync/**
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * Native kernel thread wrapper function.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync *
23777a84b3e56937722404214b6064a797daf7b6vboxsync * This will forward to rtThreadMain and do termination upon return.
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync *
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync * @param pvArg Pointer to the argument package.
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync * @param Ignored Wait result, which we ignore.
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync */
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsyncstatic status_t rtThreadNativeMain(void *pvArg)
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync{
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync const thread_id Self = find_thread(NULL);
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync PRTTHREADINT pThread = (PRTTHREADINT)pvArg;
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync int rc = rtThreadMain(pThread, (RTNATIVETHREAD)Self, &pThread->szName[0]);
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync if (rc < 0)
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync return RTErrConvertFromHaikuKernReturn(rc);
23777a84b3e56937722404214b6064a797daf7b6vboxsync return rc;
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync}
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsyncint rtThreadNativeCreate(PRTTHREADINT pThreadInt, PRTNATIVETHREAD pNativeThread)
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync{
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync thread_id NativeThread;
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync RT_ASSERT_PREEMPTIBLE();
23777a84b3e56937722404214b6064a797daf7b6vboxsync
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync NativeThread = spawn_kernel_thread(rtThreadNativeMain, pThreadInt->szName, B_NORMAL_PRIORITY, pThreadInt);
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync if (NativeThread >= B_OK)
7bf07b1592dfaab1a4fb6d497fd0ff1302fb7585vboxsync {
4b9a9888c020ed3508c8ac3a5b47842d6aa3f8d2vboxsync resume_thread(NativeThread);
7c1f498692cd2393f8ba68cb62be482495106f93vboxsync *pNativeThread = (RTNATIVETHREAD)NativeThread;
4b9a9888c020ed3508c8ac3a5b47842d6aa3f8d2vboxsync return VINF_SUCCESS;
7c1f498692cd2393f8ba68cb62be482495106f93vboxsync }
4b9a9888c020ed3508c8ac3a5b47842d6aa3f8d2vboxsync return RTErrConvertFromHaikuKernReturn(NativeThread);
4715f6e2473402353acb43c06a8986f957758259vboxsync}
c503384be18fd215490512125ce789bc2a71ad97vboxsync