mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	macro: add PA_ROUND_UP/PA_ROUND_DOWN macros
This commit is contained in:
		
							parent
							
								
									319d187972
								
							
						
					
					
						commit
						fe3a21f6a5
					
				
					 1 changed files with 30 additions and 4 deletions
				
			
		| 
						 | 
					@ -91,7 +91,8 @@ static inline size_t pa_page_align(size_t l) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __GNUC__
 | 
					#ifdef __GNUC__
 | 
				
			||||||
#define PA_MAX(a,b)                             \
 | 
					#define PA_MAX(a,b)                             \
 | 
				
			||||||
    __extension__ ({ typeof(a) _a = (a);        \
 | 
					    __extension__ ({                            \
 | 
				
			||||||
 | 
					            typeof(a) _a = (a);                 \
 | 
				
			||||||
            typeof(b) _b = (b);                 \
 | 
					            typeof(b) _b = (b);                 \
 | 
				
			||||||
            _a > _b ? _a : _b;                  \
 | 
					            _a > _b ? _a : _b;                  \
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
| 
						 | 
					@ -101,7 +102,8 @@ static inline size_t pa_page_align(size_t l) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __GNUC__
 | 
					#ifdef __GNUC__
 | 
				
			||||||
#define PA_MIN(a,b)                             \
 | 
					#define PA_MIN(a,b)                             \
 | 
				
			||||||
    __extension__ ({ typeof(a) _a = (a);        \
 | 
					    __extension__ ({                            \
 | 
				
			||||||
 | 
					            typeof(a) _a = (a);                 \
 | 
				
			||||||
            typeof(b) _b = (b);                 \
 | 
					            typeof(b) _b = (b);                 \
 | 
				
			||||||
            _a < _b ? _a : _b;                  \
 | 
					            _a < _b ? _a : _b;                  \
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
| 
						 | 
					@ -111,7 +113,8 @@ static inline size_t pa_page_align(size_t l) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __GNUC__
 | 
					#ifdef __GNUC__
 | 
				
			||||||
#define PA_CLAMP(x, low, high)                                          \
 | 
					#define PA_CLAMP(x, low, high)                                          \
 | 
				
			||||||
    __extension__ ({ typeof(x) _x = (x);                                \
 | 
					    __extension__ ({                                                    \
 | 
				
			||||||
 | 
					            typeof(x) _x = (x);                                         \
 | 
				
			||||||
            typeof(low) _low = (low);                                   \
 | 
					            typeof(low) _low = (low);                                   \
 | 
				
			||||||
            typeof(high) _high = (high);                                \
 | 
					            typeof(high) _high = (high);                                \
 | 
				
			||||||
            ((_x > _high) ? _high : ((_x < _low) ? _low : _x));         \
 | 
					            ((_x > _high) ? _high : ((_x < _low) ? _low : _x));         \
 | 
				
			||||||
| 
						 | 
					@ -122,7 +125,8 @@ static inline size_t pa_page_align(size_t l) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __GNUC__
 | 
					#ifdef __GNUC__
 | 
				
			||||||
#define PA_CLAMP_UNLIKELY(x, low, high)                                 \
 | 
					#define PA_CLAMP_UNLIKELY(x, low, high)                                 \
 | 
				
			||||||
    __extension__ ({ typeof(x) _x = (x);                                \
 | 
					    __extension__ ({                                                    \
 | 
				
			||||||
 | 
					            typeof(x) _x = (x);                                         \
 | 
				
			||||||
            typeof(low) _low = (low);                                   \
 | 
					            typeof(low) _low = (low);                                   \
 | 
				
			||||||
            typeof(high) _high = (high);                                \
 | 
					            typeof(high) _high = (high);                                \
 | 
				
			||||||
            (PA_UNLIKELY(_x > _high) ? _high : (PA_UNLIKELY(_x < _low) ? _low : _x)); \
 | 
					            (PA_UNLIKELY(_x > _high) ? _high : (PA_UNLIKELY(_x < _low) ? _low : _x)); \
 | 
				
			||||||
| 
						 | 
					@ -135,6 +139,28 @@ static inline size_t pa_page_align(size_t l) {
 | 
				
			||||||
 * make sense: we cannot know if it is more likely that the values is
 | 
					 * make sense: we cannot know if it is more likely that the values is
 | 
				
			||||||
 * lower or greater than the boundaries.*/
 | 
					 * lower or greater than the boundaries.*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __GNUC__
 | 
				
			||||||
 | 
					#define PA_ROUND_UP(a, b)                       \
 | 
				
			||||||
 | 
					    __extension__ ({                            \
 | 
				
			||||||
 | 
					            typeof(a) _a = (a);                 \
 | 
				
			||||||
 | 
					            typeof(b) _b = (b);                 \
 | 
				
			||||||
 | 
					            ((_a + _b - 1) / _b) * _b;          \
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#define PA_ROUND_UP(a, b) ((((a) + (b) - 1) / (b)) * (b))
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __GNUC__
 | 
				
			||||||
 | 
					#define PA_ROUND_DOWN(a, b)                     \
 | 
				
			||||||
 | 
					    __extension__ ({                            \
 | 
				
			||||||
 | 
					            typeof(a) _a = (a);                 \
 | 
				
			||||||
 | 
					            typeof(b) _b = (b);                 \
 | 
				
			||||||
 | 
					            (_a / _b) * _b;                     \
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					#define PA_ROUND_DOWN(a, b) (((a) / (b)) * (b))
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* This type is not intended to be used in exported APIs! Use classic "int" there! */
 | 
					/* This type is not intended to be used in exported APIs! Use classic "int" there! */
 | 
				
			||||||
#ifdef HAVE_STD_BOOL
 | 
					#ifdef HAVE_STD_BOOL
 | 
				
			||||||
typedef _Bool pa_bool_t;
 | 
					typedef _Bool pa_bool_t;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue