epoc32/include/stdapis/glib-2.0/glowmem.h
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
child 4 837f303aceeb
     1.1 --- a/epoc32/include/stdapis/glib-2.0/glowmem.h	Tue Nov 24 13:55:44 2009 +0000
     1.2 +++ b/epoc32/include/stdapis/glib-2.0/glowmem.h	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -1,1 +1,144 @@
     1.4 -glowmem.h
     1.5 +/*
     1.6 +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
     1.7 +
     1.8 +* Redistribution and use in source and binary forms, with or without 
     1.9 +* modification, are permitted provided that the following conditions are met:
    1.10 +
    1.11 +* Redistributions of source code must retain the above copyright notice, this 
    1.12 +* list of conditions and the following disclaimer.
    1.13 +* Redistributions in binary form must reproduce the above copyright notice, 
    1.14 +* this list of conditions and the following disclaimer in the documentation 
    1.15 +* and/or other materials provided with the distribution.
    1.16 +* Neither the name of Nokia Corporation nor the names of its contributors 
    1.17 +* may be used to endorse or promote products derived from this software 
    1.18 +* without specific prior written permission.
    1.19 +
    1.20 +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
    1.21 +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
    1.22 +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
    1.23 +* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 
    1.24 +* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
    1.25 +* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
    1.26 +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
    1.27 +* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
    1.28 +* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    1.29 +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.30 +*
    1.31 +* Description:
    1.32 +*
    1.33 +*/
    1.34 +
    1.35 +#ifndef __G_LOW_MEM_H__
    1.36 +#define __G_LOW_MEM_H__
    1.37 + 
    1.38 +#include <unistd.h> 
    1.39 +#include <setjmp.h>
    1.40 +
    1.41 +/*-------------------------- Data Structure Decleration ----------------*/
    1.42 +typedef struct _cleanUpStack cleanUpStack ;
    1.43 +typedef struct _mem_info mem_info ;
    1.44 +
    1.45 +struct _cleanUpStack
    1.46 +{
    1.47 +	void *ptr[1000];
    1.48 +	int top;
    1.49 +};
    1.50 +
    1.51 +struct _mem_info
    1.52 +{
    1.53 +	int is_setjmp_called;
    1.54 +	jmp_buf buf;
    1.55 +	cleanUpStack stack;
    1.56 +};
    1.57 +
    1.58 + 
    1.59 +/*--------------------Function declerations------------------*/ 
    1.60 +#ifdef __cplusplus
    1.61 +extern "C"
    1.62 +{
    1.63 +#endif    /* __cplusplus */
    1.64 +
    1.65 +IMPORT_C mem_info * _get_thread_specific_data();
    1.66 +IMPORT_C int _set_thread_specific_data(mem_info *m);
    1.67 +IMPORT_C int _push(cleanUpStack *cs,void *ptr);
    1.68 +IMPORT_C void *_pop(cleanUpStack *cs);
    1.69 +IMPORT_C void _findAndDestroy(cleanUpStack *cs,void *ptr);
    1.70 +IMPORT_C void _destroCleanUpStack(cleanUpStack *cs);
    1.71 +IMPORT_C void _clearCleanUpStack(cleanUpStack *cs);
    1.72 +IMPORT_C void * _pAlloc(size_t size);
    1.73 +IMPORT_C void _dummy1();
    1.74 +IMPORT_C void _dummy2();
    1.75 +IMPORT_C void _dummy3();
    1.76 +
    1.77 +#ifdef __cplusplus
    1.78 +}
    1.79 +#endif    /* __cplusplus */
    1.80 +
    1.81 +/*--------------------MACRO declerations------------------*/
    1.82 +
    1.83 +#define SET_LOW_MEMORY_TRAP_VOID()	\
    1.84 +gboolean did_i_set = FALSE;\
    1.85 +{\
    1.86 +	mem_info *m = _get_thread_specific_data();\
    1.87 +	if(m == NULL)\
    1.88 +	{\
    1.89 +		m = (mem_info *)_pAlloc(sizeof(mem_info));\
    1.90 +		if(!m)\
    1.91 +			return;\
    1.92 +		m->is_setjmp_called = FALSE;\
    1.93 +		_clearCleanUpStack(&(m->stack));\
    1.94 +		if(_set_thread_specific_data(m))\
    1.95 +			return;\
    1.96 +	}\
    1.97 +	if(!m->is_setjmp_called)\
    1.98 +	{\
    1.99 +  		if(setjmp(m->buf) > 0)\
   1.100 +  		{\
   1.101 +  			m->is_setjmp_called = FALSE;\
   1.102 +  			_destroCleanUpStack(&(m->stack));\
   1.103 +  			return ;\
   1.104 +  		}\
   1.105 +  		m->is_setjmp_called = TRUE;\
   1.106 +  		did_i_set = TRUE;\
   1.107 +  	}\
   1.108 +}
   1.109 +
   1.110 +#define SET_LOW_MEMORY_TRAP(failure_value)	\
   1.111 +gboolean did_i_set = FALSE;\
   1.112 +{\
   1.113 +	mem_info *m = _get_thread_specific_data();\
   1.114 +	if(m == NULL)\
   1.115 +	{\
   1.116 +		m = (mem_info *)_pAlloc(sizeof(mem_info));\
   1.117 +		if(!m)\
   1.118 +			return failure_value;\
   1.119 +		m->is_setjmp_called = FALSE;\
   1.120 +		_clearCleanUpStack(&(m->stack));\
   1.121 +		if(_set_thread_specific_data(m))\
   1.122 +			return failure_value;\
   1.123 +	}\
   1.124 +	if(!m->is_setjmp_called)\
   1.125 +	{\
   1.126 +  		if(setjmp(m->buf) > 0)\
   1.127 +  		{\
   1.128 +  			m->is_setjmp_called = FALSE;\
   1.129 +  			_destroCleanUpStack(&(m->stack));\
   1.130 +  			return failure_value;\
   1.131 +  		}\
   1.132 +  		m->is_setjmp_called = TRUE;\
   1.133 +  		did_i_set = TRUE;\
   1.134 +  	}\
   1.135 +}
   1.136 +
   1.137 +
   1.138 +#define REMOVE_LOW_MEMORY_TRAP()	{\
   1.139 +if(did_i_set)\
   1.140 +	{\
   1.141 +	mem_info *m = _get_thread_specific_data();\
   1.142 +	if(m)\
   1.143 +		m->is_setjmp_called = FALSE;\
   1.144 +		_clearCleanUpStack(&(m->stack));\
   1.145 +	}\
   1.146 +}
   1.147 +
   1.148 +#endif /* __G_LOW_MEM_H__ */
   1.149 \ No newline at end of file