You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
1.1 KiB
88 lines
1.1 KiB
#define __LIBRARY__
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/types.h>
|
|
#include <fcntl.h>
|
|
#include <errno.h>
|
|
|
|
#define PAGE_SIZE 4096
|
|
|
|
int pthread_create(pthread_t *thread,const pthread_attr_t* attr,void* (*start_routine)(void *),void* arg)
|
|
{
|
|
pthread_t thread_id;
|
|
|
|
if(thread == NULL || start_routine == NULL)
|
|
{
|
|
printf("Error:Thread or func_addr is NULL!!!\n");
|
|
exit(0);
|
|
}
|
|
|
|
if(attr != NULL && attr->stacksize > PAGE_SIZE)
|
|
return EINVAL;
|
|
|
|
thread_id = thread_fork(attr,start_routine,arg);
|
|
if(thread_id == -1)
|
|
{
|
|
printf("Error:New thread creating failed!!!\n");
|
|
return errno;
|
|
}
|
|
|
|
if(thread_id > 0)
|
|
{
|
|
(*thread) = thread_id;
|
|
return 0;
|
|
}
|
|
|
|
printf("Error:pthread_create error!\n");
|
|
return -1;
|
|
}
|
|
|
|
int pthread_join(pthread_t thread,void** value_ptr)
|
|
{
|
|
if(thread <=0)
|
|
{
|
|
printf("Error:Invalid thread for pthread_join!\n");
|
|
exit(0);
|
|
}
|
|
|
|
if(value_ptr == NULL)
|
|
{
|
|
printf("Error:value_ptr is invalid!\n");
|
|
exit(0);
|
|
}
|
|
|
|
thread_join(thread,value_ptr);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void pthread_exit(void* value_ptr)
|
|
{
|
|
thread_exit(value_ptr);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|