Logo Search packages:      
Sourcecode: icu version File versions  Download package

U_STABLE void U_EXPORT2 u_setAtomicIncDecFunctions ( const void *  context,
UMtxAtomicFn inc,
UMtxAtomicFn dec,
UErrorCode status 
)

Set the functions that ICU will use for atomic increment and decrement of int32_t values. Use of this function is optional; by default (without this function), ICU will use its own internal implementation of atomic increment/decrement. This function can only be used when ICU is in an initial, unused state, before u_init() has been called.

Parameters:
context This pointer value will be saved, and then (later) passed as a parameter to the increment and decrement functions each time they are called. This function can only be called
inc Pointer to a function to do an atomic increment operation. Must be non-null.
dec Pointer to a function to do an atomic decrement operation. Must be non-null.
status Receives error values. ICU 2.8

Definition at line 557 of file umutex.c.

References NULL, U_FAILURE, U_ILLEGAL_ARGUMENT_ERROR, and U_INVALID_STATE_ERROR.

                                                    {
    if (U_FAILURE(*status)) {
        return;
    }
    /* Can not set a mutex function to a NULL value  */
    if (ip==NULL || dp==NULL) {
        *status = U_ILLEGAL_ARGUMENT_ERROR;
        return;
    }
    /* If ICU is not in an initial state, disallow this operation. */
    if (cmemory_inUse()) {
        *status = U_INVALID_STATE_ERROR;
        return;
    }

    pIncFn = ip;
    pDecFn = dp;
    gIncDecContext = context;

#if !U_RELEASE
    {
        int32_t   testInt = 0;
        U_ASSERT(umtx_atomic_inc(&testInt) == 1);     /* Sanity Check.    Do the functions work at all? */
        U_ASSERT(testInt == 1);
        U_ASSERT(umtx_atomic_dec(&testInt) == 0);
        U_ASSERT(testInt == 0);
    }
#endif
}


Generated by  Doxygen 1.6.0   Back to index