os/ossrv/genericopenlibs/openenvcore/libpthread/inc/pthread.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description:  POSIX thread exported header file 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
#ifndef  PTHREAD_H
sl@0
    19
#define  PTHREAD_H
sl@0
    20
sl@0
    21
#include <pthreadtypes.h>
sl@0
    22
#include <sched.h>
sl@0
    23
#include <e32def.h>
sl@0
    24
#include <stddef.h>
sl@0
    25
#include <time.h>
sl@0
    26
#include <limits.h>
sl@0
    27
#include <pthreadalias.h>
sl@0
    28
sl@0
    29
#define POSIX_THREAD_DESTRUCTOR_ITERATIONS  4
sl@0
    30
#define POSIX_THREAD_KEYS_MAX               128
sl@0
    31
#define PTHREAD_STACK_MIN                   0x2000
sl@0
    32
#define POSIX_THREAD_THREADS_MAX            64
sl@0
    33
#define PTHREAD_THREADS_MAX                 1024
sl@0
    34
#define POSIX_SEM_NSEMS_MAX                 256
sl@0
    35
#define SEM_NSEMS_MAX                       1024
sl@0
    36
#define _POSIX_SEM_VALUE_MAX                32767
sl@0
    37
#define SEM_VALUE_MAX                       INT_MAX
sl@0
    38
sl@0
    39
/* internal use*/
sl@0
    40
typedef enum 
sl@0
    41
{
sl@0
    42
    _ENeedsNormalInit =-3,
sl@0
    43
    _ENeedsRecursiveInit,
sl@0
    44
    _ENeedsErrorCheckInit,
sl@0
    45
    _EInitialized =1,
sl@0
    46
    _EDestroyed,
sl@0
    47
    _EInvalid,
sl@0
    48
}_handle_state;
sl@0
    49
sl@0
    50
enum _LockStatus
sl@0
    51
{
sl@0
    52
    _ELockNotCreated,
sl@0
    53
    _ELockCreating,
sl@0
    54
    _ELockCreated,
sl@0
    55
};
sl@0
    56
sl@0
    57
enum _OnceStatus
sl@0
    58
{
sl@0
    59
    _ENotDone,
sl@0
    60
    _EDoing,
sl@0
    61
    _EDone,
sl@0
    62
};
sl@0
    63
sl@0
    64
typedef int pthread_once_t;
sl@0
    65
sl@0
    66
struct _pthread_mutex_t;
sl@0
    67
typedef struct 
sl@0
    68
{
sl@0
    69
    _handle_state  iState;
sl@0
    70
    struct _pthread_mutex_t* iPtr;
sl@0
    71
    int   iReentry;
sl@0
    72
}pthread_mutex_t;
sl@0
    73
sl@0
    74
typedef struct 
sl@0
    75
{
sl@0
    76
    _handle_state iState;
sl@0
    77
    int iSharedType;
sl@0
    78
    int iMutexType;
sl@0
    79
}pthread_mutexattr_t;
sl@0
    80
sl@0
    81
sl@0
    82
struct _CondNode;
sl@0
    83
struct _CondQueue
sl@0
    84
{
sl@0
    85
  struct _CondNode*       iHead;
sl@0
    86
  struct _CondNode*       iTail;
sl@0
    87
  pthread_mutex_t iMutex;
sl@0
    88
};
sl@0
    89
sl@0
    90
typedef struct 
sl@0
    91
{
sl@0
    92
  _handle_state    iState;
sl@0
    93
  struct _CondQueue       iQueue;
sl@0
    94
}pthread_cond_t;
sl@0
    95
sl@0
    96
typedef struct _pthread_condattr_t*   pthread_condattr_t;
sl@0
    97
sl@0
    98
#define PTHREAD_ONCE_INIT _ENotDone
sl@0
    99
sl@0
   100
#define PTHREAD_MUTEX_INITIALIZER { _ENeedsNormalInit, NULL,0 }
sl@0
   101
#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP { _ENeedsRecursiveInit, NULL, 0 }
sl@0
   102
#define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP { _ENeedsErrorCheckInit, NULL,0 }
sl@0
   103
sl@0
   104
#define PTHREAD_COND_INITIALIZER { _ENeedsNormalInit, NULL,NULL }
sl@0
   105
sl@0
   106
enum 
sl@0
   107
{ 
sl@0
   108
    PTHREAD_CREATE_JOINABLE = 0,  /* Default */ 
sl@0
   109
    PTHREAD_CREATE_DETACHED = 1
sl@0
   110
};
sl@0
   111
sl@0
   112
enum 
sl@0
   113
{ 
sl@0
   114
    PTHREAD_SCOPE_SYSTEM  = 1  /* Default */
sl@0
   115
};
sl@0
   116
sl@0
   117
enum 
sl@0
   118
{  
sl@0
   119
    PTHREAD_CANCEL_ASYNCHRONOUS = 0,  
sl@0
   120
    PTHREAD_CANCEL_DEFERRED = 1  /* Default */
sl@0
   121
};
sl@0
   122
sl@0
   123
enum 
sl@0
   124
{  
sl@0
   125
    PTHREAD_PROCESS_PRIVATE = 0,   
sl@0
   126
};
sl@0
   127
sl@0
   128
enum
sl@0
   129
{
sl@0
   130
  PTHREAD_MUTEX_NORMAL,
sl@0
   131
  PTHREAD_MUTEX_RECURSIVE,
sl@0
   132
  PTHREAD_MUTEX_ERRORCHECK,
sl@0
   133
  PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL
sl@0
   134
};
sl@0
   135
sl@0
   136
sl@0
   137
sl@0
   138
#ifdef __cplusplus
sl@0
   139
extern "C"
sl@0
   140
{
sl@0
   141
#endif    /* __cplusplus */
sl@0
   142
sl@0
   143
typedef void * (*thread_begin_routine)(void *);
sl@0
   144
/*
sl@0
   145
This function creates a thread, with attributes specified by attrib,
sl@0
   146
within a process. If attrib is NULL, then default attributes will be used.
sl@0
   147
On successful completion, pthread_create() will store the ID of the 
sl@0
   148
created thread in the location referenced by threadhdl.
sl@0
   149
*/ 
sl@0
   150
IMPORT_C extern int pthread_create(pthread_t *threadhdl, pthread_attr_t *attrib, 
sl@0
   151
                   thread_begin_routine begin_routine , void * param);  
sl@0
   152
/*
sl@0
   153
This function return the handle to current thread.
sl@0
   154
*/                    
sl@0
   155
IMPORT_C extern pthread_t pthread_self ();
sl@0
   156
sl@0
   157
/*
sl@0
   158
Compare two thread handles
sl@0
   159
*/
sl@0
   160
IMPORT_C extern int pthread_equal(pthread_t t1,pthread_t t2);
sl@0
   161
/*
sl@0
   162
Waiting for thread termination
sl@0
   163
*/
sl@0
   164
IMPORT_C extern int pthread_join(pthread_t thHandle, void **retValPtr);
sl@0
   165
/*
sl@0
   166
detach from thread 
sl@0
   167
*/
sl@0
   168
IMPORT_C extern int pthread_detach(pthread_t thrHandle);
sl@0
   169
/*
sl@0
   170
exit current thread
sl@0
   171
*/
sl@0
   172
IMPORT_C extern void pthread_exit(void *retValPtr);
sl@0
   173
/*
sl@0
   174
Initialise the thread attributes
sl@0
   175
*/
sl@0
   176
IMPORT_C int pthread_attr_init(pthread_attr_t *attrib);
sl@0
   177
/*
sl@0
   178
Destroy the thread attributes
sl@0
   179
*/
sl@0
   180
IMPORT_C int pthread_attr_destroy(pthread_attr_t *attrib);
sl@0
   181
/*
sl@0
   182
Get the detach_state of the current thread
sl@0
   183
*/
sl@0
   184
IMPORT_C int pthread_attr_getdetachstate(const pthread_attr_t *attrib,
sl@0
   185
                                         int *detState);
sl@0
   186
/*
sl@0
   187
Set the detach_state of the current thread
sl@0
   188
*/                                         
sl@0
   189
IMPORT_C int pthread_attr_setdetachstate(pthread_attr_t *attrib, 
sl@0
   190
                                         int detState);                                         
sl@0
   191
/*
sl@0
   192
Get the stack size of the current thread
sl@0
   193
*/
sl@0
   194
IMPORT_C int pthread_attr_getstacksize(const pthread_attr_t *attrib,
sl@0
   195
                                       size_t *stkSize);
sl@0
   196
/*
sl@0
   197
Set the stack size of the current thread
sl@0
   198
*/                                       
sl@0
   199
IMPORT_C int pthread_attr_setstacksize(pthread_attr_t *attrib, 
sl@0
   200
                                       size_t stkSize);                                       
sl@0
   201
sl@0
   202
/*
sl@0
   203
This function ensures that a piece of initialization code is executed at most once. 
sl@0
   204
The once_control argument must point to a static  variable statically initialized to PTHREAD_ONCE_INIT
sl@0
   205
sl@0
   206
*/
sl@0
   207
typedef void (*thread_init_routine) (void);
sl@0
   208
IMPORT_C extern int pthread_once (pthread_once_t * once_control, 
sl@0
   209
                                  thread_init_routine init_routine);
sl@0
   210
sl@0
   211
/*
sl@0
   212
extern int pthread_key_create (pthread_key_t * key, void (*destructor) (void *));
sl@0
   213
extern int pthread_key_delete (pthread_key_t key);
sl@0
   214
extern int pthread_setspecific (pthread_key_t key, const void *value);
sl@0
   215
extern void* pthread_getspecific (pthread_key_t key);
sl@0
   216
*/
sl@0
   217
sl@0
   218
/*
sl@0
   219
This function initializes the mutex attribute object attr and fills it with default values for the attributes.
sl@0
   220
*/
sl@0
   221
IMPORT_C extern int pthread_mutexattr_init (pthread_mutexattr_t * attr);
sl@0
   222
sl@0
   223
/*
sl@0
   224
This function destroys the mutex attribute object attr and marks it as a destroyed object.
sl@0
   225
*/
sl@0
   226
IMPORT_C extern int pthread_mutexattr_destroy (pthread_mutexattr_t * attr);
sl@0
   227
sl@0
   228
/*
sl@0
   229
This function retrieves the current value of the process shared attribute in 
sl@0
   230
attr and stores it in the location pointed to by pshared.
sl@0
   231
*/
sl@0
   232
IMPORT_C extern int pthread_mutexattr_getpshared (const pthread_mutexattr_t* attr, int* pshared);
sl@0
   233
sl@0
   234
/*
sl@0
   235
This function sets the current value of the process shared attribute in attr to the value specifed in the  
sl@0
   236
pshared variable.
sl@0
   237
*/
sl@0
   238
IMPORT_C extern int pthread_mutexattr_setpshared (pthread_mutexattr_t * attr, int pshared);
sl@0
   239
sl@0
   240
/*
sl@0
   241
This function retrieves the current value of the mutex kind attribute in attr and 
sl@0
   242
stores it in the location pointed to by type.
sl@0
   243
*/
sl@0
   244
IMPORT_C extern int pthread_mutexattr_gettype (pthread_mutexattr_t * attr, int *type);
sl@0
   245
sl@0
   246
sl@0
   247
/*
sl@0
   248
This function sets the current value of the mutex kind attribute in attr to the value specifed in the  type variable.
sl@0
   249
*/
sl@0
   250
IMPORT_C extern int pthread_mutexattr_settype (pthread_mutexattr_t * attr, int type);
sl@0
   251
sl@0
   252
/*
sl@0
   253
This function initializes the mutex object pointed to by mutex according to the mutex attributes specified in attr. 
sl@0
   254
If attr is NULL, default attributes are used instead.
sl@0
   255
sl@0
   256
*/
sl@0
   257
IMPORT_C extern int pthread_mutex_init (pthread_mutex_t * mutex, const pthread_mutexattr_t * attr);
sl@0
   258
sl@0
   259
/*
sl@0
   260
This function destroys the mutex object.  The mutex must be unlocked on entrance.
sl@0
   261
This implementation requires even statically initialized mutexes to be explicitly destroyed.
sl@0
   262
*/
sl@0
   263
IMPORT_C extern int pthread_mutex_destroy (pthread_mutex_t * mutex);
sl@0
   264
sl@0
   265
/*
sl@0
   266
This function locks the given mutex. If the mutex is currently
sl@0
   267
unlocked, it becomes locked and owned by the calling thread, and
sl@0
   268
this function  returns immediately. If the mutex is already
sl@0
   269
locked by another thread, this function suspends the calling
sl@0
   270
thread until the mutex is unlocked. 
sl@0
   271
sl@0
   272
If the mutex is already locked by the calling thread, the behavior of
sl@0
   273
this function depends on the kind of the mutex. If the mutex is
sl@0
   274
of the  PTHREAD_MUTEX_NORMAL or PTHREAD_MUTEX_DEFAULT kind, the calling thread is suspended until the mutex
sl@0
   275
is unlocked, thus effectively causing the calling thread to
sl@0
   276
deadlock. If the mutex is of the PTHREAD_MUTEX_ERRORCHECK kind,
sl@0
   277
this function returns immediately with the error code EDEADLK.
sl@0
   278
If the mutex is of the PTHREAD_MUTEX_RECURSIVE kind, this function
sl@0
   279
succeeds and returns immediately, recording the number of times the
sl@0
   280
calling thread has locked the mutex. An equal number of
sl@0
   281
pthread_mutex_unlock operations must be performed before the mutex
sl@0
   282
returns to the unlocked state.
sl@0
   283
*/
sl@0
   284
IMPORT_C extern int pthread_mutex_lock (pthread_mutex_t * mutex);
sl@0
   285
sl@0
   286
sl@0
   287
/*
sl@0
   288
This function behaves identically to pthread_mutex_lock, except that if it cannot acquire the lock before 
sl@0
   289
the abs_timeout time, the call returns with the error code ETIMEDOUT. 
sl@0
   290
*/
sl@0
   291
IMPORT_C extern int pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abstime);
sl@0
   292
sl@0
   293
/*
sl@0
   294
This function behaves identically to pthread_mutex_lock, except that it does not 
sl@0
   295
block the calling thread if the mutex is already locked by another thread (or by 
sl@0
   296
the calling thread in the case of a PTHREAD_MUTEX_RECURSIVE mutex). Instead, pthread_mutex_trylock 
sl@0
   297
returns immediately with the error code EAGAIN.
sl@0
   298
*/
sl@0
   299
IMPORT_C extern int pthread_mutex_trylock (pthread_mutex_t * mutex);
sl@0
   300
sl@0
   301
/*
sl@0
   302
This function unlocks the given mutex. The mutex is assumed
sl@0
   303
to be locked and owned by the calling thread on entrance to
sl@0
   304
this function. If the mutex is of the PTHREAD_MUTEX_NORMAL or PTHREAD_MUTEX_DEFAULT kind,
sl@0
   305
this function always returns it to the unlocked state. If it
sl@0
   306
is of the PTHREAD_MUTEX_RECURSIVE kind, it decrements the locking count of the
sl@0
   307
mutex (number of pthread_mutex_lock operations performed on it by
sl@0
   308
the calling thread), and only when this count reaches zero is the
sl@0
   309
mutex actually unlocked.
sl@0
   310
sl@0
   311
On PTHREAD_MUTEX_ERRORCHECK mutexes, this function actually checks
sl@0
   312
at run-time that the mutex is locked on entrance, and that it was
sl@0
   313
locked by the same thread that is now calling pthread_mutex_unlock.
sl@0
   314
If these conditions are not met, an error code is returned and the
sl@0
   315
mutex remains unchanged.  
sl@0
   316
*/
sl@0
   317
IMPORT_C extern int pthread_mutex_unlock (pthread_mutex_t * mutex);
sl@0
   318
sl@0
   319
/*
sl@0
   320
This function initializes the condition attribute object attr and 
sl@0
   321
sets it with default values for the attributes. 
sl@0
   322
*/
sl@0
   323
IMPORT_C extern int pthread_condattr_init (pthread_condattr_t * /*attr*/);
sl@0
   324
sl@0
   325
/*
sl@0
   326
This function destroys the condtion variable attribute object.
sl@0
   327
*/
sl@0
   328
IMPORT_C extern int pthread_condattr_destroy (pthread_condattr_t * attr);
sl@0
   329
/*
sl@0
   330
extern int pthread_condattr_getpshared (const pthread_condattr_t * attr, int *pshared);
sl@0
   331
extern int pthread_condattr_setpshared (pthread_condattr_t * attr, int pshared);
sl@0
   332
*/
sl@0
   333
sl@0
   334
/*
sl@0
   335
This function initializes the condition variable object pointed to by cond 
sl@0
   336
using the attributes of the attr variable. If attr is NULL, default attributes 
sl@0
   337
are used instead.
sl@0
   338
*/
sl@0
   339
IMPORT_C extern int pthread_cond_init (pthread_cond_t * cond, const pthread_condattr_t * /*attr*/);
sl@0
   340
sl@0
   341
/*
sl@0
   342
This function destroys the condition variable  object. 
sl@0
   343
*/
sl@0
   344
IMPORT_C extern int pthread_cond_destroy (pthread_cond_t * cond);
sl@0
   345
sl@0
   346
/*
sl@0
   347
This function atomically unlocks mutex and waits on cond, 
sl@0
   348
as pthread_cond_wait does, but it also bounds the duration 
sl@0
   349
of the wait. If cond has not been signalled within the amount 
sl@0
   350
of time specified by abstime, the mutex mutex is re-acquired and 
sl@0
   351
pthread_cond_timedwait returns the error ETIMEDOUT. The abstime 
sl@0
   352
parameter specifies an absolute time, with the same origin as time(2) and gettimeofday(2). 
sl@0
   353
*/
sl@0
   354
IMPORT_C extern int pthread_cond_timedwait (pthread_cond_t * cond,pthread_mutex_t * mutex,const struct timespec *abstime);
sl@0
   355
sl@0
   356
/*
sl@0
   357
This function atomically unlocks the mutex (as per pthread_unlock_mutex) 
sl@0
   358
and waits for the condition variable cond to be signalled. The thread 
sl@0
   359
execution is suspended and does not consume any CPU time until the condition 
sl@0
   360
variable is signalled. The mutex must be locked by the calling thread on entrance 
sl@0
   361
to pthread_cond_wait. Before returning to the calling thread, pthread_cond_wait 
sl@0
   362
re-acquires mutex (as per pthread_lock_mutex).
sl@0
   363
*/
sl@0
   364
IMPORT_C extern int pthread_cond_wait (pthread_cond_t * cond, pthread_mutex_t * mutex);
sl@0
   365
sl@0
   366
/*
sl@0
   367
This function restarts one of the threads that are waiting on the condition 
sl@0
   368
variable cond. If no threads are waiting on cond, nothing happens. If several 
sl@0
   369
threads are waiting on cond, exactly one is restarted. 
sl@0
   370
sl@0
   371
*/
sl@0
   372
IMPORT_C extern int pthread_cond_signal (pthread_cond_t * cond);
sl@0
   373
sl@0
   374
/*
sl@0
   375
This function restarts all the threads that are waiting on the 
sl@0
   376
condition variable cond. Nothing happens if no threads are waiting on cond. 
sl@0
   377
*/
sl@0
   378
IMPORT_C extern int pthread_cond_broadcast (pthread_cond_t * cond);
sl@0
   379
sl@0
   380
sl@0
   381
typedef void (*destructor_routine)(void *);
sl@0
   382
/*
sl@0
   383
Thread-specific data key creation
sl@0
   384
*/
sl@0
   385
IMPORT_C int pthread_key_create(pthread_key_t *key, destructor_routine dest);
sl@0
   386
sl@0
   387
/*
sl@0
   388
Thread-specific data key deletion
sl@0
   389
*/
sl@0
   390
IMPORT_C int pthread_key_delete(pthread_key_t key);
sl@0
   391
sl@0
   392
/*
sl@0
   393
Setting Thread-specific data 
sl@0
   394
*/
sl@0
   395
IMPORT_C int pthread_setspecific(pthread_key_t key, const void *val);
sl@0
   396
sl@0
   397
/*
sl@0
   398
Getting Thread-specific data 
sl@0
   399
*/
sl@0
   400
IMPORT_C void* pthread_getspecific(pthread_key_t key);
sl@0
   401
sl@0
   402
/*
sl@0
   403
Getting contention scope 
sl@0
   404
*/
sl@0
   405
IMPORT_C int pthread_attr_getscope(const pthread_attr_t *attrib,
sl@0
   406
                                   int* scope);
sl@0
   407
/*
sl@0
   408
Setting contention scope 
sl@0
   409
*/
sl@0
   410
IMPORT_C int pthread_attr_setscope(pthread_attr_t *attrib,int conscope); 
sl@0
   411
sl@0
   412
/*
sl@0
   413
Setting scheduling policy
sl@0
   414
*/
sl@0
   415
IMPORT_C int pthread_attr_setschedpolicy(pthread_attr_t *attrib, 
sl@0
   416
                                         int policy);                                  
sl@0
   417
sl@0
   418
/*
sl@0
   419
Getting scheduling policy of the thread
sl@0
   420
*/
sl@0
   421
IMPORT_C int pthread_attr_getschedpolicy(const pthread_attr_t *attrib,
sl@0
   422
                                         int *policy);
sl@0
   423
sl@0
   424
/*
sl@0
   425
Getting scheduling param of the thread
sl@0
   426
*/
sl@0
   427
IMPORT_C int pthread_attr_getschedparam(const pthread_attr_t *attrib,
sl@0
   428
                                        struct sched_param *param);
sl@0
   429
sl@0
   430
/*
sl@0
   431
Setting scheduling param
sl@0
   432
*/                                        
sl@0
   433
IMPORT_C int pthread_attr_setschedparam(pthread_attr_t *attrib, 
sl@0
   434
                                        const struct sched_param *param);
sl@0
   435
sl@0
   436
/*
sl@0
   437
Getting dynamic scheduling param of the thread
sl@0
   438
*/                                        
sl@0
   439
IMPORT_C int pthread_getschedparam(pthread_t thr, int *policy,
sl@0
   440
                                   struct sched_param *param);
sl@0
   441
sl@0
   442
/*
sl@0
   443
Dynamically Setting scheduling params
sl@0
   444
*/                                   
sl@0
   445
IMPORT_C int pthread_setschedparam(pthread_t th, int policy, 
sl@0
   446
                                   const struct sched_param *param);
sl@0
   447
                                         
sl@0
   448
#ifdef __cplusplus
sl@0
   449
}                               /* End of  "C" */
sl@0
   450
#endif                          /* __cplusplus */
sl@0
   451
sl@0
   452
sl@0
   453
#endif /* PTHREAD_H */
sl@0
   454