2014-02-18 12:17:06 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Hamburg University of Applied Sciences (HAW)
|
|
|
|
*
|
2014-08-23 15:43:13 +02:00
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
2014-02-18 12:17:06 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2014-05-18 17:03:06 +02:00
|
|
|
* @ingroup pthread
|
2014-02-18 12:17:06 +01:00
|
|
|
* @{
|
2014-05-18 17:03:06 +02:00
|
|
|
* @file
|
2014-02-18 12:17:06 +01:00
|
|
|
* @brief RIOT POSIX condition variable API
|
|
|
|
* @author Martin Landsmann <martin.landsmann@haw-hamburg.de>
|
|
|
|
*/
|
|
|
|
|
2017-05-23 18:19:52 +02:00
|
|
|
#ifndef PTHREAD_COND_H
|
|
|
|
#define PTHREAD_COND_H
|
2014-02-18 12:17:06 +01:00
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
#include "mutex.h"
|
2016-02-29 00:00:28 +01:00
|
|
|
#include "priority_queue.h"
|
2014-02-18 12:17:06 +01:00
|
|
|
|
2014-12-01 17:32:29 +01:00
|
|
|
#if defined(CPU_CC430) || defined(CPU_MSP430FXYZ)
|
2014-02-18 12:17:06 +01:00
|
|
|
# include "msp430_types.h"
|
|
|
|
#endif
|
|
|
|
|
2017-06-03 21:32:22 +02:00
|
|
|
#ifdef __MACH__
|
|
|
|
/* needed for AVAILABLE_MAC_OS_X_VERSION_10_12_AND_LATER */
|
|
|
|
#include <AvailabilityMacros.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__WITH_AVRLIBC__) || (defined(__MACH__) && !defined(AVAILABLE_MAC_OS_X_VERSION_10_12_AND_LATER))
|
2015-04-14 11:00:51 +02:00
|
|
|
typedef int clockid_t;
|
|
|
|
#endif
|
|
|
|
|
2014-10-10 11:51:11 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2014-02-18 12:17:06 +01:00
|
|
|
/**
|
|
|
|
* @note condition attributes are currently NOT USED in RIOT condition variables
|
|
|
|
*/
|
2016-04-07 21:31:00 +02:00
|
|
|
typedef struct {
|
2014-12-06 02:05:51 +01:00
|
|
|
/** dumdidum */
|
2014-02-18 12:17:06 +01:00
|
|
|
int __dummy;
|
|
|
|
} pthread_condattr_t;
|
|
|
|
|
2014-12-06 02:05:51 +01:00
|
|
|
/**
|
|
|
|
* @brief Condition variable
|
|
|
|
*
|
|
|
|
* @warning fields are managed by cv functions, don't touch
|
|
|
|
*/
|
2016-04-07 21:31:00 +02:00
|
|
|
typedef struct {
|
2014-07-29 09:21:11 +02:00
|
|
|
priority_queue_t queue; /**< Threads currently waiting to be signaled. */
|
2014-02-18 12:17:06 +01:00
|
|
|
} pthread_cond_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initializes a condition attribute variable object using default values
|
|
|
|
* @param[in, out] attr pre-allocated condition attribute variable structure.
|
|
|
|
* @return returns 0 on success, an errorcode otherwise.
|
|
|
|
*/
|
2016-04-07 21:31:00 +02:00
|
|
|
int pthread_cond_condattr_init(pthread_condattr_t *attr);
|
2014-02-18 12:17:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Uninitializes a condition attribute variable object
|
|
|
|
* @param[in, out] attr pre-allocated condition attribute variable structure.
|
|
|
|
* @return returns 0 on success, an errorcode otherwise.
|
|
|
|
*/
|
2016-04-07 21:31:00 +02:00
|
|
|
int pthread_cond_condattr_destroy(pthread_condattr_t *attr);
|
2014-02-18 12:17:06 +01:00
|
|
|
|
|
|
|
/**
|
2017-09-05 11:04:25 +02:00
|
|
|
* @brief Get the process-shared attribute in an initialized attributes object referenced by attr
|
2014-02-18 12:17:06 +01:00
|
|
|
* @note NOT USED since RIOT is a single process OS
|
|
|
|
* @param[in] attr pre-allocated condition attribute variable structure.
|
|
|
|
* @param[out] pshared the pre-allocated process-shared variable.
|
|
|
|
* @return returns 0 on success, an errorcode otherwise.
|
|
|
|
*/
|
2014-02-13 14:18:30 +01:00
|
|
|
int pthread_condattr_getpshared(const pthread_condattr_t *attr, int *pshared);
|
|
|
|
|
2014-02-18 12:17:06 +01:00
|
|
|
/**
|
2017-09-05 11:04:25 +02:00
|
|
|
* @brief Set the process-shared attribute in an initialized attributes object referenced by attr
|
2014-02-18 12:17:06 +01:00
|
|
|
* @note NOT USED since RIOT is a single process OS
|
|
|
|
* @param[in, out] attr pre-allocated condition attribute variable structure.
|
|
|
|
* @param[in] pshared pshared the pre-allocated process-shared variable.
|
|
|
|
* @return returns 0 on success, an errorcode otherwise.
|
|
|
|
*/
|
2014-02-13 14:18:30 +01:00
|
|
|
int pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared);
|
|
|
|
|
2014-02-18 12:17:06 +01:00
|
|
|
/**
|
|
|
|
* @brief Get the clock selected for the conditon variable attribute attr.
|
|
|
|
* @note currently NOT USED in RIOT.
|
|
|
|
* @param[in] attr pre-allocated condition attribute variable structure.
|
|
|
|
* @param[out] clock_id the clock ID that is used to measure the timeout service
|
|
|
|
* @return returns 0 on success, an errorcode otherwise.
|
|
|
|
*/
|
|
|
|
int pthread_condattr_getclock(const pthread_condattr_t *attr, clockid_t *clock_id);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set the clock selected for the conditon variable attribute ATTR.
|
|
|
|
* @note currently NOT USED in RIOT.
|
|
|
|
* @param[in, out] attr pre-allocated condition attribute variable structure.
|
|
|
|
* @param[in] clock_id the clock ID that shall be used to measure the timeout service
|
|
|
|
* @return returns 0 on success, an errorcode otherwise.
|
|
|
|
*/
|
2014-02-13 14:18:30 +01:00
|
|
|
int pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clock_id);
|
2014-02-18 12:17:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initializes a condition variable object
|
|
|
|
* @param[in, out] cond pre-allocated condition variable structure.
|
|
|
|
* @param[in] attr pre-allocated condition attribute variable structure.
|
|
|
|
* @return returns 0 on success, an errorcode otherwise.
|
|
|
|
*/
|
2016-04-07 21:31:00 +02:00
|
|
|
int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *attr);
|
2014-02-18 12:17:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Destroy the condition variable cond
|
|
|
|
* @param[in, out] cond pre-allocated condition variable structure.
|
|
|
|
* @return returns 0 on success, an errorcode otherwise.
|
|
|
|
*/
|
2016-04-07 21:31:00 +02:00
|
|
|
int pthread_cond_destroy(pthread_cond_t *cond);
|
2014-02-18 12:17:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief blocks the calling thread until the specified condition cond is signalled
|
|
|
|
* @param[in, out] cond pre-allocated condition variable structure.
|
|
|
|
* @param[in, out] mutex pre-allocated mutex variable structure.
|
|
|
|
* @return returns 0 on success, an errorcode otherwise.
|
|
|
|
*/
|
2016-04-07 21:31:00 +02:00
|
|
|
int pthread_cond_wait(pthread_cond_t *cond, mutex_t *mutex);
|
2014-02-18 12:17:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief blocks the calling thread until the specified condition cond is signalled
|
|
|
|
* @param[in, out] cond pre-allocated condition variable structure.
|
|
|
|
* @param[in, out] mutex pre-allocated mutex variable structure.
|
|
|
|
* @param[in] abstime pre-allocated timeout.
|
|
|
|
* @return returns 0 on success, an errorcode otherwise.
|
|
|
|
*/
|
2016-04-07 21:31:00 +02:00
|
|
|
int pthread_cond_timedwait(pthread_cond_t *cond, mutex_t *mutex, const struct timespec *abstime);
|
2014-02-18 12:17:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief unblock at least one of the threads that are blocked on the specified condition variable cond
|
|
|
|
* @param[in, out] cond pre-allocated condition variable structure.
|
|
|
|
* @return returns 0 on success, an errorcode otherwise.
|
|
|
|
*/
|
2016-04-07 21:31:00 +02:00
|
|
|
int pthread_cond_signal(pthread_cond_t *cond);
|
2014-02-18 12:17:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief unblock all threads that are currently blocked on the specified condition variable cond
|
|
|
|
* @param[in, out] cond pre-allocated condition variable structure.
|
|
|
|
* @return returns 0 on success, an errorcode otherwise.
|
|
|
|
*/
|
2016-04-07 21:31:00 +02:00
|
|
|
int pthread_cond_broadcast(pthread_cond_t *cond);
|
2014-02-18 12:17:06 +01:00
|
|
|
|
2014-10-10 11:51:11 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-05-23 18:19:52 +02:00
|
|
|
#endif /* PTHREAD_COND_H */
|
2016-10-26 21:53:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|