and added files
[bcm963xx.git] / userapps / opensource / libosip2 / include / osip2 / osip_mt.h
1 /*
2   The oSIP library implements the Session Initiation Protocol (SIP -rfc2543-)
3   Copyright (C) 2001  Aymeric MOIZARD jack@atosc.org
4   
5   This library is free software; you can redistribute it and/or
6   modify it under the terms of the GNU Lesser General Public
7   License as published by the Free Software Foundation; either
8   version 2.1 of the License, or (at your option) any later version.
9   
10   This library is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   Lesser General Public License for more details.
14   
15   You should have received a copy of the GNU Lesser General Public
16   License along with this library; if not, write to the Free Software
17   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 */
19
20 #ifndef _OSIP_MT_H_
21 #define _OSIP_MT_H_
22
23 #ifdef OSIP_MT
24
25 #ifdef ENABLE_MPATROL
26 #include <mpatrol.h>
27 #endif
28
29 #include <stdio.h>
30 #include <errno.h>
31
32 /**
33  * @file osip_mt.h
34  * @brief oSIP Thread, Mutex and Semaphore definitions
35  *
36  * Those methods are only available if the library is compile
37  * in multi threaded mode. This is the default for oSIP.
38  */
39
40 /**
41  * @defgroup oSIP_THREAD oSIP Thread Routines
42  * @ingroup oSIP
43  * @{
44  */
45
46 #ifdef __cplusplus
47 extern "C"
48 {
49 #endif
50
51 /**
52  * Structure for referencing a thread
53  * @var osip_thread_t
54  */
55   struct osip_thread;
56
57 /**
58  * Allocate (or initialise if a thread address is given)
59  * @param stacksize The stack size of the thread. (20000 is a good value)
60  * @param func The method where the thread start.
61  * @param arg A pointer on the argument given to the method 'func'.
62  */
63   struct osip_thread *osip_thread_create (int stacksize,
64                                           void *(*func) (void *), void *arg);
65
66 /**
67  * Join a thread.
68  * @param thread The thread to join.
69  */
70   int osip_thread_join (struct osip_thread *thread);
71
72 /**
73  * Set the priority of a thread. (NOT IMPLEMENTED ON ALL SYSTEMS)
74  * @param thread The thread to work on.
75  * @param priority The priority value to set.
76  */
77   int osip_thread_set_priority (struct osip_thread *thread, int priority);
78 /**
79  * Exit from a thread.
80  */
81   void osip_thread_exit (void);
82
83 #ifdef __cplusplus
84 }
85 #endif
86
87 /** @} */
88
89 /**
90  * @defgroup oSIP_SEMA oSIP semaphore definitions
91  * @ingroup oSIP
92  * @{
93  */
94
95 #ifdef __cplusplus
96 extern "C"
97 {
98 #endif
99
100 /**
101  * Structure for referencing a semaphore element.
102  * @defvar struct osip_sem
103  */
104   struct osip_sem;
105
106 /**
107  * Allocate and Initialise a semaphore.
108  * @param value The initial value for the semaphore.
109  */
110   struct osip_sem *osip_sem_init (unsigned int value);
111 /**
112  * Destroy a semaphore.
113  * @param sem The semaphore to destroy.
114  */
115   int osip_sem_destroy (struct osip_sem *sem);
116 /**
117  * Post operation on a semaphore.
118  * @param sem The semaphore to destroy.
119  */
120   int osip_sem_post (struct osip_sem *sem);
121 /**
122  * Wait operation on a semaphore.
123  * NOTE: this call will block if the semaphore is at 0.
124  * @param sem The semaphore to destroy.
125  */
126   int osip_sem_wait (struct osip_sem *sem);
127 /**
128  * Wait operation on a semaphore.
129  * NOTE: if the semaphore is at 0, this call won't block.
130  * @param sem The semaphore to destroy.
131  */
132   int osip_sem_trywait (struct osip_sem *sem);
133
134
135 #ifdef __cplusplus
136 }
137 #endif
138
139 /** @} */
140
141 /**
142  * @defgroup oSIP_MUTEX oSIP semaphore definitions
143  * @ingroup oSIP
144  * @{
145  */
146
147 #ifdef __cplusplus
148 extern "C"
149 {
150 #endif
151
152 /**
153  * Structure for referencing a semaphore element.
154  * @defvar struct osip_mutex
155  */
156   struct osip_mutex;
157
158 /**
159  * Allocate and Initialise a semaphore.
160  */
161   struct osip_mutex *osip_mutex_init (void);
162 /**
163  * Destroy the mutex.
164  * @param mut The mutex to destroy.
165  */
166   void osip_mutex_destroy (struct osip_mutex *mut);
167 /**
168  * Lock the mutex.
169  * @param mut The mutex to lock.
170  */
171   int osip_mutex_lock (struct osip_mutex *mut);
172 /**
173  * Unlock the mutex.
174  * @param mut The mutex to unlock.
175  */
176   int osip_mutex_unlock (struct osip_mutex *mut);
177
178 #ifdef __cplusplus
179 }
180 #endif
181
182 /** @} */
183
184 #endif                          /* OSIP_MT */
185
186 #endif                          /* end of _THREAD_H_ */