예제 #1
0
 private static void ZSTD_cwksp_mark_tables_dirty(ZSTD_cwksp *ws)
 {
     assert(ws->tableValidEnd >= ws->objectEnd);
     assert(ws->tableValidEnd <= ws->allocStart);
     ws->tableValidEnd = ws->objectEnd;
     ZSTD_cwksp_assert_internal_consistency(ws);
 }
예제 #2
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);
        }
예제 #3
0
        private static void ZSTD_cwksp_free(ZSTD_cwksp *ws, ZSTD_customMem customMem)
        {
            void *ptr = ws->workspace;

            memset((void *)(ws), (0), ((nuint)(sizeof(ZSTD_cwksp))));
            ZSTD_customFree(ptr, customMem);
        }
예제 #4
0
 private static void ZSTD_cwksp_assert_internal_consistency(ZSTD_cwksp *ws)
 {
     assert(ws->workspace <= ws->objectEnd);
     assert(ws->objectEnd <= ws->tableEnd);
     assert(ws->objectEnd <= ws->tableValidEnd);
     assert(ws->tableEnd <= ws->allocStart);
     assert(ws->tableValidEnd <= ws->allocStart);
     assert(ws->allocStart <= ws->workspaceEnd);
 }
예제 #5
0
        private static void ZSTD_cwksp_mark_tables_clean(ZSTD_cwksp *ws)
        {
            assert(ws->tableValidEnd >= ws->objectEnd);
            assert(ws->tableValidEnd <= ws->allocStart);
            if (ws->tableValidEnd < ws->tableEnd)
            {
                ws->tableValidEnd = ws->tableEnd;
            }

            ZSTD_cwksp_assert_internal_consistency(ws);
        }
예제 #6
0
        private static void ZSTD_cwksp_clean_tables(ZSTD_cwksp *ws)
        {
            assert(ws->tableValidEnd >= ws->objectEnd);
            assert(ws->tableValidEnd <= ws->allocStart);
            if (ws->tableValidEnd < ws->tableEnd)
            {
                memset((ws->tableValidEnd), (0), (nuint)(((byte *)(ws->tableEnd) - (byte *)(ws->tableValidEnd))));
            }

            ZSTD_cwksp_mark_tables_clean(ws);
        }
예제 #7
0
 private static void ZSTD_cwksp_bump_oversized_duration(ZSTD_cwksp *ws, nuint additionalNeededSpace)
 {
     if ((ZSTD_cwksp_check_too_large(ws, additionalNeededSpace)) != 0)
     {
         ws->workspaceOversizedDuration++;
     }
     else
     {
         ws->workspaceOversizedDuration = 0;
     }
 }
예제 #8
0
        private static nuint ZSTD_cwksp_create(ZSTD_cwksp *ws, nuint size, ZSTD_customMem customMem)
        {
            void *workspace = ZSTD_customMalloc(size, customMem);

            if (workspace == null)
            {
                return(unchecked ((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_memory_allocation)));
            }

            ZSTD_cwksp_init(ws, workspace, size, ZSTD_cwksp_static_alloc_e.ZSTD_cwksp_dynamic_alloc);
            return(0);
        }
예제 #9
0
        private static void ZSTD_cwksp_clear(ZSTD_cwksp *ws)
        {
            ws->tableEnd    = ws->objectEnd;
            ws->allocStart  = ws->workspaceEnd;
            ws->allocFailed = 0;
            if (ws->phase > ZSTD_cwksp_alloc_phase_e.ZSTD_cwksp_alloc_buffers)
            {
                ws->phase = ZSTD_cwksp_alloc_phase_e.ZSTD_cwksp_alloc_buffers;
            }

            ZSTD_cwksp_assert_internal_consistency(ws);
        }
예제 #10
0
 private static void ZSTD_cwksp_init(ZSTD_cwksp *ws, void *start, nuint size, ZSTD_cwksp_static_alloc_e isStatic)
 {
     assert(((nuint)(start) & ((nuint)(sizeof(void *)) - 1)) == 0);
     ws->workspace     = start;
     ws->workspaceEnd  = (byte *)(start) + size;
     ws->objectEnd     = ws->workspace;
     ws->tableValidEnd = ws->objectEnd;
     ws->phase         = ZSTD_cwksp_alloc_phase_e.ZSTD_cwksp_alloc_objects;
     ws->isStatic      = isStatic;
     ZSTD_cwksp_clear(ws);
     ws->workspaceOversizedDuration = 0;
     ZSTD_cwksp_assert_internal_consistency(ws);
 }
예제 #11
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);
        }
예제 #12
0
        private static void *ZSTD_cwksp_reserve_object(ZSTD_cwksp *ws, nuint bytes)
        {
            nuint roundedBytes = ZSTD_cwksp_align(bytes, (nuint)(sizeof(void *)));
            void *alloc        = ws->objectEnd;
            void *end          = (void *)((byte *)(alloc) + roundedBytes);

            assert(((nuint)(alloc) & ((nuint)(sizeof(void *)) - 1)) == 0);
            assert((bytes & ((nuint)(sizeof(void *)) - 1)) == 0);
            ZSTD_cwksp_assert_internal_consistency(ws);
            if (ws->phase != ZSTD_cwksp_alloc_phase_e.ZSTD_cwksp_alloc_objects || end > ws->workspaceEnd)
            {
                ws->allocFailed = 1;
                return(null);
            }

            ws->objectEnd     = end;
            ws->tableEnd      = end;
            ws->tableValidEnd = end;
            return(alloc);
        }
예제 #13
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;
            }
        }
예제 #14
0
 private static void *ZSTD_cwksp_reserve_aligned(ZSTD_cwksp *ws, nuint bytes)
 {
     assert((bytes & ((nuint)(sizeof(uint)) - 1)) == 0);
     return(ZSTD_cwksp_reserve_internal(ws, ZSTD_cwksp_align(bytes, (nuint)(sizeof(uint))), ZSTD_cwksp_alloc_phase_e.ZSTD_cwksp_alloc_aligned));
 }
예제 #15
0
 private static int ZSTD_cwksp_check_wasteful(ZSTD_cwksp *ws, nuint additionalNeededSpace)
 {
     return(((ZSTD_cwksp_check_too_large(ws, additionalNeededSpace)) != 0 && ws->workspaceOversizedDuration > 128) ? 1 : 0);
 }
예제 #16
0
 private static int ZSTD_cwksp_check_too_large(ZSTD_cwksp *ws, nuint additionalNeededSpace)
 {
     return(ZSTD_cwksp_check_available(ws, additionalNeededSpace * 3));
 }
예제 #17
0
 private static int ZSTD_cwksp_check_available(ZSTD_cwksp *ws, nuint additionalNeededSpace)
 {
     return((ZSTD_cwksp_available_space(ws) >= additionalNeededSpace) ? 1 : 0);
 }
예제 #18
0
 private static nuint ZSTD_cwksp_available_space(ZSTD_cwksp *ws)
 {
     return((nuint)((byte *)(ws->allocStart) - (byte *)(ws->tableEnd)));
 }
예제 #19
0
 private static int ZSTD_cwksp_reserve_failed(ZSTD_cwksp *ws)
 {
     return((int)ws->allocFailed);
 }
예제 #20
0
 private static nuint ZSTD_cwksp_used(ZSTD_cwksp *ws)
 {
     return((nuint)((byte *)(ws->tableEnd) - (byte *)(ws->workspace)) + (nuint)((byte *)(ws->workspaceEnd) - (byte *)(ws->allocStart)));
 }
예제 #21
0
 private static void ZSTD_cwksp_clear_tables(ZSTD_cwksp *ws)
 {
     ws->tableEnd = ws->objectEnd;
     ZSTD_cwksp_assert_internal_consistency(ws);
 }
예제 #22
0
 private static int ZSTD_cwksp_owns_buffer(ZSTD_cwksp *ws, void *ptr)
 {
     return(((ptr != null) && (ws->workspace <= ptr) && (ptr <= ws->workspaceEnd)) ? 1 : 0);
 }
예제 #23
0
 private static nuint ZSTD_cwksp_sizeof(ZSTD_cwksp *ws)
 {
     return((nuint)((byte *)(ws->workspaceEnd) - (byte *)(ws->workspace)));
 }
예제 #24
0
 private static void ZSTD_cwksp_move(ZSTD_cwksp *dst, ZSTD_cwksp *src)
 {
     *dst = *src;
     memset((void *)(src), (0), ((nuint)(sizeof(ZSTD_cwksp))));
 }
예제 #25
0
 private static byte *ZSTD_cwksp_reserve_buffer(ZSTD_cwksp *ws, nuint bytes)
 {
     return((byte *)(ZSTD_cwksp_reserve_internal(ws, bytes, ZSTD_cwksp_alloc_phase_e.ZSTD_cwksp_alloc_buffers)));
 }