2009-03-10 19:41:20 +08:00
|
|
|
/****************************************************************************
|
2014-08-09 03:53:29 +08:00
|
|
|
* sched/semaphore/semaphore.h
|
2007-02-18 07:21:28 +08:00
|
|
|
*
|
2020-05-10 21:13:21 +08: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 07:21:28 +08:00
|
|
|
*
|
2020-05-10 21:13:21 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-02-18 07:21:28 +08:00
|
|
|
*
|
2020-05-10 21:13:21 +08: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 07:21:28 +08:00
|
|
|
*
|
2009-03-10 19:41:20 +08:00
|
|
|
****************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2014-08-09 03:53:29 +08:00
|
|
|
#ifndef __SCHED_SEMAPHORE_SEMAPHORE_H
|
|
|
|
#define __SCHED_SEMAPHORE_SEMAPHORE_H
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2009-03-10 19:41:20 +08:00
|
|
|
/****************************************************************************
|
2007-02-18 07:21:28 +08:00
|
|
|
* Included Files
|
2009-03-10 19:41:20 +08:00
|
|
|
****************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2009-12-15 02:39:29 +08:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
#include <nuttx/compiler.h>
|
2020-02-01 15:17:32 +08:00
|
|
|
#include <nuttx/semaphore.h>
|
2021-05-14 10:03:23 +08:00
|
|
|
#include <nuttx/sched.h>
|
2009-12-15 02:39:29 +08:00
|
|
|
|
2009-12-15 03:30:18 +08:00
|
|
|
#include <stdint.h>
|
2009-12-15 05:15:18 +08:00
|
|
|
#include <stdbool.h>
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2009-03-10 19:41:20 +08:00
|
|
|
/****************************************************************************
|
2007-02-18 07:21:28 +08:00
|
|
|
* Public Function Prototypes
|
2009-03-10 19:41:20 +08:00
|
|
|
****************************************************************************/
|
2007-02-18 07:21:28 +08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
#define EXTERN extern "C"
|
2013-02-05 02:46:28 +08:00
|
|
|
extern "C"
|
|
|
|
{
|
2007-02-18 07:21:28 +08:00
|
|
|
#else
|
|
|
|
#define EXTERN extern
|
|
|
|
#endif
|
|
|
|
|
2012-03-24 04:14:21 +08:00
|
|
|
/* Common semaphore logic */
|
|
|
|
|
2014-09-29 20:50:48 +08:00
|
|
|
#ifdef CONFIG_PRIORITY_INHERITANCE
|
2017-10-04 02:51:15 +08:00
|
|
|
void nxsem_initialize(void);
|
2014-09-29 20:50:48 +08:00
|
|
|
#else
|
2017-10-04 02:51:15 +08:00
|
|
|
# define nxsem_initialize()
|
2014-09-29 20:50:48 +08:00
|
|
|
#endif
|
|
|
|
|
2015-08-01 21:30:23 +08:00
|
|
|
/* Wake up a thread that is waiting on semaphore */
|
|
|
|
|
2017-10-09 23:06:46 +08:00
|
|
|
void nxsem_wait_irq(FAR struct tcb_s *wtcb, int errcode);
|
2007-02-18 07:21:28 +08:00
|
|
|
|
2015-08-01 21:30:23 +08:00
|
|
|
/* Handle semaphore timer expiration */
|
|
|
|
|
2020-08-10 02:29:35 +08:00
|
|
|
void nxsem_timeout(wdparm_t pid);
|
2015-08-01 21:30:23 +08:00
|
|
|
|
2014-12-14 02:02:25 +08:00
|
|
|
/* Recover semaphore resources with a task or thread is destroyed */
|
|
|
|
|
2017-10-04 02:51:15 +08:00
|
|
|
void nxsem_recover(FAR struct tcb_s *tcb);
|
2014-12-14 02:02:25 +08:00
|
|
|
|
2012-03-24 04:14:21 +08:00
|
|
|
/* Special logic needed only by priority inheritance to manage collections of
|
|
|
|
* holders of semaphores.
|
|
|
|
*/
|
|
|
|
|
2009-03-10 19:41:20 +08:00
|
|
|
#ifdef CONFIG_PRIORITY_INHERITANCE
|
2020-05-10 21:13:21 +08:00
|
|
|
void nxsem_initialize_holders(void);
|
2017-10-04 02:51:15 +08:00
|
|
|
void nxsem_destroyholder(FAR sem_t *sem);
|
2020-05-10 21:13:21 +08: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-04 02:51:15 +08:00
|
|
|
void nxsem_canceled(FAR struct tcb_s *stcb, FAR sem_t *sem);
|
2022-02-08 16:11:16 +08:00
|
|
|
void nxsem_release_all(FAR struct tcb_s *stcb);
|
2009-03-10 19:41:20 +08:00
|
|
|
#else
|
2020-05-10 21:13:21 +08:00
|
|
|
# define nxsem_initialize_holders()
|
2017-10-04 02:51:15 +08:00
|
|
|
# define nxsem_destroyholder(sem)
|
2020-05-10 21:13:21 +08: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-04 02:51:15 +08:00
|
|
|
# define nxsem_canceled(stcb,sem)
|
2022-02-08 16:11:16 +08:00
|
|
|
# define nxsem_release_all(stcb)
|
2009-03-10 19:41:20 +08:00
|
|
|
#endif
|
|
|
|
|
2007-02-18 07:21:28 +08:00
|
|
|
#undef EXTERN
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-08-09 03:53:29 +08:00
|
|
|
#endif /* __SCHED_SEMAPHORE_SEMAPHORE_H */
|