~ubuntu-branches/ubuntu/oneiric/virtualbox-ose/oneiric

« back to all changes in this revision

Viewing changes to src/VBox/Runtime/generic/critsect-generic.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-01-30 23:27:25 UTC
  • mfrom: (0.3.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20110130232725-2ouajjd2ggdet0zd
Tags: 4.0.2-dfsg-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Add Apport hook.
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Drop *-source packages.
* Drop ubuntu-01-fix-build-gcc45.patch, fixed upstream.
* Drop ubuntu-02-as-needed.patch, added to the Debian package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: critsect-generic.cpp $ */
 
1
/* $Id: critsect-generic.cpp 33269 2010-10-20 15:42:28Z vboxsync $ */
2
2
/** @file
3
3
 * IPRT - Critical Section, Generic.
4
4
 */
51
51
RTDECL(int) RTCritSectInitEx(PRTCRITSECT pCritSect, uint32_t fFlags, RTLOCKVALCLASS hClass, uint32_t uSubClass,
52
52
                             const char *pszNameFmt, ...)
53
53
{
54
 
    AssertReturn(fFlags <= (RTCRITSECT_FLAGS_NO_NESTING | RTCRITSECT_FLAGS_NO_LOCK_VAL), VERR_INVALID_PARAMETER);
 
54
    AssertReturn(!(fFlags & ~(RTCRITSECT_FLAGS_NO_NESTING | RTCRITSECT_FLAGS_NO_LOCK_VAL | RTCRITSECT_FLAGS_BOOTSTRAP_HACK)),
 
55
                 VERR_INVALID_PARAMETER);
55
56
 
56
57
    /*
57
58
     * Initialize the structure and
64
65
    pCritSect->pValidatorRec        = NULL;
65
66
    int rc = VINF_SUCCESS;
66
67
#ifdef RTCRITSECT_STRICT
67
 
    if (!pszNameFmt)
68
 
    {
69
 
        static uint32_t volatile s_iCritSectAnon = 0;
70
 
        rc = RTLockValidatorRecExclCreate(&pCritSect->pValidatorRec, hClass, uSubClass, pCritSect,
71
 
                                          !(fFlags & RTCRITSECT_FLAGS_NO_LOCK_VAL),
72
 
                                          "RTCritSect-%u", ASMAtomicIncU32(&s_iCritSectAnon) - 1);
73
 
    }
74
 
    else
75
 
    {
76
 
        va_list va;
77
 
        va_start(va, pszNameFmt);
78
 
        rc = RTLockValidatorRecExclCreateV(&pCritSect->pValidatorRec, hClass, uSubClass, pCritSect,
79
 
                                           !(fFlags & RTCRITSECT_FLAGS_NO_LOCK_VAL), pszNameFmt, va);
80
 
        va_end(va);
 
68
    if (!(fFlags & RTCRITSECT_FLAGS_BOOTSTRAP_HACK))
 
69
    {
 
70
        if (!pszNameFmt)
 
71
        {
 
72
            static uint32_t volatile s_iCritSectAnon = 0;
 
73
            rc = RTLockValidatorRecExclCreate(&pCritSect->pValidatorRec, hClass, uSubClass, pCritSect,
 
74
                                              !(fFlags & RTCRITSECT_FLAGS_NO_LOCK_VAL),
 
75
                                              "RTCritSect-%u", ASMAtomicIncU32(&s_iCritSectAnon) - 1);
 
76
        }
 
77
        else
 
78
        {
 
79
            va_list va;
 
80
            va_start(va, pszNameFmt);
 
81
            rc = RTLockValidatorRecExclCreateV(&pCritSect->pValidatorRec, hClass, uSubClass, pCritSect,
 
82
                                               !(fFlags & RTCRITSECT_FLAGS_NO_LOCK_VAL), pszNameFmt, va);
 
83
            va_end(va);
 
84
        }
81
85
    }
82
86
#endif
83
87
    if (RT_SUCCESS(rc))
84
88
    {
85
 
        rc = RTSemEventCreate(&pCritSect->EventSem);
 
89
        rc = RTSemEventCreateEx(&pCritSect->EventSem,
 
90
                                fFlags & RTCRITSECT_FLAGS_BOOTSTRAP_HACK
 
91
                                ? RTSEMEVENT_FLAGS_NO_LOCK_VAL | RTSEMEVENT_FLAGS_BOOTSTRAP_HACK
 
92
                                : RTSEMEVENT_FLAGS_NO_LOCK_VAL,
 
93
                                NIL_RTLOCKVALCLASS,
 
94
                                NULL);
86
95
        if (RT_SUCCESS(rc))
87
96
            return VINF_SUCCESS;
88
97
        RTLockValidatorRecExclDestroy(&pCritSect->pValidatorRec);
186
195
        return VERR_SEM_DESTROYED;
187
196
 
188
197
#ifdef RTCRITSECT_STRICT
189
 
    RTTHREAD        hThreadSelf = RTThreadSelfAutoAdopt();
190
 
    int rc9 = RTLockValidatorRecExclCheckOrder(pCritSect->pValidatorRec, hThreadSelf, pSrcPos, RT_INDEFINITE_WAIT);
191
 
    if (RT_FAILURE(rc9))
192
 
        return rc9;
 
198
    RTTHREAD hThreadSelf = pCritSect->pValidatorRec
 
199
                         ? RTThreadSelfAutoAdopt()
 
200
                         : RTThreadSelf();
 
201
    int      rc9;
 
202
    if (pCritSect->pValidatorRec) /* (bootstap) */
 
203
    {
 
204
         rc9 = RTLockValidatorRecExclCheckOrder(pCritSect->pValidatorRec, hThreadSelf, pSrcPos, RT_INDEFINITE_WAIT);
 
205
         if (RT_FAILURE(rc9))
 
206
             return rc9;
 
207
    }
193
208
#endif
194
209
 
195
210
    /*