glowmem.h

Go to the documentation of this file.
00001 /* 
00002  * Copyright (C) 2006 Nokia Corporation.
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General
00015  * Public License along with this library; if not, write to the
00016  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
00017  * Boston, MA 02111-1307, USA.
00018  */
00019 #ifndef __G_LOW_MEM_H__
00020 #define __G_LOW_MEM_H__
00021  
00022 #include <unistd.h> 
00023 #include <setjmp.h>
00024 
00025 /*-------------------------- Data Structure Decleration ----------------*/
00026 typedef struct _cleanUpStack cleanUpStack ;
00027 typedef struct _mem_info mem_info ;
00028 
00029 struct _cleanUpStack
00030 {
00031         void *ptr[1000];
00032         int top;
00033 };
00034 
00035 struct _mem_info
00036 {
00037         int is_setjmp_called;
00038         jmp_buf buf;
00039         cleanUpStack stack;
00040 };
00041 
00042  
00043 /*--------------------Function declerations------------------*/ 
00044 #ifdef __cplusplus
00045 extern "C"
00046 {
00047 #endif    /* __cplusplus */
00048 
00049 IMPORT_C mem_info * _get_thread_specific_data();
00050 IMPORT_C int _set_thread_specific_data(mem_info *m);
00051 IMPORT_C int _push(cleanUpStack *cs,void *ptr);
00052 IMPORT_C void *_pop(cleanUpStack *cs);
00053 IMPORT_C void _findAndDestroy(cleanUpStack *cs,void *ptr);
00054 IMPORT_C void _destroCleanUpStack(cleanUpStack *cs);
00055 IMPORT_C void _clearCleanUpStack(cleanUpStack *cs);
00056 IMPORT_C void * _pAlloc(size_t size);
00057 IMPORT_C void _dummy1();
00058 IMPORT_C void _dummy2();
00059 IMPORT_C void _dummy3();
00060 
00061 #ifdef __cplusplus
00062 }
00063 #endif    /* __cplusplus */
00064 
00065 /*--------------------MACRO declerations------------------*/
00066 
00067 #define SET_LOW_MEMORY_TRAP_VOID()      \
00068 gboolean did_i_set = FALSE;\
00069 {\
00070         mem_info *m = _get_thread_specific_data();\
00071         if(m == NULL)\
00072         {\
00073                 m = (mem_info *)_pAlloc(sizeof(mem_info));\
00074                 if(!m)\
00075                         return;\
00076                 m->is_setjmp_called = FALSE;\
00077                 _clearCleanUpStack(&(m->stack));\
00078                 if(_set_thread_specific_data(m))\
00079                         return;\
00080         }\
00081         if(!m->is_setjmp_called)\
00082         {\
00083                 if(setjmp(m->buf) > 0)\
00084                 {\
00085                         m->is_setjmp_called = FALSE;\
00086                         _destroCleanUpStack(&(m->stack));\
00087                         return ;\
00088                 }\
00089                 m->is_setjmp_called = TRUE;\
00090                 did_i_set = TRUE;\
00091         }\
00092 }
00093 
00094 #define SET_LOW_MEMORY_TRAP(failure_value)      \
00095 gboolean did_i_set = FALSE;\
00096 {\
00097         mem_info *m = _get_thread_specific_data();\
00098         if(m == NULL)\
00099         {\
00100                 m = (mem_info *)_pAlloc(sizeof(mem_info));\
00101                 if(!m)\
00102                         return failure_value;\
00103                 m->is_setjmp_called = FALSE;\
00104                 _clearCleanUpStack(&(m->stack));\
00105                 if(_set_thread_specific_data(m))\
00106                         return failure_value;\
00107         }\
00108         if(!m->is_setjmp_called)\
00109         {\
00110                 if(setjmp(m->buf) > 0)\
00111                 {\
00112                         m->is_setjmp_called = FALSE;\
00113                         _destroCleanUpStack(&(m->stack));\
00114                         return failure_value;\
00115                 }\
00116                 m->is_setjmp_called = TRUE;\
00117                 did_i_set = TRUE;\
00118         }\
00119 }
00120 
00121 
00122 #define REMOVE_LOW_MEMORY_TRAP()        {\
00123 if(did_i_set)\
00124         {\
00125         mem_info *m = _get_thread_specific_data();\
00126         if(m)\
00127                 m->is_setjmp_called = FALSE;\
00128                 _clearCleanUpStack(&(m->stack));\
00129         }\
00130 }
00131 
00132 #endif /* __G_LOW_MEM_H__ */

Copyright © Nokia Corporation 2001-2008
Back to top