Ejemplo n.º 1
0
STATUS
CS_find_server_slot(i4 *slotno)
{
    STATUS              status = OK;
    CS_SERV_INFO        *serv_info;
    i4                  i;

    if (cs_servernum >= 0)
    {
        *slotno = cs_servernum;
        return(OK);
    }

    CS_getspin(&Cs_sm_cb->css_spinlock);

    serv_info = Cs_sm_cb->css_servinfo;

    /* find a free slot */
    status = FAIL;
    for (i = 0; i < Cs_sm_cb->css_numservers; i++)
    {
        if (!serv_info[i].csi_in_use)
        {
            cs_servernum = *slotno = i;
            Cs_svinfo = &serv_info[i];
            MEfill(sizeof (CS_SERV_INFO), '\0', (char *)Cs_svinfo);
            Cs_svinfo->csi_in_use = TRUE;
            Cs_svinfo->csi_id_number = i;
            /* Set this so we don't get any wakeup signals until cleared */
            CS_TAS(&Cs_svinfo->csi_wakeme);
            i_EXsetothersig(SIGUSR2, SIG_IGN);
            Cs_svinfo->csi_pid = getpid();
            Cs_svinfo->csi_signal_pid = Cs_svinfo->csi_pid;
            CS_SPININIT(&Cs_svinfo->csi_spinlock);

            status = OK;
            break;
        }
    }

    CS_relspin(&Cs_sm_cb->css_spinlock);
    return(status);
}
Ejemplo n.º 2
0
STATUS
FPdmath(int op, double *x, double *y, double *result)
{
    double	internal_result;
    STATUS	status;
    TYPESIG	fpmathsig();
    jmp_buf	*fpmathjmp_ptr = NULL;

    if (!FPdfinite(x) || !FPdfinite(y))
    {
	status = FP_NOT_FINITE_ARGUMENT;
    }
    else if (op == FDIV && *y == 0.0)
    {
	status = FP_DIVIDE_BY_ZERO;
    }
    else
    {
	status = FAIL;

# ifndef DESKTOP

# ifdef OS_THREADS_USED
        if ( FPfpmathkey == 0 )
        {
            ME_tls_createkey( &FPfpmathkey, &status );
            ME_tls_set( FPfpmathkey, NULL, &status );
        }
        if ( FPfpmathkey == 0 )
        {
            /* not linked with threading libraries */
            FPfpmathkey = -1;
        }
        if ( FPfpmathkey == -1 )
        {
            fpmathjmp_ptr = &fpmathjmp;
        }
        else
        {
            ME_tls_get( FPfpmathkey, (PTR *)&fpmathjmp_ptr, &status );
            if ( fpmathjmp_ptr == NULL )
            {
                fpmathjmp_ptr = (jmp_buf *) MEreqmem( 0, sizeof(jmp_buf), 
						      TRUE, NULL );
                ME_tls_set( FPfpmathkey, (PTR)fpmathjmp_ptr, &status );
            }
	}
# else /* OS_THREADS_USED */
        fpmathjmp_ptr = &fpmathjmp;
# endif /* OS_THREADS_USED */

        if (!setjmp(*fpmathjmp_ptr))
	{
	    i_EXsetothersig(SIGFPE, fpmathsig);

	    errno = NOERR;

	    switch(op)
	    {
	        case FADD: internal_result = *x + *y; break;
		case FSUB: internal_result = *x - *y; break;
		case FMUL: internal_result = *x * *y; break;
		case FDIV: internal_result = *x / *y; break;
	    }

	    /* Check to make sure the result is a finite number */
	    if (errno == NOERR && FPdfinite(&internal_result))
	    {
		*result = internal_result;
		status = OK;
	    }
	}

	if (status != OK)
	    status = (internal_result == 0.0) ? FP_UNDERFLOW : FP_OVERFLOW;

	i_EXrestoreorigsig(SIGFPE);
# else /* DESKTOP */
__try
{
	    switch(op)
	    {
	        case FADD: internal_result = *x + *y; break;
		case FSUB: internal_result = *x - *y; break;
		case FMUL: internal_result = *x * *y; break;
		case FDIV: internal_result = *x / *y; break;
	    }

	    /* Check to make sure the result is a finite number */
	    if (FPdfinite(&internal_result))
	    {
		*result = internal_result;
		status = OK;
	    }
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
        switch (GetExceptionCode())
        {
                case EXCEPTION_FLT_OVERFLOW:
                        status = FP_OVERFLOW;
			break;
                case EXCEPTION_FLT_UNDERFLOW:
                        status = FP_UNDERFLOW;
			break;
                default:
                        status = FP_OVERFLOW;
			break;
        }
}
# endif /* DESKTOP */
    }

    return(status);
}