コード例 #1
0
ファイル: sci_stacksize.c プロジェクト: ZhanlinWang/scilab
/*--------------------------------------------------------------------------*/
static int setStacksizeMax(char *fname)
{
    /* we backup previous size */
    unsigned long backupSize = getCurrentStacksize();

    /* Bug 5495 on Windows 2000 -- WONT FIX GetLargestFreeMemoryRegion */
    /* it works on XP, Vista, S7ven */
    /* GetLargestFreeMemoryRegion() returns a superior size to real value */
    unsigned long maxmemfree = (GetLargestFreeMemoryRegion()) / sizeof(double);

    /* We have already max */
    if (maxmemfree <= backupSize)
    {
        LhsVar(1) = 0;
        C2F(putlhsvar) ();
        return 0;
    }

    /* we do a stacksize('min') */
    if (setStacksizeMin(fname) == 0)
    {
        unsigned long memmaxavailablebyscilab = get_max_memory_for_scilab_stack();
        unsigned long newMemSizeMax = maxmemfree;
        int errCode;

        if (memmaxavailablebyscilab < newMemSizeMax)
        {
            newMemSizeMax = memmaxavailablebyscilab;
        }

        if (newMemSizeMax < MIN_STACKSIZE)
        {
            newMemSizeMax = MIN_STACKSIZE;
        }

        errCode = setStacksize(newMemSizeMax);
        if (errCode != 0)
        {
            setStacksize(backupSize);
            Scierror(10001, _("%s: Cannot allocate memory.\n%s\n"), fname, getStackCreationErrorMessage(errCode));
        }
        return 0;
    }
    else
    {
        /* stacksize('min') fails */
        /* restore previous size */
        setStacksize(backupSize);
        Scierror(10001, _("%s: Cannot allocate memory.\n"), fname);
    }
    return 0;
}
コード例 #2
0
ファイル: sci_stacksize.c プロジェクト: ASP1234/Scilabv5.5.2
/*--------------------------------------------------------------------------*/
static int setStacksizeMin(char *fname)
{
    unsigned long memstackused = getUsedStacksize();

    if (memstackused < MIN_STACKSIZE)
    {
        return setStacksize(MIN_STACKSIZE);
    }
    else
    {
        /* Add 3000 security for the stack */
        return setStacksize(memstackused + 3000);
    }
}
コード例 #3
0
ファイル: mmsthread.cpp プロジェクト: RomTok/disco-light
MMSThread::MMSThread(string identity, int priority, bool autodetach) {
#ifdef __HAVE_DIRECTFB__
    D_DEBUG_AT( MMS_Thread, "MMSThread( %s )\n", identity.c_str() );

    direct_trace_print_stack(NULL);
#endif /* __HAVE_DIRECTFB__ */

    // save parameters
    this->identity = identity;
    this->priority = priority;

    // setup initial values
    this->starting = false;
    this->running = false;
    this->detached = false;
    this->autodetach = autodetach;
    setStacksize();
}
コード例 #4
0
ファイル: sci_stacksize.c プロジェクト: ASP1234/Scilabv5.5.2
/*--------------------------------------------------------------------------*/
static int sci_stacksizeOneRhs(char *fname)
{
    int l1 = 0, n1 = 0, m1 = 0;
    int errCode = 0;

    if (GetType(1) == sci_matrix)
    {
        GetRhsVar(1, MATRIX_OF_DOUBLE_DATATYPE, &m1, &n1, &l1);
        if ((m1 == 1) && (n1 == 1))
        {
            unsigned long NEWMEMSTACKSIZE = (unsigned long) * stk(l1);

            /* add 1 for alignment problems */
            if (is_a_valid_size_for_scilab_stack(NEWMEMSTACKSIZE + 1))
            {
                if ((NEWMEMSTACKSIZE >= MIN_STACKSIZE) && (NEWMEMSTACKSIZE <= get_max_memory_for_scilab_stack()))
                {
                    /* we backup previous size */
                    unsigned long backupSize = getCurrentStacksize();

                    errCode = setStacksizeMin(fname);
                    if (errCode == 0)
                    {
                        errCode = setStacksize(NEWMEMSTACKSIZE);
                        if (errCode == 0)
                        {
                            LhsVar(1) = 0;
                            PutLhsVar();
                            return 0;
                        }
                        else
                        {
                            /* restore previous size */
                            setStacksize(backupSize);
                            Scierror(10001, _("%s: Cannot allocate memory.\n%s\n"), fname, getStackCreationErrorMessage(errCode));
                        }
                    }
                    else
                    {
                        /* restore previous size */
                        setStacksize(backupSize);
                        Scierror(10001, _("%s: Cannot allocate memory.\n%s\n"), fname, getStackCreationErrorMessage(errCode));
                    }

                }
                else
                {
                    Scierror(1504, _("%s: Out of bounds value. Not in [%lu,%lu].\n"), fname, MIN_STACKSIZE, get_max_memory_for_scilab_stack() - 1);
                }
            }
            else
            {
                Scierror(1504, _("%s: Out of bounds value. Not in [%lu,%lu].\n"), fname, MIN_STACKSIZE, get_max_memory_for_scilab_stack() - 1);
            }
        }
        else
        {
            Scierror(204, _("%s: Wrong size for input argument #%d: Scalar expected.\n"), fname, 1);
        }
    }
    else if (GetType(1) == sci_strings)
    {
        char *param = NULL;

        GetRhsVar(1, STRING_DATATYPE, &m1, &n1, &l1);
        param = cstk(l1);
        if (strcmp(PARAM_MAX_STR, param) == 0)
        {
            return sci_stacksizeMax(fname);
        }
        else if (strcmp(PARAM_MIN_STR, param) == 0)
        {
            return sci_stacksizeMin(fname);
        }
        else
        {
            Scierror(204, _("%s: Wrong type for input argument #%d: Scalar, '%s' or '%s'.\n"), fname, 1, "min", "max");
        }
    }
    else
    {
        Scierror(204, _("%s: Wrong type for input argument #%d: Scalar, '%s' or '%s'.\n"), fname, 1, "min", "max");
    }
    return 0;
}