1.1 --- a/epoc32/include/stdapis/pthread.h Tue Nov 24 13:55:44 2009 +0000
1.2 +++ b/epoc32/include/stdapis/pthread.h Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -1,1 +1,471 @@
1.4 -pthread.h
1.5 +/*
1.6 +* ==============================================================================
1.7 +* Name : pthread.h
1.8 +* Part of : pthread
1.9 +* Interface : POSIX, pthread
1.10 +* Description : POSIX thread exported header file
1.11 +* Version :
1.12 +
1.13 +Copyright © 2005-2006 Nokia Corporation
1.14 +All rights reserved.
1.15 +* © Portions copyright (c) 2007 Symbian Software Ltd. All rights reserved.
1.16 +Redistribution and use in source and binary forms, with or without
1.17 +modification, are permitted provided that the following conditions are met:
1.18 + * Redistributions of source code must retain the above copyright notice, this
1.19 + list of conditions and the following disclaimer.
1.20 + * Redistributions in binary form must reproduce the above copyright notice,
1.21 + this list of conditions and the following disclaimer in the documentation
1.22 + and/or other materials provided with the distribution.
1.23 + * Neither the name of the <ORGANIZATION> nor the names of its contributors
1.24 + may be used to endorse or promote products derived from this software
1.25 + without specific prior written permission.
1.26 +
1.27 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1.28 +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1.29 +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1.30 +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
1.31 +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1.32 +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1.33 +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1.34 +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
1.35 +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1.36 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1.37 +* ==============================================================================
1.38 +*/
1.39 +#ifndef PTHREAD_H
1.40 +#define PTHREAD_H
1.41 +
1.42 +#include <pthreadtypes.h>
1.43 +#include <sched.h>
1.44 +#include <e32def.h>
1.45 +#include <stddef.h>
1.46 +#include <time.h>
1.47 +#include <limits.h>
1.48 +#include <pthreadalias.h>
1.49 +
1.50 +#define POSIX_THREAD_DESTRUCTOR_ITERATIONS 4
1.51 +#define POSIX_THREAD_KEYS_MAX 128
1.52 +#define PTHREAD_STACK_MIN 0x2000
1.53 +#define POSIX_THREAD_THREADS_MAX 64
1.54 +#define PTHREAD_THREADS_MAX 1024
1.55 +#define POSIX_SEM_NSEMS_MAX 256
1.56 +#define SEM_NSEMS_MAX 1024
1.57 +#define _POSIX_SEM_VALUE_MAX 32767
1.58 +#define SEM_VALUE_MAX INT_MAX
1.59 +
1.60 +/* internal use*/
1.61 +typedef enum
1.62 +{
1.63 + _ENeedsNormalInit =-3,
1.64 + _ENeedsRecursiveInit,
1.65 + _ENeedsErrorCheckInit,
1.66 + _EInitialized =1,
1.67 + _EDestroyed,
1.68 + _EInvalid,
1.69 +}_handle_state;
1.70 +
1.71 +enum _LockStatus
1.72 +{
1.73 + _ELockNotCreated,
1.74 + _ELockCreating,
1.75 + _ELockCreated,
1.76 +};
1.77 +
1.78 +enum _OnceStatus
1.79 +{
1.80 + _ENotDone,
1.81 + _EDoing,
1.82 + _EDone,
1.83 +};
1.84 +
1.85 +typedef int pthread_once_t;
1.86 +
1.87 +struct _pthread_mutex_t;
1.88 +typedef struct
1.89 +{
1.90 + _handle_state iState;
1.91 + struct _pthread_mutex_t* iPtr;
1.92 + int iReentry;
1.93 +}pthread_mutex_t;
1.94 +
1.95 +typedef struct
1.96 +{
1.97 + _handle_state iState;
1.98 + int iSharedType;
1.99 + int iMutexType;
1.100 +}pthread_mutexattr_t;
1.101 +
1.102 +
1.103 +struct _CondNode;
1.104 +struct _CondQueue
1.105 +{
1.106 + struct _CondNode* iHead;
1.107 + struct _CondNode* iTail;
1.108 + pthread_mutex_t iMutex;
1.109 +};
1.110 +
1.111 +typedef struct
1.112 +{
1.113 + _handle_state iState;
1.114 + struct _CondQueue iQueue;
1.115 +}pthread_cond_t;
1.116 +
1.117 +typedef struct _pthread_condattr_t* pthread_condattr_t;
1.118 +
1.119 +#define PTHREAD_ONCE_INIT _ENotDone
1.120 +
1.121 +#define PTHREAD_MUTEX_INITIALIZER { _ENeedsNormalInit, NULL,0 }
1.122 +#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP { _ENeedsRecursiveInit, NULL, 0 }
1.123 +#define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP { _ENeedsErrorCheckInit, NULL,0 }
1.124 +
1.125 +#define PTHREAD_COND_INITIALIZER { _ENeedsNormalInit, NULL,NULL }
1.126 +
1.127 +enum
1.128 +{
1.129 + PTHREAD_CREATE_JOINABLE = 0, /* Default */
1.130 + PTHREAD_CREATE_DETACHED = 1
1.131 +};
1.132 +
1.133 +enum
1.134 +{
1.135 + PTHREAD_SCOPE_SYSTEM = 1 /* Default */
1.136 +};
1.137 +
1.138 +enum
1.139 +{
1.140 + PTHREAD_CANCEL_ASYNCHRONOUS = 0,
1.141 + PTHREAD_CANCEL_DEFERRED = 1 /* Default */
1.142 +};
1.143 +
1.144 +enum
1.145 +{
1.146 + PTHREAD_PROCESS_PRIVATE = 0,
1.147 +};
1.148 +
1.149 +enum
1.150 +{
1.151 + PTHREAD_MUTEX_NORMAL,
1.152 + PTHREAD_MUTEX_RECURSIVE,
1.153 + PTHREAD_MUTEX_ERRORCHECK,
1.154 + PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL
1.155 +};
1.156 +
1.157 +
1.158 +
1.159 +#ifdef __cplusplus
1.160 +extern "C"
1.161 +{
1.162 +#endif /* __cplusplus */
1.163 +
1.164 +typedef void * (*thread_begin_routine)(void *);
1.165 +/*
1.166 +This function creates a thread, with attributes specified by attrib,
1.167 +within a process. If attrib is NULL, then default attributes will be used.
1.168 +On successful completion, pthread_create() will store the ID of the
1.169 +created thread in the location referenced by threadhdl.
1.170 +*/
1.171 +IMPORT_C extern int pthread_create(pthread_t *threadhdl, pthread_attr_t *attrib,
1.172 + thread_begin_routine begin_routine , void * param);
1.173 +/*
1.174 +This function return the handle to current thread.
1.175 +*/
1.176 +IMPORT_C extern pthread_t pthread_self ();
1.177 +
1.178 +/*
1.179 +Compare two thread handles
1.180 +*/
1.181 +IMPORT_C extern int pthread_equal(pthread_t t1,pthread_t t2);
1.182 +/*
1.183 +Waiting for thread termination
1.184 +*/
1.185 +IMPORT_C extern int pthread_join(pthread_t thHandle, void **retValPtr);
1.186 +/*
1.187 +detach from thread
1.188 +*/
1.189 +IMPORT_C extern int pthread_detach(pthread_t thrHandle);
1.190 +/*
1.191 +exit current thread
1.192 +*/
1.193 +IMPORT_C extern void pthread_exit(void *retValPtr);
1.194 +/*
1.195 +Initialise the thread attributes
1.196 +*/
1.197 +IMPORT_C int pthread_attr_init(pthread_attr_t *attrib);
1.198 +/*
1.199 +Destroy the thread attributes
1.200 +*/
1.201 +IMPORT_C int pthread_attr_destroy(pthread_attr_t *attrib);
1.202 +/*
1.203 +Get the detach_state of the current thread
1.204 +*/
1.205 +IMPORT_C int pthread_attr_getdetachstate(const pthread_attr_t *attrib,
1.206 + int *detState);
1.207 +/*
1.208 +Set the detach_state of the current thread
1.209 +*/
1.210 +IMPORT_C int pthread_attr_setdetachstate(pthread_attr_t *attrib,
1.211 + int detState);
1.212 +/*
1.213 +Get the stack size of the current thread
1.214 +*/
1.215 +IMPORT_C int pthread_attr_getstacksize(const pthread_attr_t *attrib,
1.216 + size_t *stkSize);
1.217 +/*
1.218 +Set the stack size of the current thread
1.219 +*/
1.220 +IMPORT_C int pthread_attr_setstacksize(pthread_attr_t *attrib,
1.221 + size_t stkSize);
1.222 +
1.223 +/*
1.224 +This function ensures that a piece of initialization code is executed at most once.
1.225 +The once_control argument must point to a static variable statically initialized to PTHREAD_ONCE_INIT
1.226 +
1.227 +*/
1.228 +typedef void (*thread_init_routine) (void);
1.229 +IMPORT_C extern int pthread_once (pthread_once_t * once_control,
1.230 + thread_init_routine init_routine);
1.231 +
1.232 +/*
1.233 +extern int pthread_key_create (pthread_key_t * key, void (*destructor) (void *));
1.234 +extern int pthread_key_delete (pthread_key_t key);
1.235 +extern int pthread_setspecific (pthread_key_t key, const void *value);
1.236 +extern void* pthread_getspecific (pthread_key_t key);
1.237 +*/
1.238 +
1.239 +/*
1.240 +This function initializes the mutex attribute object attr and fills it with default values for the attributes.
1.241 +*/
1.242 +IMPORT_C extern int pthread_mutexattr_init (pthread_mutexattr_t * attr);
1.243 +
1.244 +/*
1.245 +This function destroys the mutex attribute object attr and marks it as a destroyed object.
1.246 +*/
1.247 +IMPORT_C extern int pthread_mutexattr_destroy (pthread_mutexattr_t * attr);
1.248 +
1.249 +/*
1.250 +This function retrieves the current value of the process shared attribute in
1.251 +attr and stores it in the location pointed to by pshared.
1.252 +*/
1.253 +IMPORT_C extern int pthread_mutexattr_getpshared (const pthread_mutexattr_t* attr, int* pshared);
1.254 +
1.255 +/*
1.256 +This function sets the current value of the process shared attribute in attr to the value specifed in the
1.257 +pshared variable.
1.258 +*/
1.259 +IMPORT_C extern int pthread_mutexattr_setpshared (pthread_mutexattr_t * attr, int pshared);
1.260 +
1.261 +/*
1.262 +This function retrieves the current value of the mutex kind attribute in attr and
1.263 +stores it in the location pointed to by type.
1.264 +*/
1.265 +IMPORT_C extern int pthread_mutexattr_gettype (pthread_mutexattr_t * attr, int *type);
1.266 +
1.267 +
1.268 +/*
1.269 +This function sets the current value of the mutex kind attribute in attr to the value specifed in the type variable.
1.270 +*/
1.271 +IMPORT_C extern int pthread_mutexattr_settype (pthread_mutexattr_t * attr, int type);
1.272 +
1.273 +/*
1.274 +This function initializes the mutex object pointed to by mutex according to the mutex attributes specified in attr.
1.275 +If attr is NULL, default attributes are used instead.
1.276 +
1.277 +*/
1.278 +IMPORT_C extern int pthread_mutex_init (pthread_mutex_t * mutex, const pthread_mutexattr_t * attr);
1.279 +
1.280 +/*
1.281 +This function destroys the mutex object. The mutex must be unlocked on entrance.
1.282 +This implementation requires even statically initialized mutexes to be explicitly destroyed.
1.283 +*/
1.284 +IMPORT_C extern int pthread_mutex_destroy (pthread_mutex_t * mutex);
1.285 +
1.286 +/*
1.287 +This function locks the given mutex. If the mutex is currently
1.288 +unlocked, it becomes locked and owned by the calling thread, and
1.289 +this function returns immediately. If the mutex is already
1.290 +locked by another thread, this function suspends the calling
1.291 +thread until the mutex is unlocked.
1.292 +
1.293 +If the mutex is already locked by the calling thread, the behavior of
1.294 +this function depends on the kind of the mutex. If the mutex is
1.295 +of the PTHREAD_MUTEX_NORMAL or PTHREAD_MUTEX_DEFAULT kind, the calling thread is suspended until the mutex
1.296 +is unlocked, thus effectively causing the calling thread to
1.297 +deadlock. If the mutex is of the PTHREAD_MUTEX_ERRORCHECK kind,
1.298 +this function returns immediately with the error code EDEADLK.
1.299 +If the mutex is of the PTHREAD_MUTEX_RECURSIVE kind, this function
1.300 +succeeds and returns immediately, recording the number of times the
1.301 +calling thread has locked the mutex. An equal number of
1.302 +pthread_mutex_unlock operations must be performed before the mutex
1.303 +returns to the unlocked state.
1.304 +*/
1.305 +IMPORT_C extern int pthread_mutex_lock (pthread_mutex_t * mutex);
1.306 +
1.307 +
1.308 +/*
1.309 +This function behaves identically to pthread_mutex_lock, except that if it cannot acquire the lock before
1.310 +the abs_timeout time, the call returns with the error code ETIMEDOUT.
1.311 +*/
1.312 +IMPORT_C extern int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abstime);
1.313 +
1.314 +/*
1.315 +This function behaves identically to pthread_mutex_lock, except that it does not
1.316 +block the calling thread if the mutex is already locked by another thread (or by
1.317 +the calling thread in the case of a PTHREAD_MUTEX_RECURSIVE mutex). Instead, pthread_mutex_trylock
1.318 +returns immediately with the error code EAGAIN.
1.319 +*/
1.320 +IMPORT_C extern int pthread_mutex_trylock (pthread_mutex_t * mutex);
1.321 +
1.322 +/*
1.323 +This function unlocks the given mutex. The mutex is assumed
1.324 +to be locked and owned by the calling thread on entrance to
1.325 +this function. If the mutex is of the PTHREAD_MUTEX_NORMAL or PTHREAD_MUTEX_DEFAULT kind,
1.326 +this function always returns it to the unlocked state. If it
1.327 +is of the PTHREAD_MUTEX_RECURSIVE kind, it decrements the locking count of the
1.328 +mutex (number of pthread_mutex_lock operations performed on it by
1.329 +the calling thread), and only when this count reaches zero is the
1.330 +mutex actually unlocked.
1.331 +
1.332 +On PTHREAD_MUTEX_ERRORCHECK mutexes, this function actually checks
1.333 +at run-time that the mutex is locked on entrance, and that it was
1.334 +locked by the same thread that is now calling pthread_mutex_unlock.
1.335 +If these conditions are not met, an error code is returned and the
1.336 +mutex remains unchanged.
1.337 +*/
1.338 +IMPORT_C extern int pthread_mutex_unlock (pthread_mutex_t * mutex);
1.339 +
1.340 +/*
1.341 +This function initializes the condition attribute object attr and
1.342 +sets it with default values for the attributes.
1.343 +*/
1.344 +IMPORT_C extern int pthread_condattr_init (pthread_condattr_t * /*attr*/);
1.345 +
1.346 +/*
1.347 +This function destroys the condtion variable attribute object.
1.348 +*/
1.349 +IMPORT_C extern int pthread_condattr_destroy (pthread_condattr_t * attr);
1.350 +/*
1.351 +extern int pthread_condattr_getpshared (const pthread_condattr_t * attr, int *pshared);
1.352 +extern int pthread_condattr_setpshared (pthread_condattr_t * attr, int pshared);
1.353 +*/
1.354 +
1.355 +/*
1.356 +This function initializes the condition variable object pointed to by cond
1.357 +using the attributes of the attr variable. If attr is NULL, default attributes
1.358 +are used instead.
1.359 +*/
1.360 +IMPORT_C extern int pthread_cond_init (pthread_cond_t * cond, const pthread_condattr_t * /*attr*/);
1.361 +
1.362 +/*
1.363 +This function destroys the condition variable object.
1.364 +*/
1.365 +IMPORT_C extern int pthread_cond_destroy (pthread_cond_t * cond);
1.366 +
1.367 +/*
1.368 +This function atomically unlocks mutex and waits on cond,
1.369 +as pthread_cond_wait does, but it also bounds the duration
1.370 +of the wait. If cond has not been signalled within the amount
1.371 +of time specified by abstime, the mutex mutex is re-acquired and
1.372 +pthread_cond_timedwait returns the error ETIMEDOUT. The abstime
1.373 +parameter specifies an absolute time, with the same origin as time(2) and gettimeofday(2).
1.374 +*/
1.375 +IMPORT_C extern int pthread_cond_timedwait (pthread_cond_t * cond,pthread_mutex_t * mutex,const struct timespec *abstime);
1.376 +
1.377 +/*
1.378 +This function atomically unlocks the mutex (as per pthread_unlock_mutex)
1.379 +and waits for the condition variable cond to be signalled. The thread
1.380 +execution is suspended and does not consume any CPU time until the condition
1.381 +variable is signalled. The mutex must be locked by the calling thread on entrance
1.382 +to pthread_cond_wait. Before returning to the calling thread, pthread_cond_wait
1.383 +re-acquires mutex (as per pthread_lock_mutex).
1.384 +*/
1.385 +IMPORT_C extern int pthread_cond_wait (pthread_cond_t * cond, pthread_mutex_t * mutex);
1.386 +
1.387 +/*
1.388 +This function restarts one of the threads that are waiting on the condition
1.389 +variable cond. If no threads are waiting on cond, nothing happens. If several
1.390 +threads are waiting on cond, exactly one is restarted.
1.391 +
1.392 +*/
1.393 +IMPORT_C extern int pthread_cond_signal (pthread_cond_t * cond);
1.394 +
1.395 +/*
1.396 +This function restarts all the threads that are waiting on the
1.397 +condition variable cond. Nothing happens if no threads are waiting on cond.
1.398 +*/
1.399 +IMPORT_C extern int pthread_cond_broadcast (pthread_cond_t * cond);
1.400 +
1.401 +
1.402 +typedef void (*destructor_routine)(void *);
1.403 +/*
1.404 +Thread-specific data key creation
1.405 +*/
1.406 +IMPORT_C int pthread_key_create(pthread_key_t *key, destructor_routine dest);
1.407 +
1.408 +/*
1.409 +Thread-specific data key deletion
1.410 +*/
1.411 +IMPORT_C int pthread_key_delete(pthread_key_t key);
1.412 +
1.413 +/*
1.414 +Setting Thread-specific data
1.415 +*/
1.416 +IMPORT_C int pthread_setspecific(pthread_key_t key, const void *val);
1.417 +
1.418 +/*
1.419 +Getting Thread-specific data
1.420 +*/
1.421 +IMPORT_C void* pthread_getspecific(pthread_key_t key);
1.422 +
1.423 +/*
1.424 +Getting contention scope
1.425 +*/
1.426 +IMPORT_C int pthread_attr_getscope(const pthread_attr_t *attrib,
1.427 + int* scope);
1.428 +/*
1.429 +Setting contention scope
1.430 +*/
1.431 +IMPORT_C int pthread_attr_setscope(pthread_attr_t *attrib,int conscope);
1.432 +
1.433 +/*
1.434 +Setting scheduling policy
1.435 +*/
1.436 +IMPORT_C int pthread_attr_setschedpolicy(pthread_attr_t *attrib,
1.437 + int policy);
1.438 +
1.439 +/*
1.440 +Getting scheduling policy of the thread
1.441 +*/
1.442 +IMPORT_C int pthread_attr_getschedpolicy(const pthread_attr_t *attrib,
1.443 + int *policy);
1.444 +
1.445 +/*
1.446 +Getting scheduling param of the thread
1.447 +*/
1.448 +IMPORT_C int pthread_attr_getschedparam(const pthread_attr_t *attrib,
1.449 + struct sched_param *param);
1.450 +
1.451 +/*
1.452 +Setting scheduling param
1.453 +*/
1.454 +IMPORT_C int pthread_attr_setschedparam(pthread_attr_t *attrib,
1.455 + const struct sched_param *param);
1.456 +
1.457 +/*
1.458 +Getting dynamic scheduling param of the thread
1.459 +*/
1.460 +IMPORT_C int pthread_getschedparam(pthread_t thr, int *policy,
1.461 + struct sched_param *param);
1.462 +
1.463 +/*
1.464 +Dynamically Setting scheduling params
1.465 +*/
1.466 +IMPORT_C int pthread_setschedparam(pthread_t th, int policy,
1.467 + const struct sched_param *param);
1.468 +
1.469 +#ifdef __cplusplus
1.470 +} /* End of "C" */
1.471 +#endif /* __cplusplus */
1.472 +
1.473 +
1.474 +#endif /* PTHREAD_H */
1.475 +