2009-03-10 12:41:20 +01:00
|
|
|
/****************************************************************************
|
2014-08-08 21:53:29 +02:00
|
|
|
* sched/semaphore/semaphore.h
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2020-05-10 15:13:21 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2020-05-10 15:13:21 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2020-05-10 15:13:21 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2009-03-10 12:41:20 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2014-08-08 21:53:29 +02:00
|
|
|
#ifndef __SCHED_SEMAPHORE_SEMAPHORE_H
|
|
|
|
#define __SCHED_SEMAPHORE_SEMAPHORE_H
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2009-03-10 12:41:20 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2009-03-10 12:41:20 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2009-12-14 19:39:29 +01:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
#include <nuttx/compiler.h>
|
2020-02-01 08:17:32 +01:00
|
|
|
#include <nuttx/semaphore.h>
|
2021-05-14 04:03:23 +02:00
|
|
|
#include <nuttx/sched.h>
|
2009-12-14 19:39:29 +01:00
|
|
|
|
2009-12-14 20:30:18 +01:00
|
|
|
#include <stdint.h>
|
2009-12-14 22:15:18 +01:00
|
|
|
#include <stdbool.h>
|
2007-02-18 00:21:28 +01:00
|
|
|
#include <queue.h>
|
|
|
|
|
2009-03-10 12:41:20 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Public Function Prototypes
|
2009-03-10 12:41:20 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
#define EXTERN extern "C"
|
2013-02-04 19:46:28 +01:00
|
|
|
extern "C"
|
|
|
|
{
|
2007-02-18 00:21:28 +01:00
|
|
|
#else
|
|
|
|
#define EXTERN extern
|
|
|
|
#endif
|
|
|
|
|
2012-03-23 21:14:21 +01:00
|
|
|
/* Common semaphore logic */
|
|
|
|
|
2014-09-29 14:50:48 +02:00
|
|
|
#ifdef CONFIG_PRIORITY_INHERITANCE
|
2017-10-03 20:51:15 +02:00
|
|
|
void nxsem_initialize(void);
|
2014-09-29 14:50:48 +02:00
|
|
|
#else
|
2017-10-03 20:51:15 +02:00
|
|
|
# define nxsem_initialize()
|
2014-09-29 14:50:48 +02:00
|
|
|
#endif
|
|
|
|
|
2015-08-01 15:30:23 +02:00
|
|
|
/* Wake up a thread that is waiting on semaphore */
|
|
|
|
|
2017-10-09 17:06:46 +02:00
|
|
|
void nxsem_wait_irq(FAR struct tcb_s *wtcb, int errcode);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2015-08-01 15:30:23 +02:00
|
|
|
/* Handle semaphore timer expiration */
|
|
|
|
|
2020-08-09 20:29:35 +02:00
|
|
|
void nxsem_timeout(wdparm_t pid);
|
2015-08-01 15:30:23 +02:00
|
|
|
|
2014-12-13 19:02:25 +01:00
|
|
|
/* Recover semaphore resources with a task or thread is destroyed */
|
|
|
|
|
2017-10-03 20:51:15 +02:00
|
|
|
void nxsem_recover(FAR struct tcb_s *tcb);
|
2014-12-13 19:02:25 +01:00
|
|
|
|
2012-03-23 21:14:21 +01:00
|
|
|
/* Special logic needed only by priority inheritance to manage collections of
|
|
|
|
* holders of semaphores.
|
|
|
|
*/
|
|
|
|
|
2009-03-10 12:41:20 +01:00
|
|
|
#ifdef CONFIG_PRIORITY_INHERITANCE
|
2020-05-10 15:13:21 +02:00
|
|
|
void nxsem_initialize_holders(void);
|
2017-10-03 20:51:15 +02:00
|
|
|
void nxsem_destroyholder(FAR sem_t *sem);
|
2020-05-10 15:13:21 +02:00
|
|
|
void nxsem_add_holder(FAR sem_t *sem);
|
|
|
|
void nxsem_add_holder_tcb(FAR struct tcb_s *htcb, FAR sem_t *sem);
|
|
|
|
void nxsem_boost_priority(FAR sem_t *sem);
|
|
|
|
void nxsem_release_holder(FAR sem_t *sem);
|
|
|
|
void nxsem_restore_baseprio(FAR struct tcb_s *stcb, FAR sem_t *sem);
|
2017-10-03 20:51:15 +02:00
|
|
|
void nxsem_canceled(FAR struct tcb_s *stcb, FAR sem_t *sem);
|
2009-03-10 12:41:20 +01:00
|
|
|
#else
|
2020-05-10 15:13:21 +02:00
|
|
|
# define nxsem_initialize_holders()
|
2017-10-03 20:51:15 +02:00
|
|
|
# define nxsem_destroyholder(sem)
|
2020-05-10 15:13:21 +02:00
|
|
|
# define nxsem_add_holder(sem)
|
|
|
|
# define nxsem_add_holder_tcb(htcb,sem)
|
|
|
|
# define nxsem_boost_priority(sem)
|
|
|
|
# define nxsem_release_holder(sem)
|
|
|
|
# define nxsem_restore_baseprio(stcb,sem)
|
2017-10-03 20:51:15 +02:00
|
|
|
# define nxsem_canceled(stcb,sem)
|
2009-03-10 12:41:20 +01:00
|
|
|
#endif
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
#undef EXTERN
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-08-08 21:53:29 +02:00
|
|
|
#endif /* __SCHED_SEMAPHORE_SEMAPHORE_H */
|