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