comparison src/xgccache.c @ 5118:e0db3c197671 ben-lisp-object

merge up to latest default branch, doesn't compile yet
author Ben Wing <ben@xemacs.org>
date Sat, 26 Dec 2009 21:18:49 -0600
parents ea87f3f1e3ff
children b3ce27ca7647
comparison
equal deleted inserted replaced
5117:3742ea8250b5 5118:e0db3c197671
156 gc_cache_lookup (struct gc_cache *cache, XGCValues *gcv, unsigned long mask) 156 gc_cache_lookup (struct gc_cache *cache, XGCValues *gcv, unsigned long mask)
157 { 157 {
158 struct gc_cache_cell *cell, *next, *prev; 158 struct gc_cache_cell *cell, *next, *prev;
159 struct gcv_and_mask gcvm; 159 struct gcv_and_mask gcvm;
160 160
161 #ifdef DEBUG_XEMACS
162 (void) describe_gc_cache (cache, DGCCFLAG_DISABLE);
163 #endif
164
161 if ((!!cache->head) != (!!cache->tail)) ABORT (); 165 if ((!!cache->head) != (!!cache->tail)) ABORT ();
162 if (cache->head && (cache->head->prev || cache->tail->next)) ABORT (); 166 if (cache->head && (cache->head->prev || cache->tail->next)) ABORT ();
163 167
164 gcvm.mask = mask; 168 gcvm.mask = mask;
165 gcvm.gcv = *gcv; /* this copies... */ 169 gcvm.gcv = *gcv; /* this copies... */
194 { 198 {
195 /* Found a cell. Move this cell to the end of the list, so that it 199 /* Found a cell. Move this cell to the end of the list, so that it
196 will be less likely to be collected than a cell that was accessed 200 will be less likely to be collected than a cell that was accessed
197 less recently. 201 less recently.
198 */ 202 */
203 #if 0
204 debug_out ("Returning cached GC: %08lx\n", XE_GCONTEXT(cell));
205 #endif
199 if (cell == cache->tail) 206 if (cell == cache->tail)
200 return cell->gc; 207 return cell->gc;
201 208
202 next = cell->next; 209 next = cell->next;
203 prev = cell->prev; 210 prev = cell->prev;
224 { 231 {
225 cell = cache->head; 232 cell = cache->head;
226 cache->head = cell->next; 233 cache->head = cell->next;
227 cache->head->prev = 0; 234 cache->head->prev = 0;
228 if (cache->tail == cell) cache->tail = 0; /* only one */ 235 if (cache->tail == cell) cache->tail = 0; /* only one */
236 #if 0
237 debug_out ("Cache full, freeing GC: %08lx\n ", XE_GCONTEXT(cell));
238 #endif
229 XFreeGC (cache->dpy, cell->gc); 239 XFreeGC (cache->dpy, cell->gc);
230 cache->delete_count++; 240 cache->delete_count++;
231 #ifdef GCCACHE_HASH 241 #ifdef GCCACHE_HASH
232 remhash (&cell->gcvm, cache->table); 242 remhash (&cell->gcvm, cache->table);
233 #endif 243 #endif
262 cell->gc = XCreateGC (cache->dpy, cache->window, mask, gcv); 272 cell->gc = XCreateGC (cache->dpy, cache->window, mask, gcv);
263 273
264 /* debug */ 274 /* debug */
265 assert (cell->gc == gc_cache_lookup (cache, gcv, mask)); 275 assert (cell->gc == gc_cache_lookup (cache, gcv, mask));
266 276
277 #if 0
278 debug_out ("Returning new GC: %08lx\n ", XE_GCONTEXT(cell));
279 #endif
267 return cell->gc; 280 return cell->gc;
268 } 281 }
269 282
270 283
271 #ifdef DEBUG_XEMACS 284 #ifdef DEBUG_XEMACS
272 285
273 void describe_gc_cache (struct gc_cache *cache); 286 /* FLAGS
287 The flags argument is a bitwise or of any of the following:
288
289 DGCCFLAG_SUMMARY Summary statistics for cache
290 DGCCFLAG_LIST_CELLS If summary is being printed, print cell IDs too.
291 DGCCFLAG_CELL_DETAILS If cell IDs are being printed, additionally
292 print the internal fields used and values.
293
294 DGCCFLAG_DEFAULT A predefined combination giving whatever the
295 maintainers are currently interested in seeing.
296 */
274 void 297 void
275 describe_gc_cache (struct gc_cache *cache) 298 describe_gc_cache (struct gc_cache *cache, int flags)
276 { 299 {
277 int count = 0; 300 int count = 0;
278 struct gc_cache_cell *cell = cache->head; 301 struct gc_cache_cell *cell = cache->head;
302
303 if (! flags & DGCCFLAG_SUMMARY) return;
304
279 stderr_out ("\nsize: %d", cache->size); 305 stderr_out ("\nsize: %d", cache->size);
280 stderr_out ("\ncreated: %d", cache->create_count); 306 stderr_out ("\ncreated: %d", cache->create_count);
281 stderr_out ("\ndeleted: %d", cache->delete_count); 307 stderr_out ("\ndeleted: %d", cache->delete_count);
282 while (cell) 308
283 { 309 if (flags & DGCCFLAG_LIST_CELLS)
284 struct gc_cache_cell *cell2; 310 while (cell)
285 int i = 0; 311 {
286 stderr_out ("\n%d:\t0x%lx GC: 0x%08lx hash: 0x%08lx\n", 312 struct gc_cache_cell *cell2;
287 count, (long) cell, (long) cell->gc, gc_cache_hash (&cell->gcvm)); 313 int i = 0;
288 for (cell2 = cache->head; cell2; cell2 = cell2->next, i++) 314 stderr_out ("\n%d:\t0x%lx GC: 0x%08lx hash: 0x%08lx\n",
289 if (count != i && 315 count, (long) cell, (long) XE_GCONTEXT(cell),
290 gc_cache_hash (&cell->gcvm) == gc_cache_hash (&cell2->gcvm)) 316 gc_cache_hash (&cell->gcvm));
291 stderr_out ("\tHASH COLLISION with cell %d\n", i); 317
292 stderr_out ("\tmask: %8lx\n", cell->gcvm.mask); 318 for (cell2 = cache->head; cell2; cell2 = cell2->next, i++)
293 319 if (count != i &&
320 gc_cache_hash (&cell->gcvm) == gc_cache_hash (&cell2->gcvm))
321 stderr_out ("\tHASH COLLISION with cell %d\n", i);
322 stderr_out ("\tmask: %8lx\n", cell->gcvm.mask);
323
324 if (flags & DGCCFLAG_CELL_DETAILS)
325 {
294 #define FROB(field) do { \ 326 #define FROB(field) do { \
295 if ((int)cell->gcvm.gcv.field != (~0)) \ 327 if ((int)cell->gcvm.gcv.field != (~0)) \
296 stderr_out ("\t%-12s%8x\n", #field ":", (int)cell->gcvm.gcv.field); \ 328 stderr_out ("\t%-12s%8x\n", #field ":", (int)cell->gcvm.gcv.field); \
297 } while (0) 329 } while (0)
298 FROB (function); 330 FROB (function);
299 FROB (plane_mask); 331 FROB (plane_mask);
300 FROB (foreground); 332 FROB (foreground);
301 FROB (background); 333 FROB (background);
302 FROB (line_width); 334 FROB (line_width);
303 FROB (line_style); 335 FROB (line_style);
304 FROB (cap_style); 336 FROB (cap_style);
305 FROB (join_style); 337 FROB (join_style);
306 FROB (fill_style); 338 FROB (fill_style);
307 FROB (fill_rule); 339 FROB (fill_rule);
308 FROB (arc_mode); 340 FROB (arc_mode);
309 FROB (tile); 341 FROB (tile);
310 FROB (stipple); 342 FROB (stipple);
311 FROB (ts_x_origin); 343 FROB (ts_x_origin);
312 FROB (ts_y_origin); 344 FROB (ts_y_origin);
313 FROB (font); 345 FROB (font);
314 FROB (subwindow_mode); 346 FROB (subwindow_mode);
315 FROB (graphics_exposures); 347 FROB (graphics_exposures);
316 FROB (clip_x_origin); 348 FROB (clip_x_origin);
317 FROB (clip_y_origin); 349 FROB (clip_y_origin);
318 FROB (clip_mask); 350 FROB (clip_mask);
319 FROB (dash_offset); 351 FROB (dash_offset);
320 #undef FROB 352 #undef FROB
321 353 }
322 count++; 354
323 if (cell->next && cell == cache->tail) 355 count++;
324 stderr_out ("\nERROR! tail is here!\n\n"); 356 if (cell->next && cell == cache->tail)
325 else if (!cell->next && cell != cache->tail) 357 stderr_out ("\nERROR! tail is here!\n\n");
326 stderr_out ("\nERROR! tail is not at the end\n\n"); 358 else if (!cell->next && cell != cache->tail)
327 cell = cell->next; 359 stderr_out ("\nERROR! tail is not at the end\n\n");
328 } 360 cell = cell->next;
361 } /* while (cell) */
362
329 if (count != cache->size) 363 if (count != cache->size)
330 stderr_out ("\nERROR! count should be %d\n\n", cache->size); 364 stderr_out ("\nERROR! count should be %d\n\n", cache->size);
331 } 365 }
332 366
333 #endif /* DEBUG_XEMACS */ 367 #endif /* DEBUG_XEMACS */