Implemented pthread_attr_{g,s}etstacksize(). Also added commented-out
prototypes for the missing pthread_attr_*() functions. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25390 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
4c49f2056b
commit
f7cc12b389
@ -170,6 +170,47 @@ extern int pthread_attr_init(pthread_attr_t *attr);
|
||||
extern int pthread_attr_getdetachstate(const pthread_attr_t *attr,
|
||||
int *detachstate);
|
||||
extern int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate);
|
||||
extern int pthread_attr_getstacksize(const pthread_attr_t *attr,
|
||||
size_t *stacksize);
|
||||
extern int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize);
|
||||
|
||||
#if 0 /* Unimplemented attribute functions: */
|
||||
|
||||
// mandatory!
|
||||
extern int pthread_attr_getschedparam(const pthread_attr_t *attr,
|
||||
struct sched_param *param);
|
||||
extern int pthread_attr_setschedparam(pthread_attr_t *attr,
|
||||
const struct sched_param *param);
|
||||
|
||||
// [TPS]
|
||||
extern int pthread_attr_getinheritsched(const pthread_attr_t *attr,
|
||||
int *inheritsched);
|
||||
extern int pthread_attr_setinheritsched(pthread_attr_t *attr, int inheritsched);
|
||||
|
||||
extern int pthread_attr_getschedpolicy(const pthread_attr_t *attr,
|
||||
int *policy);
|
||||
extern int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy);
|
||||
extern int pthread_attr_getscope(const pthread_attr_t *attr,
|
||||
int *contentionscope);
|
||||
extern int pthread_attr_setscope(pthread_attr_t *attr, int contentionscope);
|
||||
|
||||
// [XSI]
|
||||
extern int pthread_attr_getguardsize(const pthread_attr_t *attr,
|
||||
size_t *guardsize);
|
||||
extern int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize);
|
||||
|
||||
// [TSA]
|
||||
extern int pthread_attr_getstackaddr(const pthread_attr_t *attr,
|
||||
void **stackaddr);
|
||||
extern int pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr);
|
||||
|
||||
// [TSA TSS]
|
||||
extern int pthread_attr_getstack(const pthread_attr_t *attr,
|
||||
void **stackaddr, size_t *stacksize);
|
||||
extern int pthread_attr_setstack(pthread_attr_t *attr, void *stackaddr, size_t stacksize);
|
||||
|
||||
#endif /* 0 */
|
||||
|
||||
|
||||
/* thread functions */
|
||||
extern int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
|
||||
|
@ -1,5 +1,6 @@
|
||||
SubDir HAIKU_TOP src system libroot posix pthread ;
|
||||
|
||||
UsePrivateKernelHeaders ;
|
||||
UsePrivateHeaders libroot ;
|
||||
|
||||
MergeObject posix_pthread.o :
|
||||
|
@ -11,10 +11,15 @@
|
||||
|
||||
#include <TLS.h>
|
||||
|
||||
#include <kernel.h>
|
||||
#include <syscalls.h>
|
||||
#include <thread.h>
|
||||
|
||||
|
||||
static const pthread_attr pthread_attr_default = {
|
||||
PTHREAD_CREATE_JOINABLE,
|
||||
B_NORMAL_PRIORITY
|
||||
B_NORMAL_PRIORITY,
|
||||
USER_STACK_SIZE
|
||||
};
|
||||
|
||||
|
||||
@ -60,7 +65,7 @@ pthread_destroy_thread(void *data)
|
||||
|
||||
|
||||
static int32
|
||||
pthread_thread_entry(void *_thread)
|
||||
pthread_thread_entry(thread_func _unused, void *_thread)
|
||||
{
|
||||
struct pthread_thread *thread = (struct pthread_thread *)_thread;
|
||||
|
||||
@ -84,6 +89,7 @@ pthread_create(pthread_t *_thread, const pthread_attr_t *_attr,
|
||||
const pthread_attr *attr = NULL;
|
||||
struct pthread_thread *thread;
|
||||
thread_id threadID;
|
||||
struct thread_creation_attributes attributes;
|
||||
|
||||
if (_thread == NULL)
|
||||
return B_BAD_VALUE;
|
||||
@ -109,8 +115,15 @@ pthread_create(pthread_t *_thread, const pthread_attr_t *_attr,
|
||||
sPthreadSlot = tls_allocate();
|
||||
}
|
||||
|
||||
threadID = spawn_thread(pthread_thread_entry, "pthread func",
|
||||
attr->sched_priority, thread);
|
||||
attributes.entry = pthread_thread_entry;
|
||||
attributes.name = "pthread func";
|
||||
attributes.priority = attr->sched_priority;
|
||||
attributes.args1 = thread;
|
||||
attributes.args2 = NULL;
|
||||
attributes.stack_address = NULL;
|
||||
attributes.stack_size = attr->stack_size;
|
||||
|
||||
threadID = _kern_spawn_thread(&attributes);
|
||||
if (threadID < B_OK) {
|
||||
// stupid error code (EAGAIN) but demanded by POSIX
|
||||
return B_WOULD_BLOCK;
|
||||
|
@ -1,14 +1,16 @@
|
||||
/*
|
||||
** Copyright 2006, Jérôme Duval. All rights reserved.
|
||||
** Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
* Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||
* Copyright 2006, Jérôme Duval. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include "pthread_private.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <kernel.h>
|
||||
|
||||
|
||||
int
|
||||
pthread_attr_init(pthread_attr_t *_attr)
|
||||
@ -24,6 +26,7 @@ pthread_attr_init(pthread_attr_t *_attr)
|
||||
|
||||
attr->detach_state = PTHREAD_CREATE_JOINABLE;
|
||||
attr->sched_priority = B_NORMAL_PRIORITY;
|
||||
attr->stack_size = USER_STACK_SIZE;
|
||||
|
||||
*_attr = attr;
|
||||
return B_OK;
|
||||
@ -75,3 +78,33 @@ pthread_attr_setdetachstate(pthread_attr_t *_attr, int state)
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
pthread_attr_getstacksize(const pthread_attr_t *_attr, size_t *stacksize)
|
||||
{
|
||||
pthread_attr *attr;
|
||||
|
||||
if (_attr == NULL || (attr = *_attr) == NULL || stacksize == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
*stacksize = attr->stack_size;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
pthread_attr_setstacksize(pthread_attr_t *_attr, size_t stacksize)
|
||||
{
|
||||
pthread_attr *attr;
|
||||
|
||||
if (_attr == NULL || (attr = *_attr) == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
if (stacksize < MIN_USER_STACK_SIZE || stacksize > MAX_USER_STACK_SIZE)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
attr->stack_size = stacksize;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ typedef struct _pthread_mutex {
|
||||
typedef struct _pthread_attr {
|
||||
int32 detach_state;
|
||||
int32 sched_priority;
|
||||
size_t stack_size;
|
||||
} pthread_attr;
|
||||
|
||||
typedef void (*pthread_key_destructor)(void *data);
|
||||
|
Loading…
x
Reference in New Issue
Block a user