glowmem_action.h

Go to the documentation of this file.
00001 /* 
00002  * Copyright (C) 2006 Nokia Corporation.
00003  * Copyright 2010 Helsinki Institute for Information Technology (HIIT)
00004  * and Tero Hasu <tero.hasu@hut.fi>.
00005  *
00006  * This is a derived work of SET_LOW_MEMORY_TRAP as found in glowmem.h
00007  * by Nokia Corporation.
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License.
00013  *
00014  * This library is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00017  * Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General
00020  * Public License along with this library; if not, write to the
00021  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
00022  * Boston, MA 02111-1307, USA.
00023  */
00024 #ifndef __glowmem_action_h__
00025 #define __glowmem_action_h__
00026 
00027 #if defined(__SYMBIAN32__)
00028 
00029 #include <glowmem.h>
00030 
00031 // The idea is to set up some action to deal with an OOM error.
00032 // You must specify an action that causes a return, non-local return, jump, or thread exit. This is because the macro assumes that its execution does not continue after the provided action (this could be changed with better understanding of the internal APIs used).
00033 // Yes, SET_LOW_MEMORY_TRAP_VOID() and SET_LOW_MEMORY_TRAP(failure_value) could be implemented in terms of this macro.
00034 // And yes, this is a bit naughty as it uses internal APIs, but if the internal ABI changes, then existing uses of SET_LOW_MEMORY_TRAP_VOID and SET_LOW_MEMORY_TRAP also require at least recompilation.
00035 // Does this code leak memory if _set_thread_specific_data fails?
00036 #define SET_LOW_MEMORY_TRAP_ACTION(action)      \
00037 gboolean did_i_set = FALSE;\
00038 {\
00039         mem_info *m = _get_thread_specific_data();\
00040         if(m == NULL)\
00041         {\
00042                 m = (mem_info *)_pAlloc(sizeof(mem_info));\
00043                 if(!m) { action; } \
00044                 m->is_setjmp_called = FALSE;\
00045                 _clearCleanUpStack(&(m->stack));\
00046                 if(_set_thread_specific_data(m))\
00047                         { action; } \
00048         }\
00049         if(!m->is_setjmp_called)\
00050         {\
00051                 if(setjmp(m->buf) > 0)\
00052                 {\
00053                         m->is_setjmp_called = FALSE;\
00054                         _destroCleanUpStack(&(m->stack));\
00055                         { action; } \
00056                 }\
00057                 m->is_setjmp_called = TRUE;\
00058                 did_i_set = TRUE;\
00059         }\
00060 }
00061 
00062 #else
00063 #define SET_LOW_MEMORY_TRAP_ACTION(action)
00064 #endif /* __SYMBIAN32__ */
00065 
00066 #endif /* __glowmem_action_h__ */

ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:53 2011 by Doxygen 1.6.1