Blame liblttng-ust/wait.h

Packit c04fcb
#ifndef _UST_WAIT_H
Packit c04fcb
#define _UST_WAIT_H
Packit c04fcb
Packit c04fcb
/*
Packit c04fcb
 * Copyright (C) 2011  Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Packit c04fcb
 *
Packit c04fcb
 * This library is free software; you can redistribute it and/or
Packit c04fcb
 * modify it under the terms of the GNU Lesser General Public
Packit c04fcb
 * License as published by the Free Software Foundation; version 2.1 of
Packit c04fcb
 * the License.
Packit c04fcb
 *
Packit c04fcb
 * This library is distributed in the hope that it will be useful,
Packit c04fcb
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit c04fcb
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit c04fcb
 * Lesser General Public License for more details.
Packit c04fcb
 *
Packit c04fcb
 * You should have received a copy of the GNU Lesser General Public
Packit c04fcb
 * License along with this library; if not, write to the Free Software
Packit c04fcb
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
Packit c04fcb
 */
Packit c04fcb
Packit c04fcb
#include <poll.h>
Packit c04fcb
Packit c04fcb
/*
Packit c04fcb
 * Wait until "cond" gets true or timeout (in ms).
Packit c04fcb
 */
Packit c04fcb
#define wait_cond_interruptible_timeout(_cond, _timeout)	\
Packit c04fcb
	({							\
Packit c04fcb
		int __ret = 0, __pollret;			\
Packit c04fcb
		int __timeout = _timeout;			\
Packit c04fcb
								\
Packit c04fcb
		for (;;) {					\
Packit c04fcb
			if (_cond)				\
Packit c04fcb
				break;				\
Packit c04fcb
			if (__timeout <= 0) {			\
Packit c04fcb
				__ret = -ETIMEDOUT;		\
Packit c04fcb
				break;				\
Packit c04fcb
			}					\
Packit c04fcb
			__pollret = poll(NULL, 0, 10);	/* wait 10ms */	\
Packit c04fcb
			if (__pollret < 0) {			\
Packit c04fcb
				__ret = -errno;			\
Packit c04fcb
				break;				\
Packit c04fcb
			}					\
Packit c04fcb
			__timeout -= 10;			\
Packit c04fcb
		}						\
Packit c04fcb
		__ret;						\
Packit c04fcb
	})
Packit c04fcb
Packit c04fcb
Packit c04fcb
#endif /* _UST_WAIT_H */