Beispiel #1
0
void slab_cache_free(slab_cache_t *c, void *obj) {
  spinlock_acquire(&c->lock);
  assert(c->first && "Trying to free from an empty cache!");
  
  slab_footer_t *f = FOOTER_FOR_PTR(obj);

  mark_unused(c, f, obj);

  if (!c->empty || c->empty > obj)
    c->empty = obj;

  if (!f->next && all_unused(c, f)) {
    slab_footer_t *f2 = c->first;
    if (f2 == f) {
      c->first = NULL;
    } else {
      while (f2->next != f)
        f2 = f2->next;
      f2->next = NULL;
    }
    if (FOOTER_FOR_PTR(c->empty) == f)
      c->empty = NULL;
    destroy(c, f);
  }
  spinlock_release(&c->lock);
}
Beispiel #2
0
void freespace_add(freespace* fs, int x0, int y0, int w0, int h0 )
{
    mark_unused(fs->row_buf,        fs->col_buf,
                fs->nat_row_buf,    fs->nat_col_buf,
                fs->blk_row_buf,    fs->blk_col_buf,
                x0,     y0,     w0,     h0);
}
Beispiel #3
0
void dealloc(void *p)
{
    return;
    #ifdef PRINT_DEALLOC_CNT_EACH_TIME
        std::cout<<"DEALLOC CALLED"<<std::endl;
    #endif
    #ifdef NODEF
    if((size_t)p == 0x10)
        std::cout<<"ERR"<<std::endl;
    #endif
//    Buffer *buffer = _buffers;
    Node *cell = find_cell((size_t)p);
    mark_unused(cell);
/*    for(;buffer;buffer = buffer->next)
    {
        for(cell = buffer->cells; cell; cell = cell->next)
        {
            if(cell->offset + buffer->data == p)
            {
                mark_unused(cell);
                break;
            }
        }
    }*/
}
Beispiel #4
0
void freespace_block_add(freespace* fs, int x0, int y0, int w0, int h0 )
{
    int i;

    for (i = 0; i < MAX_BLOCK_AREAS; ++i)
    {
        /* search for existing block which matches */

        if (fs->blklist[i].w
         && fs->blklist[i].x == x0
         && fs->blklist[i].y == y0
         && fs->blklist[i].w == w0
         && fs->blklist[i].h == h0)
        {
            int j;

            fs->blklist[i].w = 0;

            /* set the area to unused space */

            mark_unused(fs->row_buf,        fs->col_buf,
                        fs->blk_row_buf,    fs->blk_col_buf,
                        fs->nat_row_buf,    fs->nat_col_buf,
                        x0,     y0,     w0,     h0);

            /* check for intersections with other blocks */

            for (j = 0; j < MAX_BLOCK_AREAS; ++j)
            {
                if (fs->blklist[j].w == 0)
                    continue;

                if (j == i)
                    continue; /* __ */
                {
                    int ix0 = MAX(fs->blklist[j].x, x0);
                    int iy0 = MAX(fs->blklist[j].y, y0);
                    int ix1 = MIN(x0 + w0,  fs->blklist[j].x
                                          + fs->blklist[j].w);
                    int iy1 = MIN(y0 + h0,  fs->blklist[j].y
                                          + fs->blklist[j].h);

                    if (ix1 > ix0 && iy1 > iy0)
                    {
                        mark_used(  fs->row_buf,        fs->col_buf,
                                    fs->blk_row_buf,    fs->blk_col_buf,
                                    ix0,    iy0,    ix1 - ix0,  iy1 - iy0);
                    }
                }
            }
        }
    }
}
Beispiel #5
0
//! Finds or creates a semaphore with zero counter
interprocess_condition_variable::semaphore_info* interprocess_condition_variable::get_unused_semaphore()
{
    // Be optimistic, check the current semaphore first
    if (m_current_semaphore && m_current_semaphore->m_semaphore.is_zero_count())
    {
        mark_unused(*m_current_semaphore);
        return m_current_semaphore;
    }

    const tick_count_clock::time_point now = tick_count_clock::now();

    semaphore_info_list::iterator it = m_semaphore_info_list.begin(), end = m_semaphore_info_list.end();
    while (it != end)
    {
        if (is_overflow_less(m_next_semaphore_id, it->m_id) || m_next_semaphore_id == it->m_id)
            m_next_semaphore_id = it->m_id + 1u;

        if (it->m_semaphore.is_zero_count())
        {
            semaphore_info& info = *it;
            mark_unused(info);
            return &info;
        }
        else if (it->check_non_zero_timeout(now))
        {
            // The semaphore is non-zero for too long. A blocked process must have crashed. Close it.
            m_semaphore_info_set.erase(m_semaphore_info_set.iterator_to(*it));
            m_semaphore_info_list.erase_and_dispose(it++, boost::checked_deleter< semaphore_info >());
        }
        else
        {
            ++it;
        }
    }

    // No semaphore found, create a new one
    for (uint32_t semaphore_id = m_next_semaphore_id, semaphore_id_end = semaphore_id - 1u; semaphore_id != semaphore_id_end; ++semaphore_id)
    {
        interprocess_semaphore sem;
        try
        {
            generate_semaphore_name(semaphore_id);
            sem.create_or_open(m_semaphore_name.c_str(), m_perms);
            if (!sem.is_zero_count())
                continue;
        }
        catch (...)
        {
            // Ignore errors, try the next one
            continue;
        }

        semaphore_info* p = NULL;
        semaphore_info_set::insert_commit_data insert_state;
        std::pair< semaphore_info_set::iterator, bool > res = m_semaphore_info_set.insert_check(semaphore_id, semaphore_info::order_by_id(), insert_state);
        if (res.second)
        {
            p = new semaphore_info(semaphore_id);
            p->m_semaphore.swap(sem);

            res.first = m_semaphore_info_set.insert_commit(*p, insert_state);
            m_semaphore_info_list.push_back(*p);
        }
        else
        {
            // Some of our currently open semaphores must have been released by another thread
            p = &*res.first;
            mark_unused(*p);
        }

        m_next_semaphore_id = semaphore_id + 1u;

        return p;
    }

    BOOST_LOG_THROW_DESCR(limitation_error, "Too many semaphores are actively used for an interprocess condition variable");
    BOOST_LOG_UNREACHABLE_RETURN(NULL);
}