package com.gh.gamecenter.core.utils

open class SingletonHolder<out T>(creator: () -> T) {
    private var creator: (() -> T)? = creator

    @Volatile
    private var instance: T? = null

    fun getInstance(): T {
        val obj = instance
        if (obj != null) {
            return obj
        }
        return synchronized(this) {
            val obj1 = instance
            if (obj1 != null) {
                obj1
            } else {
                val created = creator!!()
                instance = created
                creator = null
                created
            }
        }
    }
}
