Ejemplo n.º 1
0
void comm_service_init(void)
{
    int s;

    enable_progress_thread = get_env_flag(ENV_PROGRESS_THREAD,
                                          DEFAULT_ENABLE_PROGRESS_THREAD);

    /* don't spawn a progress thread here if the conduit is ibv or vapi, since
     * GASNet's receive thread (GASNET_RCV_THREAD) will be enabled.
     */
#if !defined(GASNET_CONDUIT_IBV) && !defined(GASNET_CONDUIT_VAPI)
    if (enable_progress_thread == 0)
#endif
        return;

    progress_thread_interval = get_env_size(ENV_PROGRESS_THREAD_INTERVAL,
                                            DEFAULT_PROGRESS_THREAD_INTERVAL);

    delayspec.tv_sec = (time_t) 0;
    delayspec.tv_nsec = progress_thread_interval;

    s = pthread_create(&thr, NULL, start_service, (void *) 0);
    if (s != 0) {
        LIBCAF_TRACE(LIBCAF_LOG_FATAL,
                     "service thread creation failed (%s)", strerror(s));
        /* NOT REACHED */
    }

    LIBCAF_TRACE(LIBCAF_LOG_SERVICE, "started progress thread");
}
Ejemplo n.º 2
0
int get_env_flag(const char *var_name, int default_val)
{
    char *val;
    if (var_name == NULL)
        return 0;

    val = getenv(var_name);

    if (val == NULL)
        return default_val;

    if (strcasecmp(val, "1") == 0 ||
        strcasecmp(val, "y") == 0 ||
        strcasecmp(val, "on") == 0 || strcasecmp(val, "yes") == 0) {
        return 1;
    } else if (strcasecmp(val, "0") == 0 ||
               strcasecmp(val, "n") == 0 ||
               strcasecmp(val, "off") == 0 || strcasecmp(val, "no") == 0) {
        return 0;
    } else {
        LIBCAF_TRACE(LIBCAF_LOG_NOTICE,
                     "Bad val for %s: %s", var_name, val);
        return default_val;
    }
}
Ejemplo n.º 3
0
size_t get_env_size_with_unit(const char *var_name, size_t default_size)
{
    char *val;
    size_t ret_val;
    char *u;

    if (var_name == NULL)
        return default_size;

    val = getenv(var_name);

    if (val == NULL)
        return default_size;

    u = alloca(strlen(val));

    ret_val = 0;
    sscanf(val, "%ld", (long *)&ret_val);
    sprintf(u, "%ld", (long) ret_val);
    if (strlen(u) != strlen(val)) {
        sscanf(val, "%ld%s", (unsigned long *)&ret_val, u);
        if (strlen(u) != 0 && strlen(u) != 1) {
            LIBCAF_TRACE(LIBCAF_LOG_NOTICE,
                    "Bad val for %s: %s", var_name, val);
            ret_val = default_size;
        } else if (strlen(u) != 0) {

            if (strncasecmp(u, "k", strlen(u)) == 0) {
                ret_val *= 1024L;
            } else if (strncasecmp(u, "m", strlen(u)) == 0) {
                ret_val *= 1024L*1024L;
            } else if (strncasecmp(u, "g", strlen(u)) == 0) {
                ret_val *= 1024L*1024L*1024L;
            } else {
                LIBCAF_TRACE(LIBCAF_LOG_NOTICE,
                        "Bad val for %s: %s", var_name, val);
                ret_val = default_size;
            }
        }

    }

    if (ret_val == 0)
        ret_val = default_size;

    return ret_val;
}
Ejemplo n.º 4
0
void comm_service_finalize(void)
{
    int s;

    /* don't spawn a progress thread here if the conduit is ibv or vapi, since
     * GASNet's receive thread (GASNET_RCV_THREAD) will be enabled.
     */
#if !defined(GASNET_CONDUIT_IBV) && !defined(GASNET_CONDUIT_VAPI)
    if (enable_progress_thread == 0)
#endif
        return;

    done = 1;

    s = pthread_join(thr, NULL);
    if (s != 0) {
        LIBCAF_TRACE(LIBCAF_LOG_FATAL,
                     "service thread termination failed (%s)",
                     strerror(s));
        /* NOT REACHED */
    }

    LIBCAF_TRACE(LIBCAF_LOG_SERVICE, "stopped progress thread");
}
Ejemplo n.º 5
0
static void show_trace_levels(void)
{
    char buf[BUF_SIZE];
    int i;
    strcpy(buf, "Enabled Messages: ");

    for (i = 0; i < NUM_TRACERS; i++) {
        if (tracers[i].state == ON) {
            strncat(buf, tracers[i].text, strlen(tracers[i].text));
            strncat(buf, " ", 1);
        }
    }

    LIBCAF_TRACE(LIBCAF_LOG_INIT, buf);
}
Ejemplo n.º 6
0
size_t get_env_size(const char *var_name, size_t default_size)
{
    char *p;
    char *val;

    if (var_name == NULL)
        return default_size;

    val = getenv(var_name);

    if (val == NULL)
        return default_size;

    double dummy = strtod(val, &p);

    if (*p != '\0') {
        LIBCAF_TRACE(LIBCAF_LOG_NOTICE,
                     "Bad val for %s: %s", var_name, val);
        return default_size;
    }

    return (size_t) atoll(val);
}