epoc32/include/stdapis/glib-2.0/glowmem.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 2 2fe1408b6811
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 #ifndef __G_LOW_MEM_H__
    20 #define __G_LOW_MEM_H__
    21  
    22 #include <unistd.h> 
    23 #include <setjmp.h>
    24 
    25 /*-------------------------- Data Structure Decleration ----------------*/
    26 typedef struct _cleanUpStack cleanUpStack ;
    27 typedef struct _mem_info mem_info ;
    28 
    29 struct _cleanUpStack
    30 {
    31 	void *ptr[1000];
    32 	int top;
    33 };
    34 
    35 struct _mem_info
    36 {
    37 	int is_setjmp_called;
    38 	jmp_buf buf;
    39 	cleanUpStack stack;
    40 };
    41 
    42  
    43 /*--------------------Function declerations------------------*/ 
    44 #ifdef __cplusplus
    45 extern "C"
    46 {
    47 #endif    /* __cplusplus */
    48 
    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();
    60 
    61 #ifdef __cplusplus
    62 }
    63 #endif    /* __cplusplus */
    64 
    65 /*--------------------MACRO declerations------------------*/
    66 
    67 #define SET_LOW_MEMORY_TRAP_VOID()	\
    68 gboolean did_i_set = FALSE;\
    69 {\
    70 	mem_info *m = _get_thread_specific_data();\
    71 	if(m == NULL)\
    72 	{\
    73 		m = (mem_info *)_pAlloc(sizeof(mem_info));\
    74 		if(!m)\
    75 			return;\
    76 		m->is_setjmp_called = FALSE;\
    77 		_clearCleanUpStack(&(m->stack));\
    78 		if(_set_thread_specific_data(m))\
    79 			return;\
    80 	}\
    81 	if(!m->is_setjmp_called)\
    82 	{\
    83   		if(setjmp(m->buf) > 0)\
    84   		{\
    85   			m->is_setjmp_called = FALSE;\
    86   			_destroCleanUpStack(&(m->stack));\
    87   			return ;\
    88   		}\
    89   		m->is_setjmp_called = TRUE;\
    90   		did_i_set = TRUE;\
    91   	}\
    92 }
    93 
    94 #define SET_LOW_MEMORY_TRAP(failure_value)	\
    95 gboolean did_i_set = FALSE;\
    96 {\
    97 	mem_info *m = _get_thread_specific_data();\
    98 	if(m == NULL)\
    99 	{\
   100 		m = (mem_info *)_pAlloc(sizeof(mem_info));\
   101 		if(!m)\
   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;\
   107 	}\
   108 	if(!m->is_setjmp_called)\
   109 	{\
   110   		if(setjmp(m->buf) > 0)\
   111   		{\
   112   			m->is_setjmp_called = FALSE;\
   113   			_destroCleanUpStack(&(m->stack));\
   114   			return failure_value;\
   115   		}\
   116   		m->is_setjmp_called = TRUE;\
   117   		did_i_set = TRUE;\
   118   	}\
   119 }
   120 
   121 
   122 #define REMOVE_LOW_MEMORY_TRAP()	{\
   123 if(did_i_set)\
   124 	{\
   125 	mem_info *m = _get_thread_specific_data();\
   126 	if(m)\
   127 		m->is_setjmp_called = FALSE;\
   128 		_clearCleanUpStack(&(m->stack));\
   129 	}\
   130 }
   131 
   132 #endif /* __G_LOW_MEM_H__ */