comparison src/cs/riviera/support/exception.c @ 0:945cf7f506b2

src/cs: chipsetsw import from tcs211-fcmodem binary blobs and LCD demo files have been excluded, all line endings are LF only
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 25 Sep 2016 22:50:11 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:945cf7f506b2
1 /*
2 ******************************
3 *
4 *
5 * Initialial version: Laurent Deniau, Laurent.Deniau@cern.ch
6 *
7 * For more information, please see the paper:
8 * http://cern.ch/Laurent.Deniau/html/oopc/exception.html
9 *
10 * -----------------------------------------------------------
11 *
12 * Strong rework and adaption to riviera by Christophe Favergeon
13 *
14 ******************************
15 */
16
17 // Authorization to use this source code communicated to Christophe Favergeon
18 // by email
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <assert.h>
23 #include "support/exception.h"
24
25 #ifndef _WINDOWS
26 #include "config/swconfig.cfg"
27 #endif
28
29
30 /* global stack of exception context */
31 struct _exceptionContext_ *const _returnExceptionContext_[MAX_RVF_TASKS]=
32 #if (!GSMLITE)
33 {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
34 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
35 #else
36 {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
37 #endif
38
39 struct _exceptionContext_ *_currentExceptionContext_ [MAX_RVF_TASKS]=
40 #if (!GSMLITE)
41 {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
42 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
43 #else
44 {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
45 #endif
46
47 /* delete protected pointers and throw exception */
48 void
49 _exceptionThrow_(int exception)
50 {
51 struct _protectedPtr_ *p;
52 struct _protectedPtr_ *oldp;
53
54 /* no exception context saved, exit program */
55 if (!_currentExceptionContext_[rvf_get_taskid()]) exit(exception);
56
57 /* free pointers stored on the current exception context pointers stack */
58 p=_currentExceptionContext_[rvf_get_taskid()]->stack;
59
60 while(p)
61 {
62 oldp=p->previous;
63 p->func(p->ptr);
64 rvf_free_buf(p);
65 p=oldp;
66 }
67
68 _currentExceptionContext_[rvf_get_taskid()]->stack=NULL;
69
70 /* jump to previous exception context */
71 rvf_restore_context_buffer_(_currentExceptionContext_[rvf_get_taskid()]->context, exception);
72 }
73
74
75 // Protect a pointer when there is a try/ctahc block active
76 void rvf_protect_pointer(T_RVF_MB_ID mb_id,void *p,T_RVF_RELEASE_PROTECTED_POINTER func)
77 {
78
79 struct _protectedPtr_ *ptr;
80 struct _exceptionContext_ *context;
81 T_RVF_MB_STATUS err;
82
83
84
85 if (_currentExceptionContext_[rvf_get_taskid()])
86 {
87
88 if (p==NULL)
89 throw(E_not_enough_memory);
90
91 context=_currentExceptionContext_[rvf_get_taskid()];
92 err=rvf_get_buf(mb_id,sizeof(struct _protectedPtr_),(void*)&ptr);
93
94
95 if (err==RVF_GREEN)
96 {
97 ptr->next=NULL;
98 ptr->previous=NULL;
99 ptr->ptr=p;
100 ptr->func=func;
101
102 if (context->stack==NULL)
103 {
104 context->stack=ptr;
105 }
106 else
107 {
108 ptr->previous=context->stack;
109 context->stack->next=ptr;
110 context->stack=ptr;
111 }
112 }
113 else
114 {
115 if (p!=NULL)
116 rvf_free_buf(p);
117 throw(E_not_enough_memory);
118 }
119 }
120 }
121
122 void rvf_forget_protected_ptr()
123 {
124 struct _protectedPtr_ *p;
125 struct _protectedPtr_ *oldp;
126
127 p=_currentExceptionContext_[rvf_get_taskid()]->stack;
128
129 while(p)
130 {
131 oldp=p->previous;
132 rvf_free_buf(p);
133 p=oldp;
134 }
135
136 _currentExceptionContext_[rvf_get_taskid()]->stack=NULL;
137 }
138
139
140