Changeset 25390

Show
Ignore:
Timestamp:
05/08/08 20:36:49 (3 days ago)
Author:
bonefish
Message:
Implemented pthread_attr_{g,s}etstacksize(). Also added commented-out
prototypes for the missing pthread_attr_*() functions.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • haiku/trunk/headers/posix/pthread.h

    r25090 r25390  
    171171        int *detachstate); 
    172172extern int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate); 
     173extern int pthread_attr_getstacksize(const pthread_attr_t *attr, 
     174        size_t *stacksize); 
     175extern int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize); 
     176 
     177#if 0   /* Unimplemented attribute functions: */ 
     178 
     179// mandatory! 
     180extern int pthread_attr_getschedparam(const pthread_attr_t *attr, 
     181        struct sched_param *param); 
     182extern int pthread_attr_setschedparam(pthread_attr_t *attr, 
     183        const struct sched_param *param); 
     184 
     185// [TPS] 
     186extern int pthread_attr_getinheritsched(const pthread_attr_t *attr, 
     187        int *inheritsched); 
     188extern int pthread_attr_setinheritsched(pthread_attr_t *attr, int inheritsched); 
     189 
     190extern int pthread_attr_getschedpolicy(const pthread_attr_t *attr, 
     191        int *policy); 
     192extern int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy); 
     193extern int pthread_attr_getscope(const pthread_attr_t *attr, 
     194        int *contentionscope); 
     195extern int pthread_attr_setscope(pthread_attr_t *attr, int contentionscope); 
     196 
     197// [XSI] 
     198extern int pthread_attr_getguardsize(const pthread_attr_t *attr, 
     199        size_t *guardsize); 
     200extern int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize); 
     201 
     202// [TSA] 
     203extern int pthread_attr_getstackaddr(const pthread_attr_t *attr, 
     204        void **stackaddr); 
     205extern int pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr); 
     206 
     207// [TSA TSS] 
     208extern int pthread_attr_getstack(const pthread_attr_t *attr, 
     209        void **stackaddr, size_t *stacksize); 
     210extern int pthread_attr_setstack(pthread_attr_t *attr, void *stackaddr, size_t stacksize); 
     211 
     212#endif  /* 0 */ 
     213 
    173214 
    174215/* thread functions */ 
  • haiku/trunk/src/system/libroot/posix/pthread/Jamfile

    r25000 r25390  
    11SubDir HAIKU_TOP src system libroot posix pthread ; 
    22 
     3UsePrivateKernelHeaders ; 
    34UsePrivateHeaders libroot ; 
    45 
  • haiku/trunk/src/system/libroot/posix/pthread/pthread_attr.c

    r17885 r25390  
    11/*  
    2 ** Copyright 2006, Jérôme Duval. All rights reserved
    3 ** Distributed under the terms of the MIT License
    4 */ 
    5  
     2 * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de
     3 * Copyright 2006, Jérôme Duval. All rights reserved
     4 * Distributed under the terms of the MIT License. 
     5 */ 
    66 
    77#include <pthread.h> 
     
    99 
    1010#include <stdlib.h> 
     11 
     12#include <kernel.h> 
    1113 
    1214 
     
    2527        attr->detach_state = PTHREAD_CREATE_JOINABLE; 
    2628        attr->sched_priority = B_NORMAL_PRIORITY; 
     29        attr->stack_size = USER_STACK_SIZE; 
    2730 
    2831        *_attr = attr; 
     
    7679} 
    7780 
     81 
     82int 
     83pthread_attr_getstacksize(const pthread_attr_t *_attr, size_t *stacksize) 
     84{ 
     85        pthread_attr *attr; 
     86 
     87        if (_attr == NULL || (attr = *_attr) == NULL || stacksize == NULL) 
     88                return B_BAD_VALUE; 
     89 
     90        *stacksize = attr->stack_size; 
     91 
     92        return 0; 
     93} 
     94 
     95 
     96int 
     97pthread_attr_setstacksize(pthread_attr_t *_attr, size_t stacksize) 
     98{ 
     99        pthread_attr *attr; 
     100 
     101        if (_attr == NULL || (attr = *_attr) == NULL) 
     102                return B_BAD_VALUE; 
     103 
     104        if (stacksize < MIN_USER_STACK_SIZE || stacksize > MAX_USER_STACK_SIZE) 
     105                return B_BAD_VALUE; 
     106 
     107        attr->stack_size = stacksize; 
     108 
     109        return 0; 
     110} 
  • haiku/trunk/src/system/libroot/posix/pthread/pthread.c

    r25000 r25390  
    1212#include <TLS.h> 
    1313 
     14#include <kernel.h> 
     15#include <syscalls.h> 
     16#include <thread.h> 
     17 
    1418 
    1519static const pthread_attr pthread_attr_default = { 
    1620        PTHREAD_CREATE_JOINABLE, 
    17         B_NORMAL_PRIORITY 
     21        B_NORMAL_PRIORITY, 
     22        USER_STACK_SIZE 
    1823}; 
    1924 
     
    6166 
    6267static int32 
    63 pthread_thread_entry(void *_thread) 
     68pthread_thread_entry(thread_func _unused, void *_thread) 
    6469{ 
    6570        struct pthread_thread *thread = (struct pthread_thread *)_thread; 
     
    8590        struct pthread_thread *thread; 
    8691        thread_id threadID; 
     92        struct thread_creation_attributes attributes; 
    8793 
    8894        if (_thread == NULL) 
     
    110116        } 
    111117 
    112         threadID = spawn_thread(pthread_thread_entry, "pthread func", 
    113                 attr->sched_priority, thread); 
     118        attributes.entry = pthread_thread_entry; 
     119        attributes.name = "pthread func"; 
     120        attributes.priority = attr->sched_priority; 
     121        attributes.args1 = thread; 
     122        attributes.args2 = NULL; 
     123        attributes.stack_address = NULL; 
     124        attributes.stack_size = attr->stack_size; 
     125 
     126        threadID = _kern_spawn_thread(&attributes); 
    114127        if (threadID < B_OK) { 
    115128                // stupid error code (EAGAIN) but demanded by POSIX 
  • haiku/trunk/src/system/libroot/posix/pthread/pthread_private.h

    r25000 r25390  
    4545        int32           detach_state; 
    4646        int32           sched_priority; 
     47        size_t          stack_size; 
    4748} pthread_attr; 
    4849