Example #1
0
void HeapContainer<NodeType,CostType,PlannerSpecificVariables>::push 
									( SearchGraphNode<NodeType,CostType,PlannerSpecificVariables>* np, 
										SearchGraphNode<NodeType,CostType,PlannerSpecificVariables>* searchStart )
{
	if (!start && !end) // empty list
	{
		key_init(np);
		start = np;
		end = np;
		heap_size = 1;
	}
	else
	{
		heapItem_p pointer;
		if (searchStart)
			pointer = searchStart;
		else
			pointer = key_find(np->f);
		
		while (true)
		{
			// found position at the beginning
			if ( pointer->f <= np->f && !pointer->prev )
			{
				start->prev = np;
				np->nxt = start;
				start = np;
				break;
			}
			// found position at the middle
			if ( pointer->f <= np->f && pointer->prev->f >= np->f )
			{
				np->prev = pointer->prev;
				np->nxt = pointer;
				pointer->prev->nxt = np;
				pointer->prev = np;
				break;
			}
			// found position at the end
			if ( pointer->f >= np->f && !pointer->nxt )
			{
				end->nxt = np;
				np->prev = end;
				end = np;
				break;
			}
			
			if ( pointer->f <= np->f )
				pointer = pointer->prev;
			else if ( pointer->f > np->f )
				pointer = pointer->nxt;
		}
		
		np->inHeap = true;
		heap_size++;
		key_update(np);
	}
}
Example #2
0
/*
 * update a key's data payload
 * - the key must be writable
 * - implements keyctl(KEYCTL_UPDATE)
 */
long keyctl_update_key(key_serial_t id,
		       const void __user *_payload,
		       size_t plen)
{
	key_ref_t key_ref;
	void *payload;
	long ret;

	ret = -EINVAL;
	if (plen > PAGE_SIZE)
		goto error;

	/* pull the payload in if one was supplied */
	payload = NULL;
	if (_payload) {
		ret = -ENOMEM;
		payload = kmalloc(plen, GFP_KERNEL);
		if (!payload)
			goto error;

		ret = -EFAULT;
		if (copy_from_user(payload, _payload, plen) != 0)
			goto error2;
	}

	/* find the target key (which must be writable) */
	key_ref = lookup_user_key(NULL, id, 0, 0, KEY_WRITE);
	if (IS_ERR(key_ref)) {
		ret = PTR_ERR(key_ref);
		goto error2;
	}

	/* update the key */
	ret = key_update(key_ref, payload, plen);

	key_ref_put(key_ref);
 error2:
	kfree(payload);
 error:
	return ret;

} /* end keyctl_update_key() */
Example #3
0
static key_t key_getkey(void)
{
	key_update();
	return key;
}