1 /* Copyright (C) 1999 artofcode LLC. All rights reserved. 2 3 This program is free software; you can redistribute it and/or modify it 4 under the terms of the GNU General Public License as published by the 5 Free Software Foundation; either version 2 of the License, or (at your 6 option) any later version. 7 8 This program is distributed in the hope that it will be useful, but 9 WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along 14 with this program; if not, write to the Free Software Foundation, Inc., 15 59 Temple Place, Suite 330, Boston, MA, 02111-1307. 16 17 */ 18 19 /*$Id: gsmemret.h,v 1.2.6.1.2.1 2003/01/17 00:49:03 giles Exp $ */ 20 /* Interface to retrying memory allocator */ 21 22 #if !defined(gsmemret_INCLUDED) 23 # define gsmemret_INCLUDED 24 25 #include "gsmemory.h" 26 27 /* 28 * This allocator encapsulates another allocator with a closure that is 29 * called to attempt to free up memory if an allocation fails. 30 * Note that it does not keep track of memory that it acquires: 31 * thus free_all with FREE_ALL_DATA is a no-op. 32 */ 33 typedef struct gs_memory_retrying_s gs_memory_retrying_t; 34 35 /* 36 * Define the procedure type for the recovery closure. 37 */ 38 typedef enum { 39 RECOVER_STATUS_NO_RETRY, 40 RECOVER_STATUS_RETRY_OK 41 } gs_memory_recover_status_t; 42 typedef gs_memory_recover_status_t (*gs_memory_recover_proc_t) 43 (P2(gs_memory_retrying_t *rmem, void *proc_data)); 44 45 struct gs_memory_retrying_s { 46 gs_memory_common; /* interface outside world sees */ 47 gs_memory_t *target; /* allocator to front */ 48 gs_memory_recover_proc_t recover_proc; 49 void *recover_proc_data; 50 }; 51 52 /* ---------- Public constructors/destructors ---------- */ 53 54 /* Initialize a retrying memory manager. */ 55 int gs_memory_retrying_init(P2( 56 gs_memory_retrying_t * rmem, /* allocator to init */ 57 gs_memory_t * target /* allocator to wrap */ 58 )); 59 60 /* Release a retrying memory manager. */ 61 /* Note that this has no effect on the target. */ 62 void gs_memory_retrying_release(P1(gs_memory_retrying_t *rmem)); 63 64 /* Set the recovery closure of a retrying memory manager. */ 65 void gs_memory_retrying_set_recover(P3(gs_memory_retrying_t *rmem, 66 gs_memory_recover_proc_t recover_proc, 67 void *recover_proc_data)); 68 69 /* Get the target of a retrying memory manager. */ 70 gs_memory_t * gs_memory_retrying_target(P1(const gs_memory_retrying_t *rmem)); 71 72 #endif /*!defined(gsmemret_INCLUDED) */ 73