Lines Matching refs:pool
645 idm_idpool_t *pool) in idm_idpool_increment() argument
650 ASSERT(pool->id_magic == IDM_IDPOOL_MAGIC); in idm_idpool_increment()
652 new_size = pool->id_size * 2; in idm_idpool_increment()
657 bcopy(pool->id_pool, new_pool, pool->id_size / 8); in idm_idpool_increment()
658 kmem_free(pool->id_pool, pool->id_size / 8); in idm_idpool_increment()
659 pool->id_pool = new_pool; in idm_idpool_increment()
660 pool->id_free_counter += new_size - pool->id_size; in idm_idpool_increment()
661 pool->id_max_free_counter += new_size - pool->id_size; in idm_idpool_increment()
662 pool->id_size = new_size; in idm_idpool_increment()
663 pool->id_idx_msk = (new_size / 8) - 1; in idm_idpool_increment()
666 pool->id_pool[pool->id_idx_msk] = 0x80; in idm_idpool_increment()
667 pool->id_free_counter--; in idm_idpool_increment()
668 pool->id_max_free_counter--; in idm_idpool_increment()
683 idm_idpool_create(idm_idpool_t *pool) in idm_idpool_create() argument
686 ASSERT(pool->id_magic != IDM_IDPOOL_MAGIC); in idm_idpool_create()
688 pool->id_size = IDM_IDPOOL_MIN_SIZE; in idm_idpool_create()
689 pool->id_idx_msk = (IDM_IDPOOL_MIN_SIZE / 8) - 1; in idm_idpool_create()
690 pool->id_free_counter = IDM_IDPOOL_MIN_SIZE - 1; in idm_idpool_create()
691 pool->id_max_free_counter = IDM_IDPOOL_MIN_SIZE - 1; in idm_idpool_create()
692 pool->id_bit = 0x02; in idm_idpool_create()
693 pool->id_bit_idx = 1; in idm_idpool_create()
694 pool->id_idx = 0; in idm_idpool_create()
695 pool->id_pool = (uint8_t *)kmem_alloc((IDM_IDPOOL_MIN_SIZE / 8), in idm_idpool_create()
697 bzero(pool->id_pool, (IDM_IDPOOL_MIN_SIZE / 8)); in idm_idpool_create()
699 pool->id_pool[0] = 0x01; /* id 0 made unavailable */ in idm_idpool_create()
700 mutex_init(&pool->id_mutex, NULL, MUTEX_DEFAULT, NULL); in idm_idpool_create()
701 pool->id_magic = IDM_IDPOOL_MAGIC; in idm_idpool_create()
713 idm_idpool_destroy(idm_idpool_t *pool) in idm_idpool_destroy() argument
715 ASSERT(pool->id_magic == IDM_IDPOOL_MAGIC); in idm_idpool_destroy()
716 ASSERT(pool->id_free_counter == pool->id_max_free_counter); in idm_idpool_destroy()
717 pool->id_magic = (uint32_t)~IDM_IDPOOL_MAGIC; in idm_idpool_destroy()
718 mutex_destroy(&pool->id_mutex); in idm_idpool_destroy()
719 kmem_free(pool->id_pool, (size_t)(pool->id_size / 8)); in idm_idpool_destroy()
728 idm_idpool_alloc(idm_idpool_t *pool, uint16_t *id) in idm_idpool_alloc() argument
735 ASSERT(pool->id_magic == IDM_IDPOOL_MAGIC); in idm_idpool_alloc()
737 mutex_enter(&pool->id_mutex); in idm_idpool_alloc()
738 if ((pool->id_free_counter == 0) && idm_idpool_increment(pool)) { in idm_idpool_alloc()
739 mutex_exit(&pool->id_mutex); in idm_idpool_alloc()
743 i = pool->id_size; in idm_idpool_alloc()
745 bit = pool->id_bit; in idm_idpool_alloc()
746 bit_idx = pool->id_bit_idx; in idm_idpool_alloc()
747 byte = pool->id_pool[pool->id_idx]; in idm_idpool_alloc()
754 pool->id_pool[pool->id_idx] |= bit; in idm_idpool_alloc()
755 *id = (uint16_t)(pool->id_idx * 8 + (uint32_t)bit_idx); in idm_idpool_alloc()
756 pool->id_free_counter--; in idm_idpool_alloc()
757 pool->id_bit = bit; in idm_idpool_alloc()
758 pool->id_bit_idx = bit_idx; in idm_idpool_alloc()
759 mutex_exit(&pool->id_mutex); in idm_idpool_alloc()
762 pool->id_bit = 1; in idm_idpool_alloc()
763 pool->id_bit_idx = 0; in idm_idpool_alloc()
764 pool->id_idx++; in idm_idpool_alloc()
765 pool->id_idx &= pool->id_idx_msk; in idm_idpool_alloc()
773 mutex_exit(&pool->id_mutex); in idm_idpool_alloc()
783 idm_idpool_free(idm_idpool_t *pool, uint16_t id) in idm_idpool_free() argument
785 ASSERT(pool->id_magic == IDM_IDPOOL_MAGIC); in idm_idpool_free()
789 mutex_enter(&pool->id_mutex); in idm_idpool_free()
790 if (pool->id_pool[id >> 3] & (1 << (id & 7))) { in idm_idpool_free()
791 pool->id_pool[id >> 3] &= ~(1 << (id & 7)); in idm_idpool_free()
792 pool->id_free_counter++; in idm_idpool_free()
793 ASSERT(pool->id_free_counter <= pool->id_max_free_counter); in idm_idpool_free()
794 mutex_exit(&pool->id_mutex); in idm_idpool_free()
799 mutex_exit(&pool->id_mutex); in idm_idpool_free()