示例#1
0
文件: pthread.c 项目: l30nard0/Benu
/*!
 * Initialize conditional variable object
 * \param cond conditional variable descriptor (user level descriptor)
 * \param condattr conditional variable descriptor (user level descriptor)
 * \return 0 if successful, -1 otherwise and appropriate error number is set
 */
int sys__pthread_cond_init ( void *p )
{
	pthread_cond_t *cond;
	/* pthread_condattr_t *condattr; not implemented */

	kpthread_cond_t *kcond;
	kobject_t *kobj;

	cond = *( (pthread_cond_t **) p ); /* p += sizeof (pthread_cond_t *);
	condattr = *( (pthread_condattr_t *) p ); */

	ASSERT_ERRNO_AND_EXIT ( cond, EINVAL );

	kobj = kmalloc_kobject ( sizeof (kpthread_cond_t) );
	ASSERT_ERRNO_AND_EXIT ( kobj, ENOMEM );
	kcond = kobj->kobject;

	kcond->id = k_new_id ();
	kcond->flags = 0;
	kcond->ref_cnt = 1;
	kthreadq_init ( &kcond->queue );

	cond->ptr = kobj;
	cond->id = kcond->id;

	EXIT2 ( EXIT_SUCCESS, EXIT_SUCCESS );
}
示例#2
0
文件: pthread.c 项目: l30nard0/Benu
/*!
 * Initialize semaphore object
 * \param sem Semaphore descriptor (user level descriptor)
 * \param pshared Shall semaphore object be shared between processes
 * \param value Initial semaphore value
 * \return 0 if successful, -1 otherwise and appropriate error number is set
 */
int sys__sem_init ( void *p )
{
	sem_t *sem;
	int pshared;
	int value;

	ksem_t *ksem;
	kobject_t *kobj;

	sem =		*( (sem_t **) p );	p += sizeof (sem_t *);
	pshared =	*( (int *) p );		p += sizeof (int);
	value =		*( (uint *) p );

	ASSERT_ERRNO_AND_EXIT ( sem, EINVAL );

	kobj = kmalloc_kobject ( sizeof (ksem_t) );
	ASSERT_ERRNO_AND_EXIT ( kobj, ENOMEM );
	ksem = kobj->kobject;

	ksem->id = k_new_id ();
	ksem->sem_value = value;
	ksem->last_lock = NULL;
	ksem->flags = 0;
	ksem->ref_cnt = 1;
	kthreadq_init ( &ksem->queue );

	if ( pshared )
		ksem->flags |= PTHREAD_PROCESS_SHARED;

	sem->ptr = kobj;
	sem->id = ksem->id;

	EXIT2 ( EXIT_SUCCESS, EXIT_SUCCESS );
}
示例#3
0
文件: pthread.c 项目: l30nard0/Benu
/*!
 * Initialize mutex object
 * \param mutex Mutex descriptor (user level descriptor)
 * \param mutexattr Mutex parameters
 * \return 0 if successful, -1 otherwise and appropriate error number is set
 */
int sys__pthread_mutex_init ( void *p )
{
	pthread_mutex_t *mutex;
	/* pthread_mutexattr_t *mutexattr; not implemented */

	kpthread_mutex_t *kmutex;
	kobject_t *kobj;

	mutex = *( (pthread_mutex_t **) p ); /* p += sizeof (pthread_mutex_t *);
	mutexattr = *( (pthread_mutexattr_t *) p ); */

	ASSERT_ERRNO_AND_EXIT ( mutex, EINVAL );

	kobj = kmalloc_kobject ( sizeof (kpthread_mutex_t) );
	ASSERT_ERRNO_AND_EXIT ( kobj, ENOMEM );
	kmutex = kobj->kobject;

	kmutex->id = k_new_id ();
	kmutex->owner = NULL;
	kmutex->flags = 0;
	kmutex->ref_cnt = 1;
	kthreadq_init ( &kmutex->queue );

	mutex->ptr = kobj;
	mutex->id = kmutex->id;

	EXIT2 ( EXIT_SUCCESS, EXIT_SUCCESS );
}
示例#4
0
文件: time.c 项目: bkolobara/Benu-pi
/*!
 * Create new timer
 * \param clockid	Clock used in timer
 * \param evp		Timer expiration action
 * \param timerid	Timer descriptor is returned in this variable
 * \return status	0 for success
 */
int sys__timer_create ( void *p )
{
	clockid_t clockid;
	sigevent_t *evp;
	timer_t *timerid;

	ktimer_t *ktimer;
	int retval = EXIT_SUCCESS;
	kobject_t *kobj;

	clockid =	*( (clockid_t *) p );	p += sizeof (clockid_t);
	evp =		*( (sigevent_t **) p );	p += sizeof (sigevent_t *);
	timerid =	*( (timer_t **) p );

	ASSERT_ERRNO_AND_EXIT (
	clockid == CLOCK_REALTIME || clockid == CLOCK_MONOTONIC, EINVAL );
	ASSERT_ERRNO_AND_EXIT ( evp && timerid, EINVAL );

	retval = ktimer_create ( clockid, evp, &ktimer, kthread_get_active() );
	if ( retval == EXIT_SUCCESS )
	{
		kobj = kmalloc_kobject ( 0 );
		kobj->kobject = ktimer;
		timerid->id = ktimer->id;
		timerid->ptr = kobj;
	}
	EXIT ( retval );
}
示例#5
0
/*!
 * Initialize semaphore object
 * \param sem Semaphore descriptor (user level descriptor)
 * \param pshared Shall semaphore object be shared between processes
 * \param value Initial semaphore value
 * \return 0 if successful, -1 otherwise and appropriate error number is set
 */
int sys__sem_init ( sem_t *sem, int pshared, int value )
{
	ksem_t *ksem;
	kobject_t *kobj;

	SYS_ENTRY();

	ASSERT_ERRNO_AND_EXIT ( sem, EINVAL );

	kobj = kmalloc_kobject ( sizeof (ksem_t) );
	ASSERT_ERRNO_AND_EXIT ( kobj, ENOMEM );
	ksem = kobj->kobject;

	ksem->id = k_new_id ();
	ksem->sem_value = value;
	ksem->last_lock = NULL;
	ksem->flags = 0;
	ksem->ref_cnt = 1;
	kthreadq_init ( &ksem->queue );

	if ( pshared )
		ksem->flags |= PTHREAD_PROCESS_SHARED;

	sem->ptr = kobj;
	sem->id = ksem->id;

	SYS_EXIT ( EXIT_SUCCESS, EXIT_SUCCESS );
}
示例#6
0
/*!
 * Initialize mutex object
 * \param mutex Mutex descriptor (user level descriptor)
 * \param mutexattr Mutex parameters
 * \return 0 if successful, -1 otherwise and appropriate error number is set
 */
int sys__pthread_mutex_init ( pthread_mutex_t *mutex,
			      pthread_mutexattr_t *mutexattr )
{
	kpthread_mutex_t *kmutex;
	kobject_t *kobj;

	SYS_ENTRY();

	ASSERT_ERRNO_AND_EXIT ( mutex, EINVAL );

	kobj = kmalloc_kobject ( sizeof (kpthread_mutex_t) );
	ASSERT_ERRNO_AND_EXIT ( kobj, ENOMEM );
	kmutex = kobj->kobject;

	kmutex->id = k_new_id ();
	kmutex->owner = NULL;
	kmutex->flags = 0;
	kmutex->ref_cnt = 1;
	kthreadq_init ( &kmutex->queue );

	mutex->ptr = kobj;
	mutex->id = kmutex->id;

	SYS_EXIT ( EXIT_SUCCESS, EXIT_SUCCESS );
}
示例#7
0
/*!
 * Initialize conditional variable object
 * \param cond conditional variable descriptor (user level descriptor)
 * \param condattr conditional variable descriptor (user level descriptor)
 * \return 0 if successful, -1 otherwise and appropriate error number is set
 */
int sys__pthread_cond_init (pthread_cond_t *cond, pthread_condattr_t *condattr)
{
	kpthread_cond_t *kcond;
	kobject_t *kobj;

	SYS_ENTRY();

	ASSERT_ERRNO_AND_EXIT ( cond, EINVAL );

	kobj = kmalloc_kobject ( sizeof (kpthread_cond_t) );
	ASSERT_ERRNO_AND_EXIT ( kobj, ENOMEM );
	kcond = kobj->kobject;

	kcond->id = k_new_id ();
	kcond->flags = 0;
	kcond->ref_cnt = 1;
	kthreadq_init ( &kcond->queue );

	cond->ptr = kobj;
	cond->id = kcond->id;

	SYS_EXIT ( EXIT_SUCCESS, EXIT_SUCCESS );
}
示例#8
0
文件: pthread.c 项目: l30nard0/Benu
/*!
 * Open a message queue
 * \param name Queue name
 * \param oflag Opening flags
 * \param mode Permissions on created queue (only when O_CREAT is set)
 * \param attr Message queue attributes (only when O_CREAT is set)
 * \param mqdes Return queue descriptor address (user level descriptor)
 * \return 0 if successful, -1 otherwise and appropriate error number is set
 */
int sys__mq_open ( void *p )
{
	char *name;
	int oflag;
	/* mode_t mode;	not used in this implementation */
	mq_attr_t *attr;
	mqd_t *mqdes;

	kmq_queue_t *kq_queue;
	kobject_t *kobj;

	name =	*( (char **) p );		p += sizeof (char *);
	oflag =	*( (int *) p );			p += sizeof (int);
	/* mode = *( (mode_t *) p ); */		p += sizeof (mode_t);
	attr =	*( (mq_attr_t **) p );		p += sizeof (mq_attr_t*);
	mqdes =	*( (mqd_t **) p );

	ASSERT_ERRNO_AND_EXIT ( name && mqdes, EBADF );
	ASSERT_ERRNO_AND_EXIT ( strlen (name) < NAME_MAX, EBADF );


	kq_queue = list_get ( &kmq_queue, FIRST );
	while ( kq_queue &&
		strcmp ( name, kq_queue->name ) )
		kq_queue = list_get_next ( &kq_queue->list );

	if (	( kq_queue && ( (oflag & O_CREAT) || (oflag & O_EXCL) ) )
		|| ( !kq_queue && !(oflag & O_CREAT ) ) )
	{
		mqdes->ptr = (void *) -1;
		mqdes->id = -1;
		EXIT2 ( EEXIST, EXIT_FAILURE );
	}

	if ( !kq_queue && (oflag & O_CREAT) )
	{
		kq_queue = kmalloc ( sizeof (kmq_queue_t) );

		if ( attr )
			kq_queue->attr = *attr;

		kq_queue->id = k_new_id ();
		kq_queue->attr.mq_curmsgs = 0;

		kq_queue->name = kmalloc ( strlen (name) + 1 );
		strcpy ( kq_queue->name, name );

		kq_queue->ref_cnt = 0;

		list_init ( &kq_queue->msg_list );
		kthreadq_init ( &kq_queue->recv_q );
		kthreadq_init ( &kq_queue->send_q );

		list_append ( &kmq_queue, kq_queue, &kq_queue->list );
	}

	kq_queue->ref_cnt++;

	kobj = kmalloc_kobject ( 0 );
	kobj->kobject = kq_queue;
	kobj->flags = oflag;

	mqdes->ptr = kobj;
	mqdes->id = kq_queue->id;

	EXIT2 ( EXIT_SUCCESS, EXIT_SUCCESS );
}