1 /* Copyright (C) 2001-2012 Artifex Software, Inc. 2 All Rights Reserved. 3 4 This software is provided AS-IS with no warranty, either express or 5 implied. 6 7 This software is distributed under license and may not be copied, 8 modified or distributed except as expressly authorized under the terms 9 of the license contained in the file LICENSE in this distribution. 10 11 Refer to licensing information at http://www.artifex.com or contact 12 Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134, San Rafael, 13 CA 94903, U.S.A., +1(415)492-9861, for further information. 14 */ 15 16 17 /* Interface to retrying memory allocator */ 18 19 #if !defined(gsmemret_INCLUDED) 20 # define gsmemret_INCLUDED 21 22 #include "gsmemory.h" 23 24 /* 25 * This allocator encapsulates another allocator with a closure that is 26 * called to attempt to free up memory if an allocation fails. 27 * Note that it does not keep track of memory that it acquires: 28 * thus free_all with FREE_ALL_DATA is a no-op. 29 */ 30 typedef struct gs_memory_retrying_s gs_memory_retrying_t; 31 32 /* 33 * Define the procedure type for the recovery closure. 34 */ 35 typedef enum { 36 RECOVER_STATUS_NO_RETRY, 37 RECOVER_STATUS_RETRY_OK 38 } gs_memory_recover_status_t; 39 typedef gs_memory_recover_status_t (*gs_memory_recover_proc_t) 40 (gs_memory_retrying_t *rmem, void *proc_data); 41 42 struct gs_memory_retrying_s { 43 gs_memory_common; /* interface outside world sees */ 44 gs_memory_t *target; /* allocator to front */ 45 gs_memory_recover_proc_t recover_proc; 46 void *recover_proc_data; 47 }; 48 49 /* ---------- Public constructors/destructors ---------- */ 50 51 /* Initialize a retrying memory manager. */ 52 int gs_memory_retrying_init( 53 gs_memory_retrying_t * rmem, /* allocator to init */ 54 gs_memory_t * target /* allocator to wrap */ 55 ); 56 57 /* Release a retrying memory manager. */ 58 /* Note that this has no effect on the target. */ 59 void gs_memory_retrying_release(gs_memory_retrying_t *rmem); 60 61 /* Set the recovery closure of a retrying memory manager. */ 62 void gs_memory_retrying_set_recover(gs_memory_retrying_t *rmem, 63 gs_memory_recover_proc_t recover_proc, 64 void *recover_proc_data); 65 66 /* Get the target of a retrying memory manager. */ 67 gs_memory_t * gs_memory_retrying_target(const gs_memory_retrying_t *rmem); 68 69 #endif /*!defined(gsmemret_INCLUDED) */ 70