2 The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-)
3 Copyright (C) 2001,2002,2003 Aymeric MOIZARD jack@atosc.org
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.
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.
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
24 #include <osip2/internal.h>
25 #include <osip2/osip_mt.h>
27 #if defined _WIN32_WCE
29 #define _beginthreadex CreateThread
30 #define _endthreadex ExitThread
35 /* stack size is only needed on VxWorks. */
37 #ifndef __VXWORKS_OS__
38 #if defined(HAVE_PTHREAD) || defined(HAVE_PTH_PTHREAD_H)
40 osip_thread_create (int stacksize, void *(*func) (void *), void *arg)
43 osip_thread_t *thread =
44 (osip_thread_t *) osip_malloc (sizeof (osip_thread_t));
48 i = pthread_create (thread, NULL, func, (void *) arg);
51 OSIP_TRACE (osip_trace
52 (__FILE__, __LINE__, OSIP_ERROR, NULL,
53 "Error while creating a new thread\n"));
56 return (struct osip_thread *) thread;
60 osip_thread_set_priority (struct osip_thread *thread, int priority)
66 osip_thread_join (struct osip_thread *_thread)
68 osip_thread_t *thread = (osip_thread_t *) _thread;
71 return pthread_join (*thread, NULL);
85 osip_thread_create (int stacksize, void *(*func) (void *), void *arg)
87 osip_thread_t *thread =
88 (osip_thread_t *) osip_malloc (sizeof (osip_thread_t));
91 thread->h = (HANDLE) _beginthreadex (NULL, /* default security attr */
92 0, /* use default one */
93 (void *) func, arg, 0, &(thread->id));
99 return (struct osip_thread *) thread;
103 osip_thread_join (struct osip_thread *_thread)
106 osip_thread_t *thread = (osip_thread_t *) _thread;
110 i = WaitForSingleObject (thread->h, INFINITE);
111 if (i == WAIT_OBJECT_0)
113 /* fprintf (stdout, "thread joined!\n"); */
117 /* fprintf (stdout, "ERROR!! thread joined ERROR!!\n"); */
120 CloseHandle (thread->h);
132 osip_thread_set_priority (struct osip_thread *thread, int priority)
140 #ifndef __VXWORKS_OS__
143 osip_thread_create (int stacksize, void *(*func) (void *), void *arg)
145 osip_thread_t *thread =
146 (osip_thread_t *) osip_malloc (sizeof (osip_thread_t));
149 if (t_create ("sip", 150, stacksize, 0, 0, &thread->tid) != 0)
155 if (t_start (thread->tid, T_PREEMPT | T_ISR, func, 0) != 0)
161 return (struct osip_thread *) thread;
165 osip_thread_set_priority (struct osip_thread *_thread, int priority)
167 unsigned long oldprio;
168 osip_thread_t *thread = (osip_thread_t *) _thread;
172 t_set_pri (thread->tid, priority, &oldprio);
177 osip_thread_join (struct osip_thread *_thread)
179 osip_thread_t *thread = (osip_thread_t *) _thread;
182 t_delete (thread->tid);
195 #ifdef __VXWORKS_OS__
197 osip_thread_create (int stacksize, void *(*func) (void *), void *arg)
199 osip_thread_t *thread =
200 (osip_thread_t *) osip_malloc (sizeof (osip_thread_t));
203 thread->id = taskSpawn (NULL, 5, 0, stacksize, (FUNCPTR) func, (int) arg,
204 0, 0, 0, 0, 0, 0, 0, 0, 0);
207 return (struct osip_thread *) thread;
211 osip_thread_set_priority (struct osip_thread *_thread, int priority)
213 osip_thread_t *thread = (osip_thread_t *) _thread;
216 taskPrioritySet (thread->id, 1);
221 osip_thread_join (struct osip_thread *_thread)
223 osip_thread_t *thread = (osip_thread_t *) _thread;
226 return taskDelete (thread->id);