6 #define RCN_MAXCACHE 16
7 mbkcache
* RCN_POOLCACHE
[RCN_MAXCACHE
];
10 /******************************************************************************\
11 Fonction d'accès aux ensembles de cache.
12 \******************************************************************************/
13 mbkcache
* rcn_getpoolcache( int pool
)
15 return RCN_POOLCACHE
[pool
];
18 void rcn_setpoolcache( int pool
, mbkcache
*cache
)
20 RCN_POOLCACHE
[pool
] = cache
;
23 int rcn_getnewpoolcache( void )
25 if( RCN_NBCACHE
== RCN_MAXCACHE
) {
26 avt_errmsg( RCN_ERRMSG
, "001", AVT_FATAL
);
31 /******************************************************************************\
33 Active le cache pour la lofig. Aucuns réseaux RC ne doit être déjà présent. Si
34 un réseau RC est déjà présent sur un signal, le cache n'est pas actif pour ce
35 signal. Cette fonction est principalement destinée à être utilisée dans les
38 \******************************************************************************/
40 void rcn_enable_cache( lofig_list
*lofig
,
41 unsigned long int (*fn_load
)(lofig_list
*, losig_list
*),
42 void (*fn_free
)(lofig_list
*),
49 cache
= rcn_getlofigcache( lofig
);
50 if( cache
|| RCN_CACHE_SIZE
== 0ul ) return;
52 cache
= rcn_getpoolcache( pool
);
55 cache
= mbk_cache_create(
56 (char(*)(void*,void*))NULL
,
57 (unsigned long int(*)(void*,void*))fn_load
,
58 (unsigned long int(*)(void*,void*))rcn_cache_release
,
61 rcn_setpoolcache( pool
, cache
);
64 rcn_alloclofigcache( lofig
, cache
, fn_free
);
67 /******************************************************************************\
71 \******************************************************************************/
73 void rcn_disable_cache( lofig_list
*lofig
)
76 void (*fn_free
)(lofig_list
*) ;
78 losig_list
*scanlosig
;
80 cache
= rcn_getlofigcache( lofig
);
84 for( scanlosig
= lofig
->LOSIG
; scanlosig
; scanlosig
= scanlosig
->NEXT
)
85 rcn_flush_signal( lofig
, scanlosig
);
87 ptl
= getptype( lofig
->USER
, RCN_LOFIGCACHE_FREE
);
89 fn_free
= (void(*)(lofig_list
*)) ptl
->DATA
;
91 lofig
->USER
= delptype( lofig
->USER
, RCN_LOFIGCACHE_FREE
);
94 lofig
->USER
= delptype( lofig
->USER
, RCN_LOFIGCACHE
);
97 /******************************************************************************\
99 Récupère les informations relative au cache pour une lofig. Si cette fonction
100 renvoie NULL, c'est que le cache n'est pas actif pour cette lofig.
102 \******************************************************************************/
104 mbkcache
* rcn_getlofigcache( lofig_list
*lofig
)
108 ptl
= getptype( lofig
->USER
, RCN_LOFIGCACHE
);
110 return (mbkcache
*)(ptl
->DATA
);
114 /******************************************************************************\
116 Alloue les informations de cache pour une lofig.
118 \******************************************************************************/
120 void rcn_alloclofigcache( lofig_list
*lofig
,
122 void (*fn_free
)(lofig_list
*)
125 lofig
->USER
= addptype( lofig
->USER
, RCN_LOFIGCACHE
, cache
);
127 lofig
->USER
= addptype( lofig
->USER
, RCN_LOFIGCACHE_FREE
, fn_free
);
130 /******************************************************************************\
132 Met à jour un signal. Sans effet si le cache n'est pas actif.
134 \******************************************************************************/
136 void rcn_refresh_signal( lofig_list
*lofig
, losig_list
*losig
)
139 static lofig_list
*lastlofig
= NULL
;
140 static losig_list
*lastlosig
= NULL
;
142 if( lastlofig
== lofig
&& lastlosig
== losig
)
145 if( rcn_issignal_disablecache( losig
) ) {
146 // rcn_error( 34, AVT_WARNING );
150 avt_logenterfunction(LOGMBKCACHE
,2,"rcn_refresh_signal()" );
151 cache
= rcn_getlofigcache( lofig
);
153 rcn_enablewritelofig( lofig
);
154 mbk_cache_refresh( cache
, lofig
, losig
);
155 rcn_disablewritelofig( lofig
);
156 rcn_setsignal_loaded( losig
);
160 rcn_synccapa( lofig
, losig
);
162 avt_logexitfunction(LOGMBKCACHE
,2);
164 // rcn_cache_debug( lofig );
168 /******************************************************************************\
170 Fonctions de verrouillage d'un signal.
172 \******************************************************************************/
174 void rcn_lock_signal( lofig_list
*lofig
, losig_list
*losig
)
178 cache
= rcn_getlofigcache( lofig
);
182 rcn_refresh_signal( lofig
, losig
);
183 mbk_cache_lock( cache
, losig
);
186 void rcn_unlock_signal( lofig_list
*lofig
, losig_list
*losig
)
190 cache
= rcn_getlofigcache( lofig
);
194 mbk_cache_unlock( cache
, losig
);
197 /* Renvoie YES ou NO */
198 char rcn_islock_signal( lofig_list
*lofig
, losig_list
*losig
)
202 cache
= rcn_getlofigcache( lofig
);
206 return mbk_cache_islock( cache
, losig
);
209 /******************************************************************************\
211 Force la libération des RC d'un signal
213 \******************************************************************************/
215 void rcn_flush_signal( lofig_list
*lofig
, losig_list
*losig
)
219 cache
= rcn_getlofigcache( lofig
);
223 mbk_cache_release( cache
, lofig
, losig
);
226 /******************************************************************************\
228 Autorise ou interdit les fonctions de modification des vues RCN de la lofig
230 \******************************************************************************/
232 void rcn_enablewritelofig( lofig_list
*lofig
)
236 for( losig
= lofig
->LOSIG
; losig
; losig
= losig
->NEXT
)
237 rcn_enblewritesignal( losig
);
241 void rcn_disablewritelofig( lofig_list
*lofig
)
245 for( losig
= lofig
->LOSIG
; losig
; losig
= losig
->NEXT
)
246 rcn_disablewritesignal( losig
);
250 /******************************************************************************\
252 Autorise ou interdit les fonctions de modification des losigs
254 \******************************************************************************/
256 void rcn_disablewritesignal( losig_list
*losig
)
259 RCN_SETFLAG( losig
->RCNCACHE
, RCNCACHEFLAG_WF
);
263 void rcn_enblewritesignal( losig_list
*losig
)
266 RCN_CLEARFLAG( losig
->RCNCACHE
, RCNCACHEFLAG_WF
);
270 char rcn_iswritesignal( losig_list
*losig
)
272 if( RCN_GETFLAG( losig
->RCNCACHE
, RCNCACHEFLAG_WF
) )
277 void rcn_checkwritesignal( losig_list
*losig
)
280 if( ! rcn_iswritesignal( losig
) ) {
281 rcn_error( 35, AVT_WARNING
);
287 /******************************************************************************\
289 Indicateurs de l'état d'un signal.
291 \******************************************************************************/
293 void rcn_setsignal_loaded( losig_list
*losig
)
295 RCN_SETFLAG( losig
->RCNCACHE
, RCNCACHEFLAG_LOAD
);
298 void rcn_clearsignal_loaded( losig_list
*losig
)
300 RCN_CLEARFLAG( losig
->RCNCACHE
, RCNCACHEFLAG_LOAD
);
303 char rcn_issignal_loaded( losig_list
*losig
)
305 if( RCN_GETFLAG( losig
->RCNCACHE
, RCNCACHEFLAG_LOAD
) )
310 void rcn_setsignal_disablecache( losig_list
*losig
)
312 RCN_SETFLAG( losig
->RCNCACHE
, RCNCACHEFLAG_DISABLE
);
315 char rcn_issignal_disablecache( losig_list
*losig
)
317 if( RCN_GETFLAG( losig
->RCNCACHE
, RCNCACHEFLAG_DISABLE
) )
322 /******************************************************************************\
324 Fonction appellée par mbk_cache qui libère le signal.
326 \******************************************************************************/
328 unsigned long int rcn_cache_release( lofig_list
*lofig
, losig_list
*losig
)
333 unsigned long int removed
=0;
335 if (rcn_issignal_disablecache(losig
)) return 0;
337 rcn_clearsignal_loaded( losig
);
340 while( losig
->PRCN
->PWIRE
) {
342 losig
->PRCN
->PWIRE
->NODE1
,
343 losig
->PRCN
->PWIRE
->NODE2
345 removed
= removed
+ RCN_SIZEOFLOWIRE
;
348 for( scanctc
= losig
->PRCN
->PCTC
; scanctc
; scanctc
= nextctc
) {
349 nextctc
= scanctc
->NEXT
;
350 ptctc
= (loctc_list
*)(scanctc
->DATA
);
351 if( rcn_cache_removable_ctc( ptctc
) ) {
353 removed
= removed
+ RCN_SIZEOFLOCTC
;
357 lofig
= NULL
; //avoid a warning
362 /******************************************************************************\
364 Lors de l'effacement d'une ctc en raison d'un flush du cache, renvoie 1 si la
365 capacité passée en paramètre peut être retirée, et 0 sinon.
367 \******************************************************************************/
369 char rcn_cache_removable_ctc( loctc_list
*ctc
)
371 if( !rcn_issignal_loaded( ctc
->SIG1
) &&
372 !rcn_issignal_loaded( ctc
->SIG2
) )
377 /******************************************************************************\
379 Lors de l'ajout d'une capacité lors d'un refresh d'un signal, renvoie 1 si il
380 faut ajouter une capacité placée entre les 2 signaux.
382 \******************************************************************************/
384 char rcn_cache_addable_ctc( losig_list
*sig1
, losig_list
*sig2
)
386 if( rcn_issignal_loaded( sig1
) ||
387 rcn_issignal_loaded( sig2
) )
392 /******************************************************************************\
396 \******************************************************************************/
402 str
= getenv("RCN_DEBUG");
405 if( !strcmp( str
, "yes" ) ) {
408 fprintf( stderr
, "\n*** RCN DEBUG MODE enabled ***.\n" );
411 if( !strcmp( str
, "no" ) )
415 fprintf( stderr
, "\n*** warning *** bad value for RCN_DEBUG.\n" );
421 void rcn_cache_debug( lofig_list
*lofig
)
425 unsigned long int size
;
432 cache
= rcn_getlofigcache( lofig
);
436 /* check the cache size */
440 for( losig
= lofig
->LOSIG
; losig
; losig
= losig
->NEXT
) {
444 for( wire
= losig
->PRCN
->PWIRE
; wire
; wire
= wire
->NEXT
)
445 size
+= RCN_SIZEOFLOWIRE
;
447 for( chain
= losig
->PRCN
->PCTC
; chain
; chain
= chain
->NEXT
) {
448 ctc
= (loctc_list
*)chain
->DATA
;
449 if( ctc
->SIG1
== losig
)
450 size
+= RCN_SIZEOFLOCTC
;
454 x
= mbk_cache_getmbkcachelist( cache
, losig
) ;
455 y
= rcn_issignal_loaded( losig
) ;
457 if( (x
&& !y
) || (!x
&& y
) )
458 printf( "error : mismatch cache status for signal %p\n", losig
);
462 if( cache
->CURSIZE
!= size
) {
463 printf( "error : cache->CURSIZE=%lu size=%lu\n", cache
->CURSIZE
, size
);
467 int rcn_hascache( lofig_list
*lofig
)
469 return rcn_getlofigcache( lofig
)!=NULL
;