1 /*****************************************************************************
2 * osdep.c: platform-specific code
3 *****************************************************************************
4 * Copyright (C) 2003-2011 x264 project
6 * Authors: Steven Walters <kemuri9@gmail.com>
7 * Laurent Aimar <fenrir@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
23 * This program is also available under a commercial proprietary license.
24 * For more information, contact us at licensing@x264.com.
25 *****************************************************************************/
30 #include <sys/types.h>
31 #include <sys/timeb.h>
38 #define WIN32_LEAN_AND_MEAN
40 /* this is a global in pthread-win32 to indicate if it has been initialized or not */
41 extern int ptw32_processInitialized;
44 int64_t x264_mdate( void )
47 struct timeval tv_date;
48 gettimeofday( &tv_date, NULL );
49 return (int64_t)tv_date.tv_sec * 1000000 + (int64_t)tv_date.tv_usec;
53 return ((int64_t)tb.time * 1000 + (int64_t)tb.millitm) * 1000;
57 #if HAVE_WIN32THREAD || PTW32_STATIC_LIB
58 /* state of the threading library being initialized */
59 static volatile LONG x264_threading_is_init = 0;
61 static void x264_threading_destroy( void )
64 pthread_win32_thread_detach_np();
65 pthread_win32_process_detach_np();
67 x264_win32_threading_destroy();
71 int x264_threading_init( void )
73 /* if already init, then do nothing */
74 if( InterlockedCompareExchange( &x264_threading_is_init, 1, 0 ) )
77 /* if static pthread-win32 is already initialized, then do nothing */
78 if( ptw32_processInitialized )
80 if( !pthread_win32_process_attach_np() )
83 if( x264_win32_threading_init() )
86 /* register cleanup to run at process termination */
87 atexit( x264_threading_destroy );