1 /*  Thread compatibility glue
2  *  Copyright (C) 2009 Howard Chu
3  *
4  *  This Program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2, or (at your option)
7  *  any later version.
8  *
9  *  This Program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with RTMPDump; see the file COPYING.  If not, write to
16  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  *  Boston, MA  02110-1301, USA.
18  *  http://www.gnu.org/copyleft/gpl.html
19  *
20  */
21 
22 #include "thread.h"
23 #include "librtmp/log.h"
24 
25 #ifdef WIN32
26 
27 #include <errno.h>
28 
29 HANDLE
ThreadCreate(thrfunc * routine,void * args)30 ThreadCreate(thrfunc *routine, void *args)
31 {
32   HANDLE thd;
33 
34   thd = (HANDLE) _beginthread(routine, 0, args);
35   if (thd == -1L)
36     RTMP_LogPrintf("%s, _beginthread failed with %d\n", __FUNCTION__, errno);
37 
38   return thd;
39 }
40 #else
41 pthread_t
ThreadCreate(thrfunc * routine,void * args)42 ThreadCreate(thrfunc *routine, void *args)
43 {
44   pthread_t id = 0;
45   pthread_attr_t attributes;
46   int ret;
47 
48   pthread_attr_init(&attributes);
49   pthread_attr_setdetachstate(&attributes, PTHREAD_CREATE_DETACHED);
50 
51   ret =
52     pthread_create(&id, &attributes, routine, args);
53   if (ret != 0)
54     RTMP_LogPrintf("%s, pthread_create failed with %d\n", __FUNCTION__, ret);
55 
56   return id;
57 }
58 #endif
59