VirtualBox

Changeset 6556 in vbox


Ignore:
Timestamp:
Jan 29, 2008 3:03:40 AM (17 years ago)
Author:
vboxsync
Message:

r=bird: Some cleanup. hope it works

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3Lib.cpp

    r6538 r6556  
    7070static RTFILE g_File = NIL_RTFILE;
    7171#endif
    72 /**
     72/** User counter.
    7373 * A counter of the number of times the library has been initialised, for use with
    7474 * X.org drivers, where the library may be shared by multiple independant modules
    7575 * inside a single process space.
    7676 */
    77 static uint32_t g_cInits = 0;
     77static uint32_t volatile g_cInits = 0;
     78
    7879
    7980VBGLR3DECL(int) VbglR3Init(void)
    8081{
    8182    uint32_t cInits = ASMAtomicIncU32(&g_cInits);
    82 #ifdef VBOX_VBGLR3_XFREE86
    83     if (1 != cInits)
    84         return VINF_SUCCESS;
    85     if (-1 != g_File)
    86         return VERR_INTERNAL_ERROR;
    87 #else
     83#ifndef VBOX_VBGLR3_XFREE86
    8884    Assert(cInits > 0);
    89     if (1 > cInits)
    90     {
    91         /* This will not work when the library is shared inside a multi-threaded
    92            process.  Hopefully no-one will try that, as we can't use the threads
    93            APIs here. */
    94         if (NIL_RTFILE == g_File)
     85#endif
     86    if (cInits > 1)
     87    {
     88        /*
     89         * This will fail if two (or more) threads race each other calling VbglR3Init.
     90         * However it will work fine for single threaded or otherwise serialized
     91         * processed calling us more than once.
     92         */
     93#ifndef VBOX_VBGLR3_XFREE86
     94        if (g_File == NIL_RTFILE)
     95#else
     96        if (g_File == -1)
     97#endif
    9598            return VERR_INTERNAL_ERROR;
    9699        return VINF_SUCCESS;
    97100    }
    98     if (NIL_RTFILE != g_File)
     101#ifndef VBOX_VBGLR3_XFREE86
     102    if (g_File != NIL_RTFILE)
     103#else
     104    if (g_File != -1)
     105#endif
    99106        return VERR_INTERNAL_ERROR;
    100 #endif
    101107
    102108#if defined(RT_OS_OS2)
     
    153159#elif defined(VBOX_VBGLR3_XFREE86)
    154160    int File = open(VBOXGUEST_DEVICE_NAME, O_RDWR);
    155     if (-1 == File)
    156     {
    157         return VERR_UNRESOLVED_ERROR;
    158     }
     161    if (File == -1)
     162        return VERR_OPEN_FAILED;
    159163    g_File = File;
    160164
     
    179183        return;
    180184#ifndef VBOX_VBGLR3_XFREE86
    181     AssertReturnVoid(0 == cInits);
     185    AssertReturnVoid(!cInits);
    182186    RTFILE File = g_File;
    183187    g_File = NIL_RTFILE;
    184     AssertReturnVoid(NIL_RTFILE != File);
     188    AssertReturnVoid(File != NIL_RTFILE);
     189
    185190#else
    186191    int File = g_File;
    187192    g_File = -1;
    188     if (-1 == File)
     193    if (File == -1)
    189194        return;
    190195#endif
     196
    191197#if defined(RT_OS_OS2)
    192198    APIRET rc = DosClose(File);
    193199    AssertMsg(!rc, ("%ld\n", rc));
     200
    194201#elif defined(VBOX_VBGLR3_XFREE86)
    195     /* if (-1 == close(File))
    196     {
    197         int iErr = errno;
    198         AssertRC(RTErrConvertFromErrno(iErr));
    199     } */
    200     close(File);  /* iprt is not available here. */
     202    close(File);
    201203    File = -1;
     204
    202205#else
    203206    int rc = RTFileClose(File);
     
    240243    Hdr.pvDataR3 = pvData;
    241244
     245/** @todo test status code passing! */
    242246    int rc = ioctl((int)g_File, iFunction, &Hdr);
    243247    if (rc == -1)
     
    248252    return VINF_SUCCESS;
    249253
    250 #else
    251     /* Default implementation - PORTME: Do not use this without testings that error passing works! */
    252 # ifdef VBOX_VBGLR3_XFREE86
    253     int rc = ioctl(g_File, (int) iFunction, pvData);
     254#elif defined(VBOX_VBGLR3_XFREE86)
     255    /* PORTME - This is preferred over the RTFileIOCtl variant below, just be careful with the (int). */
     256/** @todo test status code passing! */
     257    int rc = ioctl(g_File, (int)iFunction, pvData);
    254258    if (rc == -1)
    255259    {
     
    258262    }
    259263    return VINF_SUCCESS;
    260 # else
     264
     265#else
     266    /* Default implementation - PORTME: Do not use this without testings that passing errors works! */
     267/** @todo test status code passing! */
    261268    int rc2 = VERR_INTERNAL_ERROR;
    262269    int rc = RTFileIoCtl(g_File, (int)iFunction, pvData, cbData, &rc2);
     
    264271        rc = rc2;
    265272    return rc;
    266 # endif
    267 #endif
    268 }
    269 
     273#endif
     274}
     275
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