]> git.sesse.net Git - x264/blob - common/osdep.h
98170728a83d3b33e54e244c8c9e3f3898534f6b
[x264] / common / osdep.h
1 /*****************************************************************************
2  * common.h: h264 encoder
3  *****************************************************************************
4  * Copyright (C) 2007 x264 project
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
19  *****************************************************************************/
20
21 #ifndef _OSDEP_H
22 #define _OSDEP_H
23
24 #define _LARGEFILE_SOURCE 1
25 #define _FILE_OFFSET_BITS 64
26 #include <stdio.h>
27
28 #ifdef HAVE_STDINT_H
29 #include <stdint.h>
30 #else
31 #include <inttypes.h>
32 #endif
33
34 #ifdef _MSC_VER
35 #include <io.h>    // _setmode()
36 #include <fcntl.h> // _O_BINARY
37 #define inline __inline
38 #define strcasecmp stricmp
39 #define strncasecmp strnicmp
40 #define snprintf _snprintf
41 #define fseek _fseeki64
42 #define ftell _ftelli64
43 #define isfinite _finite
44 #define _CRT_SECURE_NO_DEPRECATE
45 #define X264_VERSION "" // no configure script for msvc
46 #endif
47
48 #ifdef SYS_OPENBSD
49 #define isfinite finite
50 #endif
51 #if defined(_MSC_VER) || defined(SYS_SunOS) || defined(SYS_MACOSX)
52 #define sqrtf sqrt
53 #endif
54 #ifdef _WIN32
55 #define rename(src,dst) (unlink(dst), rename(src,dst)) // POSIX says that rename() removes the destination, but win32 doesn't.
56 #ifndef strtok_r
57 #define strtok_r(str,delim,save) strtok(str,delim)
58 #endif
59 #endif
60
61 #ifdef _MSC_VER
62 #define DECLARE_ALIGNED( var, n ) __declspec(align(n)) var
63 #else
64 #define DECLARE_ALIGNED( var, n ) var __attribute__((aligned(n)))
65 #endif
66 #define DECLARE_ALIGNED_16( var ) DECLARE_ALIGNED( var, 16 )
67 #define DECLARE_ALIGNED_8( var )  DECLARE_ALIGNED( var, 8 )
68 #define DECLARE_ALIGNED_4( var )  DECLARE_ALIGNED( var, 4 )
69
70 #if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0)
71 #define UNUSED __attribute__((unused))
72 #define ALWAYS_INLINE __attribute__((always_inline)) inline
73 #define NOINLINE __attribute__((noinline))
74 #else
75 #define UNUSED
76 #define ALWAYS_INLINE inline
77 #define NOINLINE
78 #endif
79
80 /* threads */
81 #if defined(SYS_BEOS)
82 #include <kernel/OS.h>
83 #define x264_pthread_t               thread_id
84 #define x264_pthread_create(t,u,f,d) { *(t)=spawn_thread(f,"",10,d); \
85                                        resume_thread(*(t)); }
86 #define x264_pthread_join(t,s)       { long tmp; \
87                                        wait_for_thread(t,(s)?(long*)(s):&tmp); }
88 #ifndef usleep
89 #define usleep(t)                    snooze(t)
90 #endif
91 #define HAVE_PTHREAD 1
92
93 #elif defined(HAVE_PTHREAD)
94 #include <pthread.h>
95 #define USE_REAL_PTHREAD
96
97 #else
98 #define x264_pthread_t               int
99 #define x264_pthread_create(t,u,f,d)
100 #define x264_pthread_join(t,s)
101 #endif //SYS_*
102
103 #ifdef USE_REAL_PTHREAD
104 #define x264_pthread_t               pthread_t
105 #define x264_pthread_create          pthread_create
106 #define x264_pthread_join            pthread_join
107 #define x264_pthread_mutex_t         pthread_mutex_t
108 #define x264_pthread_mutex_init      pthread_mutex_init
109 #define x264_pthread_mutex_destroy   pthread_mutex_destroy
110 #define x264_pthread_mutex_lock      pthread_mutex_lock
111 #define x264_pthread_mutex_unlock    pthread_mutex_unlock
112 #define x264_pthread_cond_t          pthread_cond_t
113 #define x264_pthread_cond_init       pthread_cond_init
114 #define x264_pthread_cond_destroy    pthread_cond_destroy
115 #define x264_pthread_cond_broadcast  pthread_cond_broadcast
116 #define x264_pthread_cond_wait       pthread_cond_wait
117 #else
118 #define x264_pthread_mutex_t         int
119 #define x264_pthread_mutex_init(m,f)
120 #define x264_pthread_mutex_destroy(m)
121 #define x264_pthread_mutex_lock(m)
122 #define x264_pthread_mutex_unlock(m)
123 #define x264_pthread_cond_t          int
124 #define x264_pthread_cond_init(c,f)
125 #define x264_pthread_cond_destroy(c)
126 #define x264_pthread_cond_broadcast(c)
127 #define x264_pthread_cond_wait(c,m)  usleep(100)
128 #endif
129
130 #endif //_OSDEP_H