2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #ifndef __G_LOW_MEM_H__
20 #define __G_LOW_MEM_H__
25 /*-------------------------- Data Structure Decleration ----------------*/
26 typedef struct _cleanUpStack cleanUpStack ;
27 typedef struct _mem_info mem_info ;
43 /*--------------------Function declerations------------------*/
47 #endif /* __cplusplus */
49 IMPORT_C mem_info * _get_thread_specific_data();
50 IMPORT_C int _set_thread_specific_data(mem_info *m);
51 IMPORT_C int _push(cleanUpStack *cs,void *ptr);
52 IMPORT_C void *_pop(cleanUpStack *cs);
53 IMPORT_C void _findAndDestroy(cleanUpStack *cs,void *ptr);
54 IMPORT_C void _destroCleanUpStack(cleanUpStack *cs);
55 IMPORT_C void _clearCleanUpStack(cleanUpStack *cs);
56 IMPORT_C void * _pAlloc(size_t size);
57 IMPORT_C void _dummy1();
58 IMPORT_C void _dummy2();
59 IMPORT_C void _dummy3();
63 #endif /* __cplusplus */
65 /*--------------------MACRO declerations------------------*/
67 #define SET_LOW_MEMORY_TRAP_VOID() \
68 gboolean did_i_set = FALSE;\
70 mem_info *m = _get_thread_specific_data();\
73 m = (mem_info *)_pAlloc(sizeof(mem_info));\
76 m->is_setjmp_called = FALSE;\
77 _clearCleanUpStack(&(m->stack));\
78 if(_set_thread_specific_data(m))\
81 if(!m->is_setjmp_called)\
83 if(setjmp(m->buf) > 0)\
85 m->is_setjmp_called = FALSE;\
86 _destroCleanUpStack(&(m->stack));\
89 m->is_setjmp_called = TRUE;\
94 #define SET_LOW_MEMORY_TRAP(failure_value) \
95 gboolean did_i_set = FALSE;\
97 mem_info *m = _get_thread_specific_data();\
100 m = (mem_info *)_pAlloc(sizeof(mem_info));\
102 return failure_value;\
103 m->is_setjmp_called = FALSE;\
104 _clearCleanUpStack(&(m->stack));\
105 if(_set_thread_specific_data(m))\
106 return failure_value;\
108 if(!m->is_setjmp_called)\
110 if(setjmp(m->buf) > 0)\
112 m->is_setjmp_called = FALSE;\
113 _destroCleanUpStack(&(m->stack));\
114 return failure_value;\
116 m->is_setjmp_called = TRUE;\
122 #define REMOVE_LOW_MEMORY_TRAP() {\
125 mem_info *m = _get_thread_specific_data();\
127 m->is_setjmp_called = FALSE;\
128 _clearCleanUpStack(&(m->stack));\
132 #endif /* __G_LOW_MEM_H__ */