thread-os2.cpp revision bd85407c32a57a11e1412e7f628e9cf8ea970638
/* $Id$ */
/** @file
* innotek Portable Runtime - Threads, OS/2.
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License as published by the Free Software Foundation,
* in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
* distribution. VirtualBox OSE is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY of any kind.
*
* If you received this file as part of a commercial VirtualBox
* distribution, then only the terms of your commercial VirtualBox
* license agreement apply instead of the previous paragraph.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP RTLOGGROUP_THREAD
#define INCL_BASE
#include <os2.h>
#include <errno.h>
#include <process.h>
#include <stdlib.h>
#include <signal.h>
#include <InnoTekLIBC/FastInfoBlocks.h>
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** Pointer to thread local memory which points to the current thread. */
static PRTTHREADINT *g_ppCurThread;
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
static void rtThreadNativeMain(void *pvArgs);
int rtThreadNativeInit(void)
{
/*
* Allocate thread local memory.
*/
if (rc)
return VERR_NO_TLS_FOR_SELF;
return VINF_SUCCESS;
}
{
/*
* Block SIGALRM - required for timer-posix.cpp.
* This is done to limit harm done by OSes which doesn't do special SIGALRM scheduling.
* It will not help much if someone creates threads directly using pthread_create. :/
*/
*g_ppCurThread = pThread;
return VINF_SUCCESS;
}
/**
* Wrapper which unpacks the params and calls thread function.
*/
static void rtThreadNativeMain(void *pvArgs)
{
/*
* Block SIGALRM - required for timer-posix.cpp.
* This is done to limit harm done by OSes which doesn't do special SIGALRM scheduling.
* It will not help much if someone creates threads directly using pthread_create. :/
*/
/*
* Call common main.
*/
*g_ppCurThread = pThread;
#ifdef fibGetTidPid
#else
#endif
*g_ppCurThread = NULL;
_endthread();
}
{
/*
* Default stack size.
*/
/*
* Create the thread.
*/
if (iThreadId > 0)
{
#ifdef fibGetTidPid
#else
#endif
return VINF_SUCCESS;
}
return RTErrConvertFromErrno(errno);
}
{
if (pThread)
/** @todo import alien threads? */
return NULL;
}
{
#ifdef fibGetTidPid
return fibGetTidPid();
#else
return _gettid();
#endif
}
{
return VINF_SUCCESS;
}
RTDECL(bool) RTThreadYield(void)
{
DosSleep(0);
return fRc;
}
{
union
{
} u;
if (rc)
u.u64 = 1;
return u.u64;
}
{
union
{
} u;
if (!rc)
return VINF_SUCCESS;
return RTErrConvertFromOS2(rc);
}