static void clds_hazard_pointers_thread_helper_thread_notification()

in src/clds_hazard_pointers_thread_helper.c [29:77]


static void clds_hazard_pointers_thread_helper_thread_notification(void* context, THREAD_NOTIFICATIONS_LACKEY_DLL_REASON reason)
{
    if (context == NULL)
    {
        /* Codes_SRS_CLDS_HAZARD_POINTERS_THREAD_HELPER_01_005: [ If context is NULL, clds_hazard_pointers_thread_helper_thread_notification shall terminate the process. ]*/
        LogCriticalAndTerminate("Unexpected reason: void* context=%p, THREAD_NOTIFICATIONS_LACKEY_DLL_REASON reason=%" PRI_MU_ENUM "",
            context, MU_ENUM_VALUE(THREAD_NOTIFICATIONS_LACKEY_DLL_REASON, reason));
    }
    else
    {
        switch (reason)
        {
        default:
            /* Codes_SRS_CLDS_HAZARD_POINTERS_THREAD_HELPER_01_012: [ If reason is any other value, clds_hazard_pointers_thread_helper_thread_notification shall return. ]*/
            LogError("Unexpected reason: void* context=%p, THREAD_NOTIFICATIONS_LACKEY_DLL_REASON reason=%" PRI_MU_ENUM "",
                context, MU_ENUM_VALUE(THREAD_NOTIFICATIONS_LACKEY_DLL_REASON, reason));
            break;

        case THREAD_NOTIFICATIONS_LACKEY_DLL_REASON_THREAD_ATTACH:
            /* Codes_SRS_CLDS_HAZARD_POINTERS_THREAD_HELPER_01_006: [ If reason is THREAD_NOTIFICATIONS_LACKEY_DLL_REASON_THREAD_ATTACH, clds_hazard_pointers_thread_helper_thread_notification shall return. ]*/
            break;

        case THREAD_NOTIFICATIONS_LACKEY_DLL_REASON_THREAD_DETACH:
        {
            CLDS_HAZARD_POINTERS_THREAD_HELPER_HANDLE hazard_pointers_helper = context;

            /* Codes_SRS_CLDS_HAZARD_POINTERS_THREAD_HELPER_01_007: [ If reason is THREAD_NOTIFICATIONS_LACKEY_DLL_REASON_THREAD_DETACH, clds_hazard_pointers_thread_helper_thread_notification shall call TlsGetValue obtain the thread local value for the slot created in the clds_hazard_pointers_thread_create. ]*/
            CLDS_HAZARD_POINTERS_THREAD_HANDLE hp_thread_handle = TlsGetValue(hazard_pointers_helper->tls_slot);

            /* Codes_SRS_CLDS_HAZARD_POINTERS_THREAD_HELPER_01_009: [ If the thread local stored value is not NULL: ]*/
            if (hp_thread_handle != NULL)
            {
                /* Codes_SRS_CLDS_HAZARD_POINTERS_THREAD_HELPER_01_010: [ clds_hazard_pointers_thread_helper_thread_notification shall set the value in the slot to NULL by calling TlsSetValue. ]*/
                if (!TlsSetValue(hazard_pointers_helper->tls_slot, NULL))
                {
                    LogError("TlsSetValue(hazard_pointers_helper->tls_slot=%" PRIu32 ", NULL) failed", hazard_pointers_helper->tls_slot);
                }
                /* Codes_SRS_CLDS_HAZARD_POINTERS_THREAD_HELPER_01_011: [ clds_hazard_pointers_thread_helper_thread_notification shall call clds_hazard_pointers_unregister_thread with the argument being the obtained thread local value. ]*/
                clds_hazard_pointers_unregister_thread(hp_thread_handle);
            }
            else
            {
                /* Codes_SRS_CLDS_HAZARD_POINTERS_THREAD_HELPER_01_008: [ If the thread local stored value is NULL, clds_hazard_pointers_thread_helper_thread_notification shall return. ]*/
            }
            break;
        }
        }
    }
}