Rev 771 | Rev 773 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 771 | Rev 772 | ||
---|---|---|---|
Line 363... | Line 363... | ||
363 | static void * magazine_obj_get(slab_cache_t *cache) |
363 | static void * magazine_obj_get(slab_cache_t *cache) |
364 | { |
364 | { |
365 | slab_magazine_t *mag; |
365 | slab_magazine_t *mag; |
366 | void *obj; |
366 | void *obj; |
367 | 367 | ||
- | 368 | if (!CPU) |
|
- | 369 | return NULL; |
|
- | 370 | ||
368 | spinlock_lock(&cache->mag_cache[CPU->id].lock); |
371 | spinlock_lock(&cache->mag_cache[CPU->id].lock); |
369 | 372 | ||
370 | mag = get_full_current_mag(cache); |
373 | mag = get_full_current_mag(cache); |
371 | if (!mag) { |
374 | if (!mag) { |
372 | spinlock_unlock(&cache->mag_cache[CPU->id].lock); |
375 | spinlock_unlock(&cache->mag_cache[CPU->id].lock); |
Line 433... | Line 436... | ||
433 | */ |
436 | */ |
434 | static int magazine_obj_put(slab_cache_t *cache, void *obj) |
437 | static int magazine_obj_put(slab_cache_t *cache, void *obj) |
435 | { |
438 | { |
436 | slab_magazine_t *mag; |
439 | slab_magazine_t *mag; |
437 | 440 | ||
- | 441 | if (!CPU) |
|
- | 442 | return -1; |
|
- | 443 | ||
438 | spinlock_lock(&cache->mag_cache[CPU->id].lock); |
444 | spinlock_lock(&cache->mag_cache[CPU->id].lock); |
439 | 445 | ||
440 | mag = make_empty_current_mag(cache); |
446 | mag = make_empty_current_mag(cache); |
441 | if (!mag) { |
447 | if (!mag) { |
442 | spinlock_unlock(&cache->mag_cache[CPU->id].lock); |
448 | spinlock_unlock(&cache->mag_cache[CPU->id].lock); |
Line 505... | Line 511... | ||
505 | list_initialize(&cache->full_slabs); |
511 | list_initialize(&cache->full_slabs); |
506 | list_initialize(&cache->partial_slabs); |
512 | list_initialize(&cache->partial_slabs); |
507 | list_initialize(&cache->magazines); |
513 | list_initialize(&cache->magazines); |
508 | spinlock_initialize(&cache->lock, "cachelock"); |
514 | spinlock_initialize(&cache->lock, "cachelock"); |
509 | if (! (cache->flags & SLAB_CACHE_NOMAGAZINE)) { |
515 | if (! (cache->flags & SLAB_CACHE_NOMAGAZINE)) { |
510 | for (i=0; i< config.cpu_count; i++) |
516 | for (i=0; i< config.cpu_count; i++) { |
- | 517 | memsetb((__address)&cache->mag_cache[i], |
|
- | 518 | sizeof(cache->mag_cache[i]), 0); |
|
511 | spinlock_initialize(&cache->mag_cache[i].lock, |
519 | spinlock_initialize(&cache->mag_cache[i].lock, |
512 | "cpucachelock"); |
520 | "cpucachelock"); |
- | 521 | } |
|
513 | } |
522 | } |
514 | 523 | ||
515 | /* Compute slab sizes, object counts in slabs etc. */ |
524 | /* Compute slab sizes, object counts in slabs etc. */ |
516 | if (cache->size < SLAB_INSIDE_SIZE) |
525 | if (cache->size < SLAB_INSIDE_SIZE) |
517 | cache->flags |= SLAB_CACHE_SLINSIDE; |
526 | cache->flags |= SLAB_CACHE_SLINSIDE; |
Line 642... | Line 651... | ||
642 | void *result = NULL; |
651 | void *result = NULL; |
643 | 652 | ||
644 | /* Disable interrupts to avoid deadlocks with interrupt handlers */ |
653 | /* Disable interrupts to avoid deadlocks with interrupt handlers */ |
645 | ipl = interrupts_disable(); |
654 | ipl = interrupts_disable(); |
646 | 655 | ||
647 | if (!(cache->flags & SLAB_CACHE_NOMAGAZINE) && CPU) |
656 | if (!(cache->flags & SLAB_CACHE_NOMAGAZINE)) |
648 | result = magazine_obj_get(cache); |
657 | result = magazine_obj_get(cache); |
649 | 658 | ||
650 | if (!result) { |
659 | if (!result) { |
651 | spinlock_lock(&cache->lock); |
660 | spinlock_lock(&cache->lock); |
652 | result = slab_obj_create(cache, flags); |
661 | result = slab_obj_create(cache, flags); |
Line 667... | Line 676... | ||
667 | ipl_t ipl; |
676 | ipl_t ipl; |
668 | 677 | ||
669 | ipl = interrupts_disable(); |
678 | ipl = interrupts_disable(); |
670 | 679 | ||
671 | if ((cache->flags & SLAB_CACHE_NOMAGAZINE) \ |
680 | if ((cache->flags & SLAB_CACHE_NOMAGAZINE) \ |
672 | || !CPU \ |
- | |
673 | || magazine_obj_put(cache, obj)) { |
681 | || magazine_obj_put(cache, obj)) { |
674 | - | ||
675 | spinlock_lock(&cache->lock); |
682 | spinlock_lock(&cache->lock); |
676 | slab_obj_destroy(cache, obj, slab); |
683 | slab_obj_destroy(cache, obj, slab); |
677 | spinlock_unlock(&cache->lock); |
684 | spinlock_unlock(&cache->lock); |
678 | } |
685 | } |
679 | interrupts_restore(ipl); |
686 | interrupts_restore(ipl); |