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

void * TriStateSingleton::getInstance ( InstantiatorFn *  instantiator,
const void *  context,
void *&  duplicate,
UErrorCode errorCode 
)

Returns the singleton instance, or NULL if it could not be created. Calls the instantiator with the context if the instance has not been created yet. In a race condition, the duplicate may not be NULL. The caller must delete the duplicate. The caller need not initialize the duplicate before the call. The singleton creation is only attempted once. If it fails, the singleton will then always return NULL.

Definition at line 42 of file mutex.cpp.

References NULL, U_FAILURE, and U_SUCCESS.

                                                            {
    duplicate=NULL;
    if(U_FAILURE(errorCode)) {
        return NULL;
    }
    int8_t haveInstance;
    UMTX_CHECK(NULL, fHaveInstance, haveInstance);
    if(haveInstance>0) {
        return fInstance;  // instance was created
    } else if(haveInstance<0) {
        errorCode=fErrorCode;  // instance creation failed
        return NULL;
    } else /* haveInstance==0 */ {
        void *instance=instantiator(context, errorCode);
        Mutex mutex;
        if(fHaveInstance==0) {
            if(U_SUCCESS(errorCode)) {
                fInstance=instance;
                instance=NULL;
                fHaveInstance=1;
            } else {
                fErrorCode=errorCode;
                fHaveInstance=-1;
            }
        } else {
            errorCode=fErrorCode;
        }
        duplicate=instance;
        return fInstance;
    }
}


Generated by  Doxygen 1.6.0   Back to index