1 /*****************************************************************************
2 * Copyright 2005 Daniel Ferullo *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
16 *****************************************************************************/
20 * @author Daniel Ferullo (ferullo@cmu.edu)
22 * @brief contains useful utility functions
28 #include "errorcodes.h"
32 * @brief decrements a signed number by one, but not past zero
34 * @param x The number to decrement
35 * @return The decremented value
37 int inline DEC_UNTIL_ZERO(int x
);
39 /** @brief a macro to determine if two boolean values are the same (ie both
40 * true or both false */
41 #define BOOL_MATCH(x,y) ( (((x)!=0)&&((y)!=0))||(((x)==0)&&((y)==0)) ? 1 : 0)
44 * @brief a 'safe' free
46 * @param memory pointer to the memory to free
48 * @return SUCCESS, errorcode on failure
50 errorcode
safe_free(void *memory
);
53 * @brief waits for a flag to take one of many specified values
55 * Success if the check_flag takes on any one of the stop_flags before timeout
57 * @param check_flag pointer to the flag to watch
58 * @param stop_flags all the flags to wait for or'ed together.
59 * @param timeout the timeout time, in seconds
61 * @return SUCCESS, errorcode on failure
63 errorcode
wait_for_flag(flag_t
*check_flag
, flag_t stop_flags
, int timeout
);
65 #endif /* __UTIL_H__ */