1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/sys/posix/include/semaphore.h

123 lines
2.4 KiB
C
Raw Normal View History

/*
* Copyright (C) 2013 Freie Universität Berlin
*
* 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.
*/
2013-09-20 15:30:42 +02:00
#ifndef _SEMAPHORE_H
#define _SEMAPHORE_H 1
2013-09-20 15:30:42 +02:00
#include <time.h>
2014-10-10 11:51:11 +02:00
#include "priority_queue.h"
#ifdef __cplusplus
extern "C" {
#endif
2013-09-20 15:30:42 +02:00
/** Value returned if `sem_open' failed. */
#define SEM_FAILED ((sem_t *) 0)
2014-12-06 02:05:51 +01:00
/**
* @brief Semaphore struct
*/
2013-09-20 15:30:42 +02:00
typedef struct sem {
2014-12-06 02:05:51 +01:00
/** the value of the semaphore */
2013-09-20 15:30:42 +02:00
volatile unsigned int value;
2014-12-06 02:05:51 +01:00
/** list of threads waiting for the semaphore */
priority_queue_t queue;
2013-09-20 15:30:42 +02:00
} sem_t;
/**
* @brief Initialize semaphore object SEM to VALUE.
*
* @param sem Semaphore to initialize
* @param pshared unused
* @param value Value to set
*/
int sem_init(sem_t *sem, int pshared, unsigned int value);
/**
* @brief Free resources associated with semaphore object SEM.
*
* @param sem Semaphore to destroy
*/
int sem_destroy(sem_t *sem);
/*
* @brief Open a named semaphore NAME with open flags OFLAG.
*
* @brief WARNING: named semaphore are currently not supported
*
* @param name Name to set
* @param oflag Flags to set
*/
sem_t *sem_open(const char *name, int oflag, ...);
/**
* @brief Close descriptor for named semaphore SEM.
*
* @brief WARNING: named semaphore are currently not supported
*
* @param sem Semaphore to close
*/
int sem_close(sem_t *sem);
/**
* @brief Remove named semaphore NAME.
*
* @brief WARNING: named semaphore are currently not supported
*
* @param name Name to unlink
*/
int sem_unlink(const char *name);
/**
* @brief Wait for SEM being posted.
*
* @param sem Semaphore to wait
*/
int sem_wait(sem_t *sem);
/**
* @brief Similar to `sem_wait' but wait only until ABSTIME.
*
* @brief WARNING: currently not supported
*
* @param sem Semaphore to wait on
* @param abstime Max time to wait for a post
*
*/
int sem_timedwait(sem_t *sem, const struct timespec *abstime);
/**
* @brief Test whether SEM is posted.
*
* @param sem Semaphore to trywait on
*
*/
int sem_trywait(sem_t *sem);
/**
* @brief Post SEM.
*
* @param sem Semaphore to post on
*/
int sem_post(sem_t *sem);
/**
* @brief Get current value of SEM and store it in *SVAL.
*
* @param sem Semaphore to get value from
* @param sval place whre value goes to
*/
int sem_getvalue(sem_t *sem, int *sval);
2014-10-10 11:51:11 +02:00
#ifdef __cplusplus
}
#endif
#endif /* semaphore.h */