コード例 #1
0
ファイル: priority_queue.c プロジェクト: andrecunha/AAI-Codec
void pq_insert (priority_queue *pq, NODE_TYPE *node)
{
	pq->size++;
	int i = pq->size-1;

	while ((i>0) && (pq_get_priority(pq->nodes[parent(i)]) > pq_get_priority(node))) {
		pq->nodes[i] = pq->nodes[parent(i)];
		i = parent(i);
	}

	pq->nodes[i] = node;
}
コード例 #2
0
ファイル: priority_queue.c プロジェクト: andrecunha/AAI-Codec
int min (priority_queue *pq, int a, int b, int c)
{
	int small;
	if (b < pq->size && pq_get_priority(pq->nodes[b]) < pq_get_priority(pq->nodes[a]))
		small = b;
	else
		small = a;

	if (c < pq->size && pq_get_priority(pq->nodes[small]) > pq_get_priority(pq->nodes[c]))
		small = c;

	return small;
}
コード例 #3
0
/* Called on uthread_create(). Must assign the new uthread to a kthread;
 * anything else is left up to the implementation. Can't assume the uthread
 * itself has been initialized in any way---it just has a tid
 */
kthread_t *pcs_uthread_init(uthread_t *uthread)
{
	checkpoint("u%d: PCS: init uthread", uthread->tid);

	pcs_data_t *pcs_data = SCHED_DATA;
	gt_spin_lock(&pcs_data->lock);

	pcs_uthread_t *pcs_uthread = pcs_pcs_uthread_create(uthread);
	pcs_uthread->uthread = uthread;
	pcs_uthread->priority = pq_get_priority(uthread);
	pcs_uthread->group_id = pq_get_group_id(uthread);

	pcs_kthread_t *pcs_kthread = pcs_find_kthread_target(pcs_uthread,
	                                                     pcs_data);
	add_to_runqueue(pcs_kthread->k_runqueue.active_runq,
	                &pcs_kthread->k_runqueue.kthread_runqlock,
	                pcs_uthread);
	gt_spin_unlock(&pcs_data->lock);
	assert(pcs_kthread != NULL);
	assert(pcs_kthread->k_ctx != NULL);
	return pcs_kthread->k_ctx;
}