Beispiel #1
0
/*!
 * Destroy semaphore object
 * \param sem Semaphore descriptor (user level descriptor)
 * \return 0 if successful, -1 otherwise and appropriate error number is set
 */
int sys__sem_destroy ( void *p )
{
	sem_t *sem;

	ksem_t *ksem;
	kobject_t *kobj;

	sem = *( (sem_t **) p );

	ASSERT_ERRNO_AND_EXIT ( sem, EINVAL );

	kobj = sem->ptr;
	ASSERT_ERRNO_AND_EXIT ( kobj, EINVAL );
	ASSERT_ERRNO_AND_EXIT ( list_find ( &kobjects, &kobj->list ),
				EINVAL );
	ksem = kobj->kobject;
	ASSERT_ERRNO_AND_EXIT ( ksem && ksem->id == sem->id, EINVAL );

	ASSERT_ERRNO_AND_EXIT (kthreadq_get (&ksem->queue) == NULL, ENOTEMPTY);

	ksem->ref_cnt--;

	/* additional cleanup here (e.g. if semaphore is shared leave it) */
	if ( ksem->ref_cnt )
		EXIT2 ( EBUSY, EXIT_FAILURE );

	kfree_kobject ( kobj );

	sem->ptr = NULL;
	sem->id = 0;

	EXIT2 ( EXIT_SUCCESS, EXIT_SUCCESS );
}
Beispiel #2
0
/*!
 * Destroy conditional variable object
 * \param cond conditional variable descriptor (user level descriptor)
 * \return 0 if successful, -1 otherwise and appropriate error number is set
 */
int sys__pthread_cond_destroy ( void *p )
{
	pthread_cond_t *cond;

	kpthread_cond_t *kcond;
	kobject_t *kobj;

	cond = *( (pthread_cond_t **) p );
	ASSERT_ERRNO_AND_EXIT ( cond, EINVAL );

	kobj = cond->ptr;
	ASSERT_ERRNO_AND_EXIT ( kobj, EINVAL );
	ASSERT_ERRNO_AND_EXIT ( list_find ( &kobjects, &kobj->list ),
				EINVAL );
	kcond = kobj->kobject;
	ASSERT_ERRNO_AND_EXIT ( kcond && kcond->id == cond->id, EINVAL );

	kcond->ref_cnt--;

	/* additional cleanup here (e.g. if cond.var. is shared leave it) */
	if ( kcond->ref_cnt )
		EXIT2 ( EBUSY, EXIT_FAILURE );

	kfree_kobject ( kobj );

	cond->ptr = NULL;
	cond->id = 0;

	EXIT2 ( EXIT_SUCCESS, EXIT_SUCCESS );
}
Beispiel #3
0
/*!
 * Delete timer
 * \param timerid	Timer descriptor (user descriptor)
 * \return status	0 for success
 */
int sys__timer_delete ( void *p )
{
	timer_t *timerid;

	ktimer_t *ktimer;
	int retval;
	kobject_t *kobj;

	timerid = *( (timer_t **) p );

	ASSERT_ERRNO_AND_EXIT ( timerid, EINVAL );
	kobj = timerid->ptr;
	ASSERT_ERRNO_AND_EXIT ( kobj, EINVAL );
	ASSERT_ERRNO_AND_EXIT ( list_find ( &kobjects, &kobj->list ),
				EINVAL );

	ktimer = kobj->kobject;
	ASSERT_ERRNO_AND_EXIT ( ktimer && ktimer->id == timerid->id, EINVAL );

	retval = ktimer_delete ( ktimer );

	kfree_kobject ( kobj );

	EXIT ( retval );
}
Beispiel #4
0
/*!
 * Close a message queue
 * \param mqdes Queue descriptor address (user level descriptor)
 * \return 0 if successful, -1 otherwise and appropriate error number is set
 */
int sys__mq_close ( void *p )
{
	mqd_t *mqdes;

	kmq_queue_t *kq_queue;
	kobject_t *kobj;
	kmq_msg_t *kmq_msg;
	kthread_t *kthread;

	mqdes = *( (mqd_t **) p );

	ASSERT_ERRNO_AND_EXIT ( mqdes, EBADF );

	kobj = mqdes->ptr;
	ASSERT_ERRNO_AND_EXIT ( kobj, EBADF );
	ASSERT_ERRNO_AND_EXIT ( list_find ( &kobjects, &kobj->list ),
				EBADF );

	kq_queue = kobj->kobject;
	kq_queue = list_find_and_remove ( &kmq_queue, &kq_queue->list );

	if ( !kq_queue || kq_queue->id != mqdes->id )
		EXIT2 ( EBADF, EXIT_FAILURE );

	kq_queue->ref_cnt--;

	if ( !kq_queue->ref_cnt )
	{
		/* remove messages */
		while( (kmq_msg = list_remove(&kq_queue->msg_list,FIRST,NULL)) )
			kfree (kmq_msg);

		/* remove blocked threads */
		while ( (kthread = kthreadq_remove (&kq_queue->send_q, NULL)) )
		{
			kthread_move_to_ready ( kthread, LAST );
			kthread_set_errno ( kthread, EBADF );
			kthread_set_syscall_retval ( kthread, EXIT_FAILURE );
		}
		while ( (kthread = kthreadq_remove (&kq_queue->recv_q, NULL)) )
		{
			kthread_move_to_ready ( kthread, LAST );
			kthread_set_errno ( kthread, EBADF );
			kthread_set_syscall_retval ( kthread, EXIT_FAILURE );
		}

		list_remove ( &kmq_queue, 0, &kq_queue->list );
		k_free_id ( kq_queue->id );
		kfree ( kq_queue->name );
		kfree ( kq_queue );
	}

	/* remove kernel object descriptor */
	kfree_kobject ( kobj );

	EXIT2 ( EXIT_SUCCESS, EXIT_SUCCESS );
}
Beispiel #5
0
/*!
 * Destroy mutex object
 * \param mutex Mutex descriptor (user level descriptor)
 * \return 0 if successful, -1 otherwise and appropriate error number is set
 */
int sys__pthread_mutex_destroy ( void *p )
{
	pthread_mutex_t *mutex;

	kpthread_mutex_t *kmutex;
	kobject_t *kobj;

	mutex = *( (pthread_mutex_t **) p );
	ASSERT_ERRNO_AND_EXIT ( mutex, EINVAL );

	kobj = mutex->ptr;
	ASSERT_ERRNO_AND_EXIT ( kobj, EINVAL );
	ASSERT_ERRNO_AND_EXIT ( list_find ( &kobjects, &kobj->list ),
				EINVAL );

	kmutex = kobj->kobject;
	ASSERT_ERRNO_AND_EXIT ( kmutex && kmutex->id == mutex->id, EINVAL );

	ASSERT_ERRNO_AND_EXIT (
		kmutex->owner == NULL /* mutex locked! */ &&
		kthreadq_get ( &kmutex->queue ) == NULL,
		ENOTEMPTY
	);

	kmutex->ref_cnt--;

	/* additional cleanup here (e.g. if mutex is shared leave it) */
	if ( kmutex->ref_cnt )
		EXIT2 ( EBUSY, EXIT_FAILURE );

	kfree_kobject ( kobj );

	mutex->ptr = NULL;
	mutex->id = 0;

	EXIT2 ( EXIT_SUCCESS, EXIT_SUCCESS );
}