libUPnP  1.8.0
ithread.h
Go to the documentation of this file.
1 /*******************************************************************************
2  *
3  * Copyright (c) 2000-2003 Intel Corporation
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  * * Neither name of Intel Corporation nor the names of its contributors
15  * may be used to endorse or promote products derived from this software
16  * without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  ******************************************************************************/
31 
32 
33 #ifndef ITHREAD_H
34 #define ITHREAD_H
35 
36 
42 #if !defined(WIN32)
43  #include <sys/param.h>
44 #endif
45 
46 
47 #include "UpnpGlobal.h" /* For UPNP_INLINE, EXPORT_SPEC */
48 
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 
55 #include <pthread.h>
56 #ifdef WIN32
57  /* Do not #include <unistd.h> */
58 #else
59  #include <unistd.h>
60 #endif
61 
62 
63 #if defined(BSD)
64  #define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
65 #endif
66 
67 
68 #ifdef PTHREAD_MUTEX_RECURSIVE
69  /* This system has SuS2-compliant mutex attributes.
70  * E.g. on Cygwin, where we don't have the old nonportable (NP) symbols
71  */
72  #define ITHREAD_MUTEX_FAST_NP PTHREAD_MUTEX_NORMAL
73  #define ITHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
74  #define ITHREAD_MUTEX_ERRORCHECK_NP PTHREAD_MUTEX_ERRORCHECK
75 #else /* PTHREAD_MUTEX_RECURSIVE */
76  #define ITHREAD_MUTEX_FAST_NP PTHREAD_MUTEX_FAST_NP
77  #define ITHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE_NP
78  #define ITHREAD_MUTEX_ERRORCHECK_NP PTHREAD_MUTEX_ERRORCHECK_NP
79 #endif /* PTHREAD_MUTEX_RECURSIVE */
80 
81 
82 #define ITHREAD_PROCESS_PRIVATE PTHREAD_PROCESS_PRIVATE
83 #define ITHREAD_PROCESS_SHARED PTHREAD_PROCESS_SHARED
84 
85 
86 #define ITHREAD_CANCELED PTHREAD_CANCELED
87 
88 
89 /***************************************************************************
90  * Name: ithread_t
91  *
92  * Description:
93  * Thread handle.
94  * typedef to pthread_t.
95  * Internal Use Only.
96  ***************************************************************************/
97 typedef pthread_t ithread_t;
98 
99 
100 /****************************************************************************
101  * Name: ithread_attr_t
102  *
103  * Description:
104  * Thread attribute.
105  * typedef to pthread_attr_t
106  * Internal Use Only
107  ***************************************************************************/
108 typedef pthread_attr_t ithread_attr_t;
109 
110 
111 /****************************************************************************
112  * Name: start_routine
113  *
114  * Description:
115  * Thread start routine
116  * Internal Use Only.
117  ***************************************************************************/
118 typedef void *(*start_routine)(void *arg);
119 
120 
121 /****************************************************************************
122  * Name: ithread_cond_t
123  *
124  * Description:
125  * condition variable.
126  * typedef to pthread_cond_t
127  * Internal Use Only.
128  ***************************************************************************/
129 typedef pthread_cond_t ithread_cond_t;
130 
131 
132 /****************************************************************************
133  * Name: ithread_mutexattr_t
134  *
135  * Description:
136  * Mutex attribute.
137  * typedef to pthread_mutexattr_t
138  * Internal Use Only
139  ***************************************************************************/
140 typedef pthread_mutexattr_t ithread_mutexattr_t;
141 
142 
143 /****************************************************************************
144  * Name: ithread_mutex_t
145  *
146  * Description:
147  * Mutex.
148  * typedef to pthread_mutex_t
149  * Internal Use Only.
150  ***************************************************************************/
151 typedef pthread_mutex_t ithread_mutex_t;
152 
153 
154 /****************************************************************************
155  * Name: ithread_condattr_t
156  *
157  * Description:
158  * Condition attribute.
159  * typedef to pthread_condattr_t
160  * NOT USED
161  * Internal Use Only
162  ***************************************************************************/
163 typedef pthread_condattr_t ithread_condattr_t;
164 
165 
166 /****************************************************************************
167  * Name: ithread_rwlockattr_t
168  *
169  * Description:
170  * Mutex attribute.
171  * typedef to pthread_rwlockattr_t
172  * Internal Use Only
173  ***************************************************************************/
174 typedef pthread_rwlockattr_t ithread_rwlockattr_t;
175 
176 
177 /****************************************************************************
178  * Name: ithread_rwlock_t
179  *
180  * Description:
181  * Condition attribute.
182  * typedef to pthread_rwlock_t
183  * Internal Use Only
184  ***************************************************************************/
185 typedef pthread_rwlock_t ithread_rwlock_t;
186 
187 
188 /****************************************************************************
189  * Function: ithread_initialize_library
190  *
191  * Description:
192  * Initializes the library. Does nothing in all implementations, except
193  * when statically linked for WIN32.
194  * Parameters:
195  * none.
196  * Returns:
197  * 0 on success, Nonzero on failure.
198  ***************************************************************************/
199 static UPNP_INLINE int ithread_initialize_library(void) {
200  int ret = 0;
201 
202 #if defined(WIN32) && defined(PTW32_STATIC_LIB)
203  ret = !pthread_win32_process_attach_np();
204 #endif
205 
206  return ret;
207 }
208 
209 
210 /****************************************************************************
211  * Function: ithread_cleanup_library
212  *
213  * Description:
214  * Clean up library resources. Does nothing in all implementations, except
215  * when statically linked for WIN32.
216  * Parameters:
217  * none.
218  * Returns:
219  * 0 on success, Nonzero on failure.
220  ***************************************************************************/
221 static UPNP_INLINE int ithread_cleanup_library(void) {
222  int ret = 0;
223 
224 #if defined(WIN32) && defined(PTW32_STATIC_LIB)
225  ret = !pthread_win32_process_detach_np();
226 #endif
227 
228  return ret;
229 }
230 
231 
232 /****************************************************************************
233  * Function: ithread_initialize_thread
234  *
235  * Description:
236  * Initializes the thread. Does nothing in all implementations, except
237  * when statically linked for WIN32.
238  * Parameters:
239  * none.
240  * Returns:
241  * 0 on success, Nonzero on failure.
242  ***************************************************************************/
243 static UPNP_INLINE int ithread_initialize_thread(void) {
244  int ret = 0;
245 
246 #if defined(WIN32) && defined(PTW32_STATIC_LIB)
247  ret = !pthread_win32_thread_attach_np();
248 #endif
249 
250  return ret;
251 }
252 
253 
254 /****************************************************************************
255  * Function: ithread_cleanup_thread
256  *
257  * Description:
258  * Clean up thread resources. Does nothing in all implementations, except
259  * when statically linked for WIN32.
260  * Parameters:
261  * none.
262  * Returns:
263  * 0 on success, Nonzero on failure.
264  ***************************************************************************/
265 static UPNP_INLINE int ithread_cleanup_thread(void) {
266  int ret = 0;
267 
268 #if defined(WIN32) && defined(PTW32_STATIC_LIB)
269  ret = !pthread_win32_thread_detach_np();
270 #endif
271 
272  return ret;
273 }
274 
275 
276 /****************************************************************************
277  * Function: ithread_mutexattr_init
278  *
279  * Description:
280  * Initializes a mutex attribute variable.
281  * Used to set the type of the mutex.
282  * Parameters:
283  * ithread_mutexattr_init * attr (must be valid non NULL pointer to
284  * pthread_mutexattr_t)
285  * Returns:
286  * 0 on success, Nonzero on failure.
287  * Always returns 0.
288  * See man page for pthread_mutexattr_init
289  ***************************************************************************/
290 #define ithread_mutexattr_init pthread_mutexattr_init
291 
292 
293 /****************************************************************************
294  * Function: ithread_mutexattr_destroy
295  *
296  * Description:
297  * Releases any resources held by the mutex attribute.
298  * Currently there are no resources associated with the attribute
299  * Parameters:
300  * ithread_mutexattr_t * attr (must be valid non NULL pointer to
301  * pthread_mutexattr_t)
302  * Returns:
303  * 0 on success, Nonzero on failure.
304  * Always returns 0.
305  * See man page for pthread_mutexattr_destroy
306  ***************************************************************************/
307 #define ithread_mutexattr_destroy pthread_mutexattr_destroy
308 
309 
310 /****************************************************************************
311  * Function: ithread_mutexattr_setkind_np
312  *
313  * Description:
314  * Sets the mutex type in the attribute.
315  * Valid types are: ITHREAD_MUTEX_FAST_NP
316  * ITHREAD_MUTEX_RECURSIVE_NP
317  * ITHREAD_MUTEX_ERRORCHECK_NP
318  *
319  * Parameters:
320  * ithread_mutexattr_t * attr (must be valid non NULL pointer to
321  * ithread_mutexattr_t)
322  * int kind (one of ITHREAD_MUTEX_FAST_NP or ITHREAD_MUTEX_RECURSIVE_NP
323  * or ITHREAD_MUTEX_ERRORCHECK_NP)
324  * Returns:
325  * 0 on success. Nonzero on failure.
326  * Returns EINVAL if the kind is not supported.
327  * See man page for pthread_mutexattr_setkind_np
328  *****************************************************************************/
329 #ifdef PTHREAD_MUTEX_RECURSIVE
330  #define ithread_mutexattr_setkind_np pthread_mutexattr_settype
331 #else
332  #define ithread_mutexattr_setkind_np pthread_mutexattr_setkind_np
333 #endif
334 
335 /****************************************************************************
336  * Function: ithread_mutexattr_getkind_np
337  *
338  * Description:
339  * Gets the mutex type in the attribute.
340  * Valid types are: ITHREAD_MUTEX_FAST_NP
341  * ITHREAD_MUTEX_RECURSIVE_NP
342  * ITHREAD_MUTEX_ERRORCHECK_NP
343  *
344  * Parameters:
345  * ithread_mutexattr_t * attr (must be valid non NULL pointer to
346  * pthread_mutexattr_t)
347  * int *kind (one of ITHREAD_MUTEX_FAST_NP or ITHREAD_MUTEX_RECURSIVE_NP
348  * or ITHREAD_MUTEX_ERRORCHECK_NP)
349  * Returns:
350  * 0 on success. Nonzero on failure.
351  * Always returns 0.
352  * See man page for pthread_mutexattr_getkind_np
353  *****************************************************************************/
354 #ifdef PTHREAD_MUTEX_RECURSIVE
355  #define ithread_mutexattr_getkind_np pthread_mutexattr_gettype
356 #else
357  #define ithread_mutexattr_getkind_np pthread_mutexattr_getkind_np
358 #endif
359 
360 
361 /****************************************************************************
362  * Function: ithread_mutex_init
363  *
364  * Description:
365  * Initializes mutex.
366  * Must be called before use.
367  *
368  * Parameters:
369  * ithread_mutex_t * mutex (must be valid non NULL pointer to pthread_mutex_t)
370  * const ithread_mutexattr_t * mutex_attr
371  * Returns:
372  * 0 on success, Nonzero on failure.
373  * Always returns 0.
374  * See man page for pthread_mutex_init
375  *****************************************************************************/
376 #define ithread_mutex_init pthread_mutex_init
377 
378 
379 /****************************************************************************
380  * Function: ithread_mutex_lock
381  *
382  * Description:
383  * Locks mutex.
384  * Parameters:
385  * ithread_mutex_t * mutex (must be valid non NULL pointer to pthread_mutex_t)
386  * mutex must be initialized.
387  *
388  * Returns:
389  * 0 on success, Nonzero on failure.
390  * Always returns 0.
391  * See man page for pthread_mutex_lock
392  *****************************************************************************/
393 #define ithread_mutex_lock pthread_mutex_lock
394 
395 
396 /****************************************************************************
397  * Function: ithread_mutex_unlock
398  *
399  * Description:
400  * Unlocks mutex.
401  *
402  * Parameters:
403  * ithread_mutex_t * mutex (must be valid non NULL pointer to pthread_mutex_t)
404  * mutex must be initialized.
405  *
406  * Returns:
407  * 0 on success, Nonzero on failure.
408  * Always returns 0.
409  * See man page for pthread_mutex_unlock
410  *****************************************************************************/
411 #define ithread_mutex_unlock pthread_mutex_unlock
412 
413 
414 /****************************************************************************
415  * Function: ithread_mutex_destroy
416  *
417  * Description:
418  * Releases any resources held by the mutex.
419  * Mutex can no longer be used after this call.
420  * Mutex is only destroyed when there are no longer any threads waiting on it.
421  * Mutex cannot be destroyed if it is locked.
422  * Parameters:
423  * ithread_mutex_t * mutex (must be valid non NULL pointer to pthread_mutex_t)
424  * mutex must be initialized.
425  * Returns:
426  * 0 on success. Nonzero on failure.
427  * Always returns 0.
428  * See man page for pthread_mutex_destroy
429  *****************************************************************************/
430 #define ithread_mutex_destroy pthread_mutex_destroy
431 
432 
433 /****************************************************************************
434  * Function: ithread_rwlockattr_init
435  *
436  * Description:
437  * Initializes a rwlock attribute variable to default values.
438  * Parameters:
439  * const ithread_rwlockattr_init *attr (must be valid non NULL pointer to
440  * pthread_rwlockattr_t)
441  * Returns:
442  * 0 on success, Nonzero on failure.
443  * Always returns 0.
444  * See man page for pthread_rwlockattr_init
445  ***************************************************************************/
446 #define ithread_rwlockattr_init pthread_rwlockattr_init
447 
448 
449 /****************************************************************************
450  * Function: ithread_rwlockattr_destroy
451  *
452  * Description:
453  * Releases any resources held by the rwlock attribute.
454  * Parameters:
455  * ithread_rwlockattr_t *attr (must be valid non NULL pointer to
456  * pthread_rwlockattr_t)
457  * Returns:
458  * 0 on success, Nonzero on failure.
459  * Always returns 0.
460  * See man page for pthread_rwlockattr_destroy
461  ***************************************************************************/
462 #define ithread_rwlockattr_destroy pthread_rwlockattr_destroy
463 
464 
465 /****************************************************************************
466  * Function: ithread_rwlockatttr_setpshared
467  *
468  * Description:
469  * Sets the rwlock type in the attribute.
470  * Valid types are: ITHREAD_PROCESS_PRIVATE
471  * ITHREAD_PROCESS_SHARED
472  *
473  * Parameters:
474  * ithread_rwlockattr_t * attr (must be valid non NULL pointer to
475  * ithread_rwlockattr_t)
476  * int kind (one of ITHREAD_PROCESS_PRIVATE or ITHREAD_PROCESS_SHARED)
477  *
478  * Returns:
479  * 0 on success. Nonzero on failure.
480  * Returns EINVAL if the kind is not supported.
481  * See man page for pthread_rwlockattr_setkind_np
482  *****************************************************************************/
483 #define ithread_rwlockatttr_setpshared pthread_rwlockatttr_setpshared
484 
485 
486 /****************************************************************************
487  * Function: ithread_rwlockatttr_getpshared
488  *
489  * Description:
490  * Gets the rwlock type in the attribute.
491  * Valid types are: ITHREAD_PROCESS_PRIVATE
492  * ITHREAD_PROCESS_SHARED
493  *
494  * Parameters:
495  * ithread_rwlockattr_t * attr (must be valid non NULL pointer to
496  * pthread_rwlockattr_t)
497  * int *kind (one of ITHREAD_PROCESS_PRIVATE or ITHREAD_PROCESS_SHARED)
498  *
499  * Returns:
500  * 0 on success. Nonzero on failure.
501  * Always returns 0.
502  * See man page for pthread_rwlockatttr_getpshared
503  *****************************************************************************/
504 #define ithread_rwlockatttr_getpshared pthread_rwlockatttr_getpshared
505 
506 
507 /****************************************************************************
508  * Function: ithread_rwlock_init
509  *
510  * Description:
511  * Initializes rwlock.
512  * Must be called before use.
513  *
514  * Parameters:
515  * ithread_rwlock_t *rwlock (must be valid non NULL pointer to pthread_rwlock_t)
516  * const ithread_rwlockattr_t *rwlock_attr
517  * Returns:
518  * 0 on success, Nonzero on failure.
519  * Always returns 0.
520  * See man page for pthread_rwlock_init
521  *****************************************************************************/
522 #define ithread_rwlock_init pthread_rwlock_init
523 
524 
525 /****************************************************************************
526  * Function: ithread_rwlock_rdlock
527  *
528  * Description:
529  * Locks rwlock for reading.
530  * Parameters:
531  * ithread_rwlock_t *rwlock (must be valid non NULL pointer to pthread_rwlock_t)
532  * rwlock must be initialized.
533  *
534  * Returns:
535  * 0 on success, Nonzero on failure.
536  * Always returns 0.
537  * See man page for pthread_rwlock_rdlock
538  *****************************************************************************/
539 #define ithread_rwlock_rdlock pthread_rwlock_rdlock
540 
541 
542 /****************************************************************************
543  * Function: ithread_rwlock_wrlock
544  *
545  * Description:
546  * Locks rwlock for writting.
547  * Parameters:
548  * ithread_rwlock_t *rwlock (must be valid non NULL pointer to pthread_rwlock_t)
549  * rwlock must be initialized.
550  *
551  * Returns:
552  * 0 on success, Nonzero on failure.
553  * Always returns 0.
554  * See man page for pthread_rwlock_wrlock
555  *****************************************************************************/
556 #define ithread_rwlock_wrlock pthread_rwlock_wrlock
557 
558 
559 /****************************************************************************
560  * Function: ithread_rwlock_unlock
561  *
562  * Description:
563  * Unlocks rwlock.
564  *
565  * Parameters:
566  * ithread_rwlock_t *rwlock (must be valid non NULL pointer to pthread_rwlock_t)
567  * rwlock must be initialized.
568  *
569  * Returns:
570  * 0 on success, Nonzero on failure.
571  * Always returns 0.
572  * See man page for pthread_rwlock_unlock
573  *****************************************************************************/
574 #define ithread_rwlock_unlock pthread_rwlock_unlock
575 
576 
577 /****************************************************************************
578  * Function: ithread_rwlock_destroy
579  *
580  * Description:
581  * Releases any resources held by the rwlock.
582  * rwlock can no longer be used after this call.
583  * rwlock is only destroyed when there are no longer any threads waiting on it.
584  * rwlock cannot be destroyed if it is locked.
585  * Parameters:
586  * ithread_rwlock_t *rwlock (must be valid non NULL pointer to pthread_rwlock_t)
587  * rwlock must be initialized.
588  * Returns:
589  * 0 on success. Nonzero on failure.
590  * Always returns 0.
591  * See man page for pthread_rwlock_destroy
592  *****************************************************************************/
593 #define ithread_rwlock_destroy pthread_rwlock_destroy
594 
595 
596 /****************************************************************************
597  * Function: ithread_cond_init
598  *
599  * Description:
600  * Initializes condition variable.
601  * Must be called before use.
602  * Parameters:
603  * ithread_cond_t *cond (must be valid non NULL pointer to pthread_cond_t)
604  * const ithread_condattr_t *cond_attr (ignored)
605  * Returns:
606  * 0 on success, Nonzero on failure.
607  * See man page for pthread_cond_init
608  *****************************************************************************/
609 #define ithread_cond_init pthread_cond_init
610 
611 
612 /****************************************************************************
613  * Function: ithread_cond_signal
614  *
615  * Description:
616  * Wakes up exactly one thread waiting on condition.
617  * Associated mutex MUST be locked by thread before entering this call.
618  * Parameters:
619  * ithread_cond_t *cond (must be valid non NULL pointer to
620  * ithread_cond_t)
621  * cond must be initialized
622  * Returns:
623  * 0 on success, Nonzero on failure.
624  * See man page for pthread_cond_signal
625  *****************************************************************************/
626 #define ithread_cond_signal pthread_cond_signal
627 
628 
629 /****************************************************************************
630  * Function: ithread_cond_broadcast
631  *
632  * Description:
633  * Wakes up all threads waiting on condition.
634  * Associated mutex MUST be locked by thread before entering this call.
635  * Parameters:
636  * ithread_cond_t *cond (must be valid non NULL pointer to
637  * ithread_cond_t)
638  * cond must be initialized
639  * Returns:
640  * 0 on success, Nonzero on failure.
641  * See man page for pthread_cond_broadcast
642  *****************************************************************************/
643 #define ithread_cond_broadcast pthread_cond_broadcast
644 
645 
646 /****************************************************************************
647  * Function: ithread_cond_wait
648  *
649  * Description:
650  * Atomically releases mutex and waits on condition.
651  * Associated mutex MUST be locked by thread before entering this call.
652  * Mutex is reacquired when call returns.
653  * Parameters:
654  * ithread_cond_t *cond (must be valid non NULL pointer to
655  * ithread_cond_t)
656  * cond must be initialized
657  * ithread_mutex_t *mutex (must be valid non NULL pointer to
658  * ithread_mutex_t)
659  * Mutex must be locked.
660  * Returns:
661  * 0 on success, Nonzero on failure.
662  * See man page for pthread_cond_wait
663  *****************************************************************************/
664 #define ithread_cond_wait pthread_cond_wait
665 
666 
667  /****************************************************************************
668  * Function: pthread_cond_timedwait
669  *
670  * Description:
671  * Atomically releases the associated mutex and waits on the
672  * condition.
673  * If the condition is not signaled in the specified time than the
674  * call times out and returns.
675  * Associated mutex MUST be locked by thread before entering this call.
676  * Mutex is reacquired when call returns.
677  * Parameters:
678  * ithread_cond_t *cond (must be valid non NULL pointer to ithread_cond_t)
679  * cond must be initialized
680  * ithread_mutex_t *mutex (must be valid non NULL pointer to ithread_mutex_t)
681  * Mutex must be locked.
682  * const struct timespec *abstime (absolute time, measured from Jan 1, 1970)
683  * Returns:
684  * 0 on success. ETIMEDOUT on timeout. Nonzero on failure.
685  * See man page for pthread_cond_timedwait
686  ***************************************************************************/
687 
688 #define ithread_cond_timedwait pthread_cond_timedwait
689 
690 
691  /****************************************************************************
692  * Function: ithread_cond_destroy
693  *
694  * Description:
695  * Releases any resources held by the condition variable.
696  * Condition variable can no longer be used after this call.
697  * Parameters:
698  * ithread_cond_t *cond (must be valid non NULL pointer to
699  * ithread_cond_t)
700  * cond must be initialized.
701  * Returns:
702  * 0 on success. Nonzero on failure.
703  * See man page for pthread_cond_destroy
704  ***************************************************************************/
705 #define ithread_cond_destroy pthread_cond_destroy
706 
707 
708  /****************************************************************************
709  * Function: ithread_create
710  *
711  * Description:
712  * Creates a thread with the given start routine
713  * and argument.
714  * Parameters:
715  * ithread_t * thread (must be valid non NULL pointer to pthread_t)
716  * ithread_attr_t *attr, IGNORED
717  * void * (start_routine) (void *arg) (start routine)
718  * void * arg - argument.
719  * Returns:
720  * 0 on success. Nonzero on failure.
721  * Returns EAGAIN if a new thread can not be created.
722  * Returns EINVAL if there is a problem with the arguments.
723  * See man page fore pthread_create
724  ***************************************************************************/
725 #define ithread_create pthread_create
726 
727 
728  /****************************************************************************
729  * Function: ithread_cancel
730  *
731  * Description:
732  * Cancels a thread.
733  * Parameters:
734  * ithread_t * thread (must be valid non NULL pointer to ithread_t)
735  * Returns:
736  * 0 on success. Nonzero on failure.
737  * See man page for pthread_cancel
738  ***************************************************************************/
739 #define ithread_cancel pthread_cancel
740 
741 
742  /****************************************************************************
743  * Function: ithread_exit
744  *
745  * Description:
746  * Returns a return code from a thread.
747  * Implicitly called when the start routine returns.
748  * Parameters:
749  * void * return_code return code to return
750  * See man page for pthread_exit
751  ***************************************************************************/
752 #define ithread_exit pthread_exit
753 
754 
755 /****************************************************************************
756  * Function: ithread_get_current_thread_id
757  *
758  * Description:
759  * Returns the handle of the currently running thread.
760  * Returns:
761  * The handle of the currently running thread.
762  * See man page for pthread_self
763  ***************************************************************************/
764 #define ithread_get_current_thread_id pthread_self
765 
766 
767  /****************************************************************************
768  * Function: ithread_self
769  *
770  * Description:
771  * Returns the handle of the currently running thread.
772  * Returns:
773  * The handle of the currently running thread.
774  * See man page for pthread_self
775  ***************************************************************************/
776 #define ithread_self pthread_self
777 
778 
779  /****************************************************************************
780  * Function: ithread_detach
781  *
782  * Description:
783  * Makes a thread's resources reclaimed immediately
784  * after it finishes
785  * execution.
786  * Returns:
787  * 0 on success, Nonzero on failure.
788  * See man page for pthread_detach
789  ***************************************************************************/
790 #define ithread_detach pthread_detach
791 
792 
793  /****************************************************************************
794  * Function: ithread_join
795  *
796  * Description:
797  * Suspends the currently running thread until the
798  * specified thread
799  * has finished.
800  * Returns the return code of the thread, or ITHREAD_CANCELED
801  * if the thread has been canceled.
802  * Parameters:
803  * ithread_t *thread (valid non null thread identifier)
804  * void ** return (space for return code)
805  * Returns:
806  * 0 on success, Nonzero on failure.
807  * See man page for pthread_join
808  ***************************************************************************/
809 #define ithread_join pthread_join
810 
811 
812 /****************************************************************************
813  * Function: isleep
814  *
815  * Description:
816  * Suspends the currently running thread for the specified number
817  * of seconds
818  * Always returns 0.
819  * Parameters:
820  * unsigned int seconds - number of seconds to sleep.
821  * Returns:
822  * 0 on success, Nonzero on failure.
823  * See man page for sleep (man 3 sleep)
824  *****************************************************************************/
825 #ifdef WIN32
826  #define isleep(x) Sleep((x)*1000)
827 #else
828  #define isleep sleep
829 #endif
830 
831 
832 /****************************************************************************
833  * Function: isleep
834  *
835  * Description:
836  * Suspends the currently running thread for the specified number
837  * of milliseconds
838  * Always returns 0.
839  * Parameters:
840  * unsigned int milliseconds - number of milliseconds to sleep.
841  * Returns:
842  * 0 on success, Nonzero on failure.
843  * See man page for sleep (man 3 sleep)
844  *****************************************************************************/
845 #ifdef WIN32
846  #define imillisleep Sleep
847 #else
848  #define imillisleep(x) usleep(1000*x)
849 #endif
850 
851 
852 #ifndef PTHREAD_MUTEX_RECURSIVE
853 /* NK: Added for satisfying the gcc compiler */
854 EXPORT_SPEC int pthread_mutexattr_setkind_np(pthread_mutexattr_t *attr, int kind);
855 #endif
856 
857 
858 #ifdef __cplusplus
859 }
860 #endif
861 
862 
863 #endif /* ITHREAD_H */
864 
#define UPNP_INLINE
Declares an inline function.
Definition: UpnpGlobal.h:91
#define EXPORT_SPEC
Export functions on WIN32 DLLs.
Definition: UpnpGlobal.h:82
Defines constants that for some reason are not defined on some systems.