Merging r46096 through r46110 from trunk into soc-2011-tomato
[blender-staging.git] / source / blender / blenlib / PIL_time.h
1 /* 
2  * Platform independent time functions.
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (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 Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29
30 /** \file blender/blenlib/PIL_time.h
31  *  \ingroup bli
32  */
33
34  
35 #ifndef __PIL_TIME_H__
36 #define __PIL_TIME_H__
37
38 #ifdef __cplusplus
39 extern "C" { 
40 #endif
41
42 extern 
43         /** Return an indication of time, expressed     as
44          * seconds since some fixed point. Successive calls
45          * are guaranteed to generate values greater than or
46          * equal to the last call.
47          */
48 double  PIL_check_seconds_timer         (void);
49
50         /**
51          * Platform-independent sleep function.
52          * \param ms Number of milliseconds to sleep
53          */
54 void    PIL_sleep_ms                            (int ms);
55
56 /** Utility defines for timing.
57  * requires BLI_utildefines.h for 'AT'
58  * TIMEIT_VALUE returns the time since TIMEIT_START was called.
59  */
60 #define TIMEIT_START(var)                                                                                                       \
61 {                                                                                                                                                       \
62         double _timeit_##var= PIL_check_seconds_timer();                                                \
63         printf("time start (" #var "):  " AT "\n");                                                             \
64         fflush(stdout);                                                                                                                 \
65         {                                                                                                                                               \
66
67
68 #define TIMEIT_VALUE(var) (float)(PIL_check_seconds_timer() - _timeit_##var)
69
70
71 #define TIMEIT_END(var)                                                                                                         \
72         }                                                                                                                                               \
73         printf("time end   (" #var "): %.6f" "  " AT "\n",      TIMEIT_VALUE(var));     \
74         fflush(stdout);                                                                                                                 \
75 }                                                                                                                                                       \
76
77 #ifdef __cplusplus
78 }
79 #endif
80
81 #endif /* !__PIL_TIME_H__ */