VirtualBox

Changeset 2296 in kBuild for trunk/src/kash/shthread.c


Ignore:
Timestamp:
Mar 1, 2009 1:54:30 AM (16 years ago)
Author:
bird
Message:

kash: avoid file steams in the trace code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kash/shthread.c

    r2243 r2296  
    2727#include "shthread.h"
    2828#include "shinstance.h"
     29#include <assert.h>
    2930
    30 #if defined(_MSC_VER) || defined(__EMX__)
    31 # include <process.h>
     31#if K_OS == K_OS_WINDOWS
     32# include <Windows.h>
     33#elif K_OS == K_OS_OS2
     34# include <InnoTekLIBC/FastInfoBlocks.h>
     35# include <InnoTekLIBC/thread.h>
    3236#else
    3337# include <pthread.h>
     
    3539
    3640
     41/*******************************************************************************
     42*   Global Variables                                                           *
     43*******************************************************************************/
     44#if K_OS == K_OS_WINDOWS
     45static DWORD sh_tls = TLS_OUT_OF_INDEXES;
     46#elif K_OS == K_OS_OS2
     47static int sh_tls = -1;
     48#else
     49static int sh_tls_inited = 0;
     50static int sh_tls;
     51#endif
     52
     53
     54/**
     55 * Stores the shell instance pointer in a TLS entry.
     56 *
     57 * This will allocate the TLS entry on the first call. We assume
     58 * there will no be races at that time.
     59 *
     60 * @param   psh     The shell instance.
     61 */
    3762void shthread_set_shell(struct shinstance *psh)
    3863{
     64#if K_OS == K_OS_WINDOWS
     65    if (sh_tls == TLS_OUT_OF_INDEXES)
     66    {
     67        sh_tls = TlsAlloc();
     68        assert(sh_tls != TLS_OUT_OF_INDEXES);
     69    }
     70    if (!TlsSetValue(sh_tls, psh))
     71        assert(0);
    3972
     73#elif K_OS == K_OS_OS2
     74    if (sh_tls == -1)
     75    {
     76        sh_tls = __libc_TLSAlloc();
     77        assert(sh_tls != -1);
     78    }
     79    if (__libc_TLSSet(sh_tls, psh) == -1)
     80        assert(0);
     81#else
     82    if (!sh_tls_inited)
     83    {
     84        if (pthread_key_create(&sh_tls, NULL) != 0)
     85            assert(0);
     86        sh_tls_inited = 1;
     87    }
     88    if (pthread_setspecific(sh_tls, psh) != 0)
     89        assert(0);
     90#endif
    4091}
    4192
     93/**
     94 * Get the shell instance pointer from TLS.
     95 *
     96 * @returns The shell instance.
     97 */
    4298struct shinstance *shthread_get_shell(void)
    4399{
    44     shinstance *psh = NULL;
     100    shinstance *psh;
     101#if K_OS == K_OS_WINDOWS
     102    psh = (shinstance *)TlsGetValue(sh_tls);
     103#elif K_OS == K_OS_OS2
     104    psh = (shinstance *)__libc_TLSGet(iTls)
     105#else
     106    psh = (shinstance *)pthread_getspecific(sh_tls);
     107#endif
    45108    return psh;
    46109}
    47110
    48 
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette