universalservice/include/cheney_c89.h

65 lines
2.0 KiB
C

/* Copyright (C) 2024 Peter McGoron
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program. If not, see
* <https://www.gnu.org/licenses/>.
*/
#ifndef UNS_CHENEY_C89_H
#define UNS_CHENEY_C89_H
#include "uns.h"
/* Cheney copying collector in pure portable C89.
*
* The copying collector does not support weak references or mixed
* records. Every collection calls malloc() to obtain a new heap.
*
* This collector is useful for hosted implementations that want a
* resizable heap.
*/
struct uns_cheney_c89_statistics {
size_t usage_before;
size_t usage_after;
size_t collection_number;
};
typedef void (*uns_cheney_c89_collect_callback)
(Uns_GC, struct uns_cheney_c89_statistics *)
;
void uns_cheney_c89_set_new_heap_size(Uns_GC gc, size_t siz);
size_t uns_cheney_c89_get_new_heap_size(Uns_GC gc);
void uns_cheney_c89_set_collect_callback(
Uns_GC gc,
uns_cheney_c89_collect_callback cb
);
void *uns_cheney_c89_get(Uns_ptr p, size_t loc,
enum uns_fld_type *typ);
void uns_cheney_c89_set(Uns_ptr p, size_t loc,
enum uns_fld_type typ, void *newp);
void uns_cheney_c89_deinit(Uns_GC gc);
int uns_cheney_c89_collect(Uns_GC gc);
void *uns_cheney_c89_alloc(Uns_GC gc, size_t elems,
enum uns_bytes_type typ);
void *uns_cheney_c89_alloc_rec(Uns_GC gc, size_t elems,
enum uns_record_type typ);
int uns_cheney_c89_init(Uns_GC gc, size_t heap_size);
const extern size_t uns_cheney_c89_ctx_size;
#endif