Subversion Repositories HelenOS-historic

Rev

Rev 772 | Rev 775 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 772 Rev 773
Line 384... Line 384...
384
 
384
 
385
/**
385
/**
386
 * Assure that the current magazine is empty, return pointer to it, or NULL if
386
 * Assure that the current magazine is empty, return pointer to it, or NULL if
387
 * no empty magazine is available and cannot be allocated
387
 * no empty magazine is available and cannot be allocated
388
 *
388
 *
-
 
389
 * Assume mag_cache[CPU->id].lock is held
-
 
390
 *
389
 * We have 2 magazines bound to processor.
391
 * We have 2 magazines bound to processor.
390
 * First try the current.
392
 * First try the current.
391
 *  If full, try the last.
393
 *  If full, try the last.
392
 *   If full, put to magazines list.
394
 *   If full, put to magazines list.
393
 *   allocate new, exchange last & current
395
 *   allocate new, exchange last & current
Line 418... Line 420...
418
        return NULL;
420
        return NULL;
419
    newmag->size = SLAB_MAG_SIZE;
421
    newmag->size = SLAB_MAG_SIZE;
420
    newmag->busy = 0;
422
    newmag->busy = 0;
421
 
423
 
422
    /* Flush last to magazine list */
424
    /* Flush last to magazine list */
423
    if (lastmag)
425
    if (lastmag) {
-
 
426
        spinlock_lock(&cache->lock);
424
        list_prepend(&lastmag->link, &cache->magazines);
427
        list_prepend(&lastmag->link, &cache->magazines);
-
 
428
        spinlock_unlock(&cache->lock);
-
 
429
    }
425
    /* Move current as last, save new as current */
430
    /* Move current as last, save new as current */
426
    cache->mag_cache[CPU->id].last = cmag; 
431
    cache->mag_cache[CPU->id].last = cmag; 
427
    cache->mag_cache[CPU->id].current = newmag;
432
    cache->mag_cache[CPU->id].current = newmag;
428
 
433
 
429
    return newmag;
434
    return newmag;
Line 511... Line 516...
511
    list_initialize(&cache->full_slabs);
516
    list_initialize(&cache->full_slabs);
512
    list_initialize(&cache->partial_slabs);
517
    list_initialize(&cache->partial_slabs);
513
    list_initialize(&cache->magazines);
518
    list_initialize(&cache->magazines);
514
    spinlock_initialize(&cache->lock, "cachelock");
519
    spinlock_initialize(&cache->lock, "cachelock");
515
    if (! (cache->flags & SLAB_CACHE_NOMAGAZINE)) {
520
    if (! (cache->flags & SLAB_CACHE_NOMAGAZINE)) {
516
        for (i=0; i< config.cpu_count; i++) {
521
        for (i=0; i < config.cpu_count; i++) {
517
            memsetb((__address)&cache->mag_cache[i],
522
            memsetb((__address)&cache->mag_cache[i],
518
                sizeof(cache->mag_cache[i]), 0);
523
                sizeof(cache->mag_cache[i]), 0);
519
            spinlock_initialize(&cache->mag_cache[i].lock,
524
            spinlock_initialize(&cache->mag_cache[i].lock,
520
                        "cpucachelock");
525
                        "cpucachelock");
521
        }
526
        }
Line 647... Line 652...
647
    memory */
652
    memory */
648
void * slab_alloc(slab_cache_t *cache, int flags)
653
void * slab_alloc(slab_cache_t *cache, int flags)
649
{
654
{
650
    ipl_t ipl;
655
    ipl_t ipl;
651
    void *result = NULL;
656
    void *result = NULL;
652
 
657
   
653
    /* Disable interrupts to avoid deadlocks with interrupt handlers */
658
    /* Disable interrupts to avoid deadlocks with interrupt handlers */
654
    ipl = interrupts_disable();
659
    ipl = interrupts_disable();
655
 
660
 
656
    if (!(cache->flags & SLAB_CACHE_NOMAGAZINE))
661
    if (!(cache->flags & SLAB_CACHE_NOMAGAZINE))
657
        result = magazine_obj_get(cache);
662
        result = magazine_obj_get(cache);