ithread.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002  *
00003  * Copyright (c) 2000-2003 Intel Corporation 
00004  * All rights reserved. 
00005  *
00006  * Redistribution and use in source and binary forms, with or without 
00007  * modification, are permitted provided that the following conditions are met: 
00008  *
00009  * * Redistributions of source code must retain the above copyright notice, 
00010  * this list of conditions and the following disclaimer. 
00011  * * Redistributions in binary form must reproduce the above copyright notice, 
00012  * this list of conditions and the following disclaimer in the documentation 
00013  * and/or other materials provided with the distribution. 
00014  * * Neither name of Intel Corporation nor the names of its contributors 
00015  * may be used to endorse or promote products derived from this software 
00016  * without specific prior written permission.
00017  * 
00018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00019  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
00020  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
00021  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR 
00022  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00023  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00024  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
00025  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
00026  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00027  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
00028  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  *
00030  ******************************************************************************/
00031 
00032 
00033 #ifndef ITHREAD_H
00034 #define ITHREAD_H
00035 
00036 
00042 #if !defined(WIN32)
00043         #include <sys/param.h>
00044 #endif
00045 
00046 
00047 #include "UpnpGlobal.h" /* For UPNP_INLINE, EXPORT_SPEC */
00048 
00049 
00050 #ifdef __cplusplus
00051 extern "C" {
00052 #endif
00053 
00054 
00055 #include <pthread.h>
00056 #ifdef WIN32
00057         /* Do not #include <unistd.h> */
00058 #else
00059         #include <unistd.h>
00060 #endif
00061 
00062 
00063 #if defined(BSD)
00064         #define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
00065 #endif
00066 
00067 
00068 #ifdef PTHREAD_MUTEX_RECURSIVE
00069         /* This system has SuS2-compliant mutex attributes.
00070          * E.g. on Cygwin, where we don't have the old nonportable (NP) symbols
00071          */
00072         #define ITHREAD_MUTEX_FAST_NP       PTHREAD_MUTEX_NORMAL
00073         #define ITHREAD_MUTEX_RECURSIVE_NP  PTHREAD_MUTEX_RECURSIVE
00074         #define ITHREAD_MUTEX_ERRORCHECK_NP PTHREAD_MUTEX_ERRORCHECK
00075 #else /* PTHREAD_MUTEX_RECURSIVE */
00076         #define ITHREAD_MUTEX_FAST_NP       PTHREAD_MUTEX_FAST_NP
00077         #define ITHREAD_MUTEX_RECURSIVE_NP  PTHREAD_MUTEX_RECURSIVE_NP
00078         #define ITHREAD_MUTEX_ERRORCHECK_NP PTHREAD_MUTEX_ERRORCHECK_NP
00079 #endif /* PTHREAD_MUTEX_RECURSIVE */
00080 
00081 
00082 #define ITHREAD_PROCESS_PRIVATE PTHREAD_PROCESS_PRIVATE
00083 #define ITHREAD_PROCESS_SHARED  PTHREAD_PROCESS_SHARED
00084 
00085 
00086 #define ITHREAD_CANCELED PTHREAD_CANCELED
00087 
00088   
00089 /***************************************************************************
00090  * Name: ithread_t
00091  *
00092  *  Description:
00093  *      Thread handle.
00094  *      typedef to pthread_t.
00095  *      Internal Use Only.
00096  ***************************************************************************/
00097 typedef pthread_t ithread_t;
00098 
00099   
00100 /****************************************************************************
00101  * Name: ithread_attr_t
00102  *
00103  *  Description:
00104  *      Thread attribute.
00105  *      typedef to pthread_attr_t
00106  *      Internal Use Only
00107  ***************************************************************************/
00108 typedef pthread_attr_t ithread_attr_t;  
00109 
00110 
00111 /****************************************************************************
00112  * Name: start_routine
00113  *
00114  *  Description:
00115  *      Thread start routine 
00116  *      Internal Use Only.
00117  ***************************************************************************/
00118 typedef void *(*start_routine)(void *arg);
00119 
00120   
00121 /****************************************************************************
00122  * Name: ithread_cond_t
00123  *
00124  *  Description:
00125  *      condition variable.
00126  *      typedef to pthread_cond_t
00127  *      Internal Use Only.
00128  ***************************************************************************/
00129 typedef pthread_cond_t ithread_cond_t;
00130 
00131 
00132 /****************************************************************************
00133  * Name: ithread_mutexattr_t
00134  *
00135  *  Description:
00136  *      Mutex attribute.
00137  *      typedef to pthread_mutexattr_t
00138  *      Internal Use Only
00139  ***************************************************************************/
00140 typedef pthread_mutexattr_t ithread_mutexattr_t;        
00141 
00142 
00143 /****************************************************************************
00144  * Name: ithread_mutex_t
00145  *
00146  *  Description:
00147  *      Mutex.
00148  *      typedef to pthread_mutex_t
00149  *      Internal Use Only.
00150  ***************************************************************************/
00151 typedef pthread_mutex_t ithread_mutex_t;
00152 
00153 
00154 /****************************************************************************
00155  * Name: ithread_condattr_t
00156  *
00157  *  Description:
00158  *      Condition attribute.
00159  *      typedef to pthread_condattr_t
00160  *      NOT USED
00161  *      Internal Use Only
00162  ***************************************************************************/
00163 typedef pthread_condattr_t ithread_condattr_t;  
00164 
00165 
00166 /****************************************************************************
00167  * Name: ithread_rwlockattr_t
00168  *
00169  *  Description:
00170  *      Mutex attribute.
00171  *      typedef to pthread_rwlockattr_t
00172  *      Internal Use Only
00173  ***************************************************************************/
00174 typedef pthread_rwlockattr_t ithread_rwlockattr_t;      
00175 
00176 
00177 /****************************************************************************
00178  * Name: ithread_rwlock_t
00179  *
00180  *  Description:
00181  *      Condition attribute.
00182  *      typedef to pthread_rwlock_t
00183  *      Internal Use Only
00184  ***************************************************************************/
00185 typedef pthread_rwlock_t ithread_rwlock_t;
00186 
00187 
00188 /****************************************************************************
00189  * Function: ithread_initialize_library
00190  *
00191  *  Description:
00192  *      Initializes the library. Does nothing in all implementations, except
00193  *      when statically linked for WIN32.
00194  *  Parameters:
00195  *      none.
00196  *  Returns:
00197  *      0 on success, Nonzero on failure.
00198  ***************************************************************************/
00199 static UPNP_INLINE int ithread_initialize_library(void) {
00200         int ret = 0;
00201 
00202 #if defined(WIN32) && defined(PTW32_STATIC_LIB)
00203         ret = !pthread_win32_process_attach_np();
00204 #endif
00205 
00206         return ret;
00207 }
00208 
00209 
00210 /****************************************************************************
00211  * Function: ithread_cleanup_library
00212  *
00213  *  Description:
00214  *      Clean up library resources. Does nothing in all implementations, except
00215  *      when statically linked for WIN32.
00216  *  Parameters:
00217  *      none.
00218  *  Returns:
00219  *      0 on success, Nonzero on failure.
00220  ***************************************************************************/
00221 static UPNP_INLINE int ithread_cleanup_library(void) {
00222         int ret = 0;
00223 
00224 #if defined(WIN32) && defined(PTW32_STATIC_LIB)
00225         ret = !pthread_win32_process_detach_np();
00226 #endif
00227 
00228         return ret;
00229 }
00230 
00231 
00232 /****************************************************************************
00233  * Function: ithread_initialize_thread
00234  *
00235  *  Description:
00236  *      Initializes the thread. Does nothing in all implementations, except
00237  *      when statically linked for WIN32.
00238  *  Parameters:
00239  *      none.
00240  *  Returns:
00241  *      0 on success, Nonzero on failure.
00242  ***************************************************************************/
00243 static UPNP_INLINE int ithread_initialize_thread(void) {
00244         int ret = 0;
00245 
00246 #if defined(WIN32) && defined(PTW32_STATIC_LIB)
00247         ret = !pthread_win32_thread_attach_np();
00248 #endif
00249 
00250         return ret;
00251 }
00252 
00253 
00254 /****************************************************************************
00255  * Function: ithread_cleanup_thread
00256  *
00257  *  Description:
00258  *      Clean up thread resources. Does nothing in all implementations, except
00259  *      when statically linked for WIN32.
00260  *  Parameters:
00261  *      none.
00262  *  Returns:
00263  *      0 on success, Nonzero on failure.
00264  ***************************************************************************/
00265 static UPNP_INLINE int ithread_cleanup_thread(void) {
00266         int ret = 0;
00267 
00268 #if defined(WIN32) && defined(PTW32_STATIC_LIB)
00269         ret = !pthread_win32_thread_detach_np();
00270 #endif
00271 
00272         return ret;
00273 }
00274 
00275 
00276 /****************************************************************************
00277  * Function: ithread_mutexattr_init
00278  *
00279  *  Description:
00280  *      Initializes a mutex attribute variable.
00281  *      Used to set the type of the mutex.
00282  *  Parameters:
00283  *      ithread_mutexattr_init * attr (must be valid non NULL pointer to 
00284  *                                     pthread_mutexattr_t)
00285  *  Returns:
00286  *      0 on success, Nonzero on failure.
00287  *      Always returns 0.
00288  *      See man page for pthread_mutexattr_init
00289  ***************************************************************************/
00290 #define ithread_mutexattr_init pthread_mutexattr_init
00291 
00292 
00293 /****************************************************************************
00294  * Function: ithread_mutexattr_destroy
00295  *
00296  *  Description:
00297  *      Releases any resources held by the mutex attribute.
00298  *      Currently there are no resources associated with the attribute
00299  *  Parameters:
00300  *      ithread_mutexattr_t * attr (must be valid non NULL pointer to 
00301  *                                  pthread_mutexattr_t)
00302  *  Returns:
00303  *      0 on success, Nonzero on failure.
00304  *      Always returns 0.
00305  *      See man page for pthread_mutexattr_destroy
00306  ***************************************************************************/
00307 #define ithread_mutexattr_destroy pthread_mutexattr_destroy
00308   
00309   
00310 /****************************************************************************
00311  * Function: ithread_mutexattr_setkind_np
00312  *
00313  *  Description:
00314  *      Sets the mutex type in the attribute.
00315  *      Valid types are: ITHREAD_MUTEX_FAST_NP 
00316  *                       ITHREAD_MUTEX_RECURSIVE_NP 
00317  *                       ITHREAD_MUTEX_ERRORCHECK_NP
00318  *
00319  *  Parameters:
00320  *      ithread_mutexattr_t * attr (must be valid non NULL pointer to 
00321  *                                   ithread_mutexattr_t)
00322  *      int kind (one of ITHREAD_MUTEX_FAST_NP or ITHREAD_MUTEX_RECURSIVE_NP
00323  *                or ITHREAD_MUTEX_ERRORCHECK_NP)
00324  *  Returns:
00325  *      0 on success. Nonzero on failure.
00326  *      Returns EINVAL if the kind is not supported.
00327  *      See man page for pthread_mutexattr_setkind_np
00328  *****************************************************************************/
00329 #ifdef PTHREAD_MUTEX_RECURSIVE
00330         #define ithread_mutexattr_setkind_np pthread_mutexattr_settype
00331 #else
00332         #define ithread_mutexattr_setkind_np pthread_mutexattr_setkind_np
00333 #endif
00334 
00335 /****************************************************************************
00336  * Function: ithread_mutexattr_getkind_np
00337  *
00338  *  Description:
00339  *      Gets the mutex type in the attribute.
00340  *      Valid types are: ITHREAD_MUTEX_FAST_NP 
00341  *                       ITHREAD_MUTEX_RECURSIVE_NP 
00342  *                       ITHREAD_MUTEX_ERRORCHECK_NP
00343  *
00344  *  Parameters:
00345  *      ithread_mutexattr_t * attr (must be valid non NULL pointer to 
00346  *                                   pthread_mutexattr_t)
00347  *      int *kind (one of ITHREAD_MUTEX_FAST_NP or ITHREAD_MUTEX_RECURSIVE_NP
00348  *                or ITHREAD_MUTEX_ERRORCHECK_NP)
00349  *  Returns:
00350  *      0 on success. Nonzero on failure.
00351  *      Always returns 0.
00352  *      See man page for pthread_mutexattr_getkind_np
00353  *****************************************************************************/
00354 #ifdef PTHREAD_MUTEX_RECURSIVE
00355         #define ithread_mutexattr_getkind_np pthread_mutexattr_gettype
00356 #else
00357         #define ithread_mutexattr_getkind_np pthread_mutexattr_getkind_np
00358 #endif
00359 
00360   
00361 /****************************************************************************
00362  * Function: ithread_mutex_init
00363  *
00364  *  Description:
00365  *      Initializes mutex.
00366  *      Must be called before use.
00367  *      
00368  *  Parameters:
00369  *      ithread_mutex_t * mutex (must be valid non NULL pointer to pthread_mutex_t)
00370  *      const ithread_mutexattr_t * mutex_attr 
00371  *  Returns:
00372  *      0 on success, Nonzero on failure.
00373  *      Always returns 0.
00374  *      See man page for pthread_mutex_init
00375  *****************************************************************************/
00376 #define ithread_mutex_init pthread_mutex_init
00377 
00378 
00379 /****************************************************************************
00380  * Function: ithread_mutex_lock
00381  *
00382  *  Description:
00383  *      Locks mutex.
00384  *  Parameters:
00385  *      ithread_mutex_t * mutex (must be valid non NULL pointer to pthread_mutex_t)
00386  *      mutex must be initialized.
00387  *      
00388  *  Returns:
00389  *      0 on success, Nonzero on failure.
00390  *      Always returns 0.
00391  *      See man page for pthread_mutex_lock
00392  *****************************************************************************/
00393 #define ithread_mutex_lock pthread_mutex_lock
00394   
00395 
00396 /****************************************************************************
00397  * Function: ithread_mutex_unlock
00398  *
00399  *  Description:
00400  *      Unlocks mutex.
00401  *
00402  *  Parameters:
00403  *      ithread_mutex_t * mutex (must be valid non NULL pointer to pthread_mutex_t)
00404  *      mutex must be initialized.
00405  *      
00406  *  Returns:
00407  *      0 on success, Nonzero on failure.
00408  *      Always returns 0.
00409  *      See man page for pthread_mutex_unlock
00410  *****************************************************************************/
00411 #define ithread_mutex_unlock pthread_mutex_unlock
00412 
00413 
00414 /****************************************************************************
00415  * Function: ithread_mutex_destroy
00416  *
00417  *  Description:
00418  *      Releases any resources held by the mutex. 
00419  *              Mutex can no longer be used after this call.
00420  *              Mutex is only destroyed when there are no longer any threads waiting on it. 
00421  *              Mutex cannot be destroyed if it is locked.
00422  *  Parameters:
00423  *      ithread_mutex_t * mutex (must be valid non NULL pointer to pthread_mutex_t)
00424  *      mutex must be initialized.
00425  *  Returns:
00426  *      0 on success. Nonzero on failure.
00427  *      Always returns 0.
00428  *      See man page for pthread_mutex_destroy
00429  *****************************************************************************/
00430 #define ithread_mutex_destroy pthread_mutex_destroy
00431 
00432 
00433 /****************************************************************************
00434  * Function: ithread_rwlockattr_init
00435  *
00436  *  Description:
00437  *      Initializes a rwlock attribute variable to default values.
00438  *  Parameters:
00439  *      const ithread_rwlockattr_init *attr (must be valid non NULL pointer to 
00440  *                                           pthread_rwlockattr_t)
00441  *  Returns:
00442  *      0 on success, Nonzero on failure.
00443  *      Always returns 0.
00444  *      See man page for pthread_rwlockattr_init
00445  ***************************************************************************/
00446 #define ithread_rwlockattr_init pthread_rwlockattr_init
00447 
00448 
00449 /****************************************************************************
00450  * Function: ithread_rwlockattr_destroy
00451  *
00452  *  Description:
00453  *      Releases any resources held by the rwlock attribute.
00454  *  Parameters:
00455  *      ithread_rwlockattr_t *attr (must be valid non NULL pointer to 
00456  *                                  pthread_rwlockattr_t)
00457  *  Returns:
00458  *      0 on success, Nonzero on failure.
00459  *      Always returns 0.
00460  *      See man page for pthread_rwlockattr_destroy
00461  ***************************************************************************/
00462 #define ithread_rwlockattr_destroy pthread_rwlockattr_destroy
00463   
00464   
00465 /****************************************************************************
00466  * Function: ithread_rwlockatttr_setpshared
00467  *
00468  *  Description:
00469  *      Sets the rwlock type in the attribute.
00470  *      Valid types are: ITHREAD_PROCESS_PRIVATE 
00471  *                       ITHREAD_PROCESS_SHARED
00472  *
00473  *  Parameters:
00474  *      ithread_rwlockattr_t * attr (must be valid non NULL pointer to 
00475  *                                   ithread_rwlockattr_t)
00476  *      int kind (one of ITHREAD_PROCESS_PRIVATE or ITHREAD_PROCESS_SHARED)
00477  *
00478  *  Returns:
00479  *      0 on success. Nonzero on failure.
00480  *      Returns EINVAL if the kind is not supported.
00481  *      See man page for pthread_rwlockattr_setkind_np
00482  *****************************************************************************/
00483 #define ithread_rwlockatttr_setpshared pthread_rwlockatttr_setpshared
00484 
00485 
00486 /****************************************************************************
00487  * Function: ithread_rwlockatttr_getpshared
00488  *
00489  *  Description:
00490  *      Gets the rwlock type in the attribute.
00491  *      Valid types are: ITHREAD_PROCESS_PRIVATE 
00492  *                       ITHREAD_PROCESS_SHARED 
00493  *
00494  *  Parameters:
00495  *      ithread_rwlockattr_t * attr (must be valid non NULL pointer to 
00496  *                                   pthread_rwlockattr_t)
00497  *      int *kind (one of ITHREAD_PROCESS_PRIVATE or ITHREAD_PROCESS_SHARED)
00498  *
00499  *  Returns:
00500  *      0 on success. Nonzero on failure.
00501  *      Always returns 0.
00502  *      See man page for pthread_rwlockatttr_getpshared
00503  *****************************************************************************/
00504 #define ithread_rwlockatttr_getpshared pthread_rwlockatttr_getpshared
00505 
00506   
00507 /****************************************************************************
00508  * Function: ithread_rwlock_init
00509  *
00510  *  Description:
00511  *      Initializes rwlock.
00512  *      Must be called before use.
00513  *      
00514  *  Parameters:
00515  *      ithread_rwlock_t *rwlock (must be valid non NULL pointer to pthread_rwlock_t)
00516  *      const ithread_rwlockattr_t *rwlock_attr 
00517  *  Returns:
00518  *      0 on success, Nonzero on failure.
00519  *      Always returns 0.
00520  *      See man page for pthread_rwlock_init
00521  *****************************************************************************/
00522 #define ithread_rwlock_init pthread_rwlock_init
00523 
00524 
00525 /****************************************************************************
00526  * Function: ithread_rwlock_rdlock
00527  *
00528  *  Description:
00529  *      Locks rwlock for reading.
00530  *  Parameters:
00531  *      ithread_rwlock_t *rwlock (must be valid non NULL pointer to pthread_rwlock_t)
00532  *      rwlock must be initialized.
00533  *      
00534  *  Returns:
00535  *      0 on success, Nonzero on failure.
00536  *      Always returns 0.
00537  *      See man page for pthread_rwlock_rdlock
00538  *****************************************************************************/
00539 #define ithread_rwlock_rdlock pthread_rwlock_rdlock
00540 
00541 
00542 /****************************************************************************
00543  * Function: ithread_rwlock_wrlock
00544  *
00545  *  Description:
00546  *      Locks rwlock for writting.
00547  *  Parameters:
00548  *      ithread_rwlock_t *rwlock (must be valid non NULL pointer to pthread_rwlock_t)
00549  *      rwlock must be initialized.
00550  *      
00551  *  Returns:
00552  *      0 on success, Nonzero on failure.
00553  *      Always returns 0.
00554  *      See man page for pthread_rwlock_wrlock
00555  *****************************************************************************/
00556 #define ithread_rwlock_wrlock pthread_rwlock_wrlock
00557 
00558 
00559 /****************************************************************************
00560  * Function: ithread_rwlock_unlock
00561  *
00562  *  Description:
00563  *      Unlocks rwlock.
00564  *
00565  *  Parameters:
00566  *      ithread_rwlock_t *rwlock (must be valid non NULL pointer to pthread_rwlock_t)
00567  *      rwlock must be initialized.
00568  *      
00569  *  Returns:
00570  *      0 on success, Nonzero on failure.
00571  *      Always returns 0.
00572  *      See man page for pthread_rwlock_unlock
00573  *****************************************************************************/
00574 #define ithread_rwlock_unlock pthread_rwlock_unlock
00575 
00576 
00577 /****************************************************************************
00578  * Function: ithread_rwlock_destroy
00579  *
00580  *  Description:
00581  *      Releases any resources held by the rwlock. 
00582  *              rwlock can no longer be used after this call.
00583  *              rwlock is only destroyed when there are no longer any threads waiting on it. 
00584  *              rwlock cannot be destroyed if it is locked.
00585  *  Parameters:
00586  *      ithread_rwlock_t *rwlock (must be valid non NULL pointer to pthread_rwlock_t)
00587  *      rwlock must be initialized.
00588  *  Returns:
00589  *      0 on success. Nonzero on failure.
00590  *      Always returns 0.
00591  *      See man page for pthread_rwlock_destroy
00592  *****************************************************************************/
00593 #define ithread_rwlock_destroy pthread_rwlock_destroy
00594 
00595 
00596 /****************************************************************************
00597  * Function: ithread_cond_init
00598  *
00599  *  Description:
00600  *      Initializes condition variable.
00601  *      Must be called before use.
00602  *  Parameters:
00603  *      ithread_cond_t *cond (must be valid non NULL pointer to pthread_cond_t)
00604  *      const ithread_condattr_t *cond_attr (ignored)
00605  *  Returns:
00606  *      0 on success, Nonzero on failure.
00607  *      See man page for pthread_cond_init
00608  *****************************************************************************/
00609 #define ithread_cond_init pthread_cond_init
00610 
00611 
00612 /****************************************************************************
00613  * Function: ithread_cond_signal
00614  *
00615  *  Description:
00616  *      Wakes up exactly one thread waiting on condition.
00617  *      Associated mutex MUST be locked by thread before entering this call.
00618  *  Parameters:
00619  *      ithread_cond_t *cond (must be valid non NULL pointer to 
00620  *      ithread_cond_t)
00621  *      cond must be initialized
00622  *  Returns:
00623  *      0 on success, Nonzero on failure.
00624  *      See man page for pthread_cond_signal
00625  *****************************************************************************/
00626 #define ithread_cond_signal pthread_cond_signal
00627 
00628 
00629 /****************************************************************************
00630  * Function: ithread_cond_broadcast
00631  *
00632  *  Description:
00633  *      Wakes up all threads waiting on condition.
00634  *      Associated mutex MUST be locked by thread before entering this call.
00635  *  Parameters:
00636  *      ithread_cond_t *cond (must be valid non NULL pointer to 
00637  *      ithread_cond_t)
00638  *      cond must be initialized
00639  *  Returns:
00640  *      0 on success, Nonzero on failure.
00641  *      See man page for pthread_cond_broadcast
00642  *****************************************************************************/
00643 #define ithread_cond_broadcast pthread_cond_broadcast
00644   
00645 
00646 /****************************************************************************
00647  * Function: ithread_cond_wait
00648  *
00649  *  Description:
00650  *      Atomically releases mutex and waits on condition.
00651  *      Associated mutex MUST be locked by thread before entering this call.
00652  *      Mutex is reacquired when call returns.
00653  *  Parameters:
00654  *      ithread_cond_t *cond (must be valid non NULL pointer to 
00655  *      ithread_cond_t)
00656  *      cond must be initialized
00657  *      ithread_mutex_t *mutex (must be valid non NULL pointer to 
00658  *      ithread_mutex_t)
00659  *      Mutex must be locked.
00660  *  Returns:
00661  *      0 on success, Nonzero on failure.
00662  *      See man page for pthread_cond_wait
00663  *****************************************************************************/
00664 #define ithread_cond_wait pthread_cond_wait
00665   
00666 
00667   /****************************************************************************
00668    * Function: pthread_cond_timedwait
00669    *
00670    *    Description:      
00671    *            Atomically releases the associated mutex and waits on the
00672    *    condition.
00673    *            If the condition is not signaled in the specified time than the
00674    *    call times out and returns.
00675    *            Associated mutex MUST be locked by thread before entering this call.
00676    *            Mutex is reacquired when call returns.
00677    *  Parameters:
00678    *      ithread_cond_t *cond (must be valid non NULL pointer to ithread_cond_t)
00679    *            cond must be initialized
00680    *      ithread_mutex_t *mutex (must be valid non NULL pointer to ithread_mutex_t)
00681    *            Mutex must be locked.
00682    *      const struct timespec *abstime (absolute time, measured from Jan 1, 1970)
00683    *  Returns:
00684    *      0 on success. ETIMEDOUT on timeout. Nonzero on failure.
00685    *      See man page for pthread_cond_timedwait
00686    ***************************************************************************/
00687  
00688 #define ithread_cond_timedwait pthread_cond_timedwait
00689   
00690 
00691   /****************************************************************************
00692    * Function: ithread_cond_destroy
00693    *
00694    *  Description:
00695    *      Releases any resources held by the condition variable. 
00696    *            Condition variable can no longer be used after this call.       
00697    *  Parameters:
00698    *      ithread_cond_t *cond (must be valid non NULL pointer to 
00699    *      ithread_cond_t)
00700    *      cond must be initialized.
00701    *  Returns:
00702    *      0 on success. Nonzero on failure.
00703    *      See man page for pthread_cond_destroy
00704    ***************************************************************************/
00705 #define ithread_cond_destroy pthread_cond_destroy
00706 
00707 
00708   /****************************************************************************
00709    * Function: ithread_create
00710    *
00711    *  Description:
00712    *            Creates a thread with the given start routine
00713    *      and argument.
00714    *  Parameters:
00715    *      ithread_t * thread (must be valid non NULL pointer to pthread_t)
00716    *      ithread_attr_t *attr, IGNORED
00717    *      void * (start_routine) (void *arg) (start routine)
00718    *      void * arg - argument.
00719    *  Returns:
00720    *      0 on success. Nonzero on failure.
00721    *        Returns EAGAIN if a new thread can not be created.
00722    *      Returns EINVAL if there is a problem with the arguments.
00723    *      See man page fore pthread_create
00724    ***************************************************************************/
00725 #define ithread_create pthread_create
00726 
00727 
00728   /****************************************************************************
00729    * Function: ithread_cancel
00730    *
00731    *  Description:
00732    *            Cancels a thread.
00733    *  Parameters:
00734    *      ithread_t * thread (must be valid non NULL pointer to ithread_t)
00735    *  Returns:
00736    *      0 on success. Nonzero on failure.
00737    *      See man page for pthread_cancel
00738    ***************************************************************************/
00739 #define ithread_cancel pthread_cancel
00740   
00741 
00742   /****************************************************************************
00743    * Function: ithread_exit
00744    *
00745    *  Description:
00746    *            Returns a return code from a thread.
00747    *      Implicitly called when the start routine returns.
00748    *  Parameters:
00749    *      void  * return_code return code to return
00750    *      See man page for pthread_exit
00751    ***************************************************************************/
00752 #define ithread_exit pthread_exit
00753 
00754 
00755 /****************************************************************************
00756    * Function: ithread_get_current_thread_id
00757    *
00758    *  Description:
00759    *            Returns the handle of the currently running thread.
00760    *  Returns:
00761    *            The handle of the currently running thread.
00762    *              See man page for pthread_self
00763    ***************************************************************************/
00764 #define ithread_get_current_thread_id pthread_self
00765 
00766 
00767   /****************************************************************************
00768    * Function: ithread_self
00769    *
00770    *  Description:
00771    *            Returns the handle of the currently running thread.
00772    *  Returns:
00773    *            The handle of the currently running thread.
00774    *              See man page for pthread_self
00775    ***************************************************************************/
00776 #define ithread_self pthread_self
00777 
00778 
00779   /****************************************************************************
00780    * Function: ithread_detach
00781    *
00782    *  Description:
00783    *            Makes a thread's resources reclaimed immediately 
00784    *            after it finishes
00785    *            execution.  
00786    *  Returns:
00787    *            0 on success, Nonzero on failure.
00788    *      See man page for pthread_detach
00789    ***************************************************************************/
00790 #define ithread_detach pthread_detach  
00791 
00792 
00793   /****************************************************************************
00794    * Function: ithread_join
00795    *
00796    *  Description:
00797    *            Suspends the currently running thread until the 
00798    * specified thread
00799    *      has finished. 
00800    *      Returns the return code of the thread, or ITHREAD_CANCELED 
00801    *      if the thread has been canceled.
00802    *  Parameters:
00803    *      ithread_t *thread (valid non null thread identifier)
00804    *      void ** return (space for return code) 
00805    *  Returns:
00806    *            0 on success, Nonzero on failure.
00807    *     See man page for pthread_join
00808    ***************************************************************************/
00809 #define ithread_join pthread_join
00810   
00811 
00812 /****************************************************************************
00813  * Function: isleep
00814  *
00815  *  Description:
00816  *              Suspends the currently running thread for the specified number 
00817  *      of seconds
00818  *      Always returns 0.
00819  *  Parameters:
00820  *      unsigned int seconds - number of seconds to sleep.
00821  *  Returns:
00822  *              0 on success, Nonzero on failure.
00823  *              See man page for sleep (man 3 sleep)
00824  *****************************************************************************/
00825 #ifdef WIN32
00826         #define isleep(x) Sleep((x)*1000)
00827 #else
00828         #define isleep sleep
00829 #endif
00830 
00831 
00832 /****************************************************************************
00833  * Function: isleep
00834  *
00835  *  Description:
00836  *              Suspends the currently running thread for the specified number 
00837  *      of milliseconds
00838  *      Always returns 0.
00839  *  Parameters:
00840  *      unsigned int milliseconds - number of milliseconds to sleep.
00841  *  Returns:
00842  *              0 on success, Nonzero on failure.
00843  *              See man page for sleep (man 3 sleep)
00844  *****************************************************************************/
00845 #ifdef WIN32
00846         #define imillisleep Sleep
00847 #else
00848         #define imillisleep(x) usleep(1000*x)
00849 #endif
00850 
00851 
00852 #ifndef PTHREAD_MUTEX_RECURSIVE
00853 /* NK: Added for satisfying the gcc compiler */
00854 EXPORT_SPEC int pthread_mutexattr_setkind_np(pthread_mutexattr_t *attr, int kind);
00855 #endif
00856 
00857 
00858 #ifdef __cplusplus
00859 }
00860 #endif
00861 
00862 
00863 #endif /* ITHREAD_H */
00864 
Generated on Fri May 21 00:33:57 2010 for libUPnP by  doxygen 1.6.3