Esempio n. 1
0
        private static void *ZSTD_cwksp_reserve_table(ZSTD_cwksp *ws, nuint bytes)
        {
            ZSTD_cwksp_alloc_phase_e phase = ZSTD_cwksp_alloc_phase_e.ZSTD_cwksp_alloc_aligned;
            void *alloc = ws->tableEnd;
            void *end   = (void *)((byte *)(alloc) + bytes);
            void *top   = ws->allocStart;

            assert((bytes & ((nuint)(sizeof(uint)) - 1)) == 0);
            ZSTD_cwksp_internal_advance_phase(ws, phase);
            ZSTD_cwksp_assert_internal_consistency(ws);
            assert(end <= top);
            if (end > top)
            {
                ws->allocFailed = 1;
                return(null);
            }

            ws->tableEnd = end;
            return(alloc);
        }
Esempio n. 2
0
        private static void ZSTD_cwksp_internal_advance_phase(ZSTD_cwksp *ws, ZSTD_cwksp_alloc_phase_e phase)
        {
            assert(phase >= ws->phase);
            if (phase > ws->phase)
            {
                if (ws->phase < ZSTD_cwksp_alloc_phase_e.ZSTD_cwksp_alloc_buffers && phase >= ZSTD_cwksp_alloc_phase_e.ZSTD_cwksp_alloc_buffers)
                {
                    ws->tableValidEnd = ws->objectEnd;
                }

                if (ws->phase < ZSTD_cwksp_alloc_phase_e.ZSTD_cwksp_alloc_aligned && phase >= ZSTD_cwksp_alloc_phase_e.ZSTD_cwksp_alloc_aligned)
                {
                    ws->allocStart = (byte *)(ws->allocStart) - ((nuint)(ws->allocStart) & ((nuint)(sizeof(uint)) - 1));
                    if (ws->allocStart < ws->tableValidEnd)
                    {
                        ws->tableValidEnd = ws->allocStart;
                    }
                }

                ws->phase = phase;
            }
        }
Esempio n. 3
0
        private static void *ZSTD_cwksp_reserve_internal(ZSTD_cwksp *ws, nuint bytes, ZSTD_cwksp_alloc_phase_e phase)
        {
            void *alloc;
            void *bottom = ws->tableEnd;

            ZSTD_cwksp_internal_advance_phase(ws, phase);
            alloc = (byte *)(ws->allocStart) - bytes;
            if (bytes == 0)
            {
                return(null);
            }

            ZSTD_cwksp_assert_internal_consistency(ws);
            assert(alloc >= bottom);
            if (alloc < bottom)
            {
                ws->allocFailed = 1;
                return(null);
            }

            if (alloc < ws->tableValidEnd)
            {
                ws->tableValidEnd = alloc;
            }

            ws->allocStart = alloc;
            return(alloc);
        }