2012-03-30 00:20:47 +02:00
|
|
|
/****************************************************************************
|
2014-09-20 23:53:28 +02:00
|
|
|
* nuttx/graphics/nxterm/nxterm_sem.c
|
2012-03-30 00:20:47 +02:00
|
|
|
*
|
2021-02-05 11:12:53 +01: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
|
2012-03-30 00:20:47 +02:00
|
|
|
*
|
2021-02-05 11:12:53 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-03-30 00:20:47 +02:00
|
|
|
*
|
2021-02-05 11:12:53 +01: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.
|
2012-03-30 00:20:47 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2014-09-20 23:53:28 +02:00
|
|
|
#include "nxterm.h"
|
2012-03-30 00:20:47 +02:00
|
|
|
|
2019-03-17 18:34:45 +01:00
|
|
|
#ifdef CONFIG_DEBUG_GRAPHICS
|
2012-03-30 00:20:47 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2014-09-20 23:53:28 +02:00
|
|
|
* Name: nxterm_semwait and nxterm_sempost
|
2012-03-30 00:20:47 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* If debug is on, then lower level code may attempt console output while
|
|
|
|
* we are doing console output! In this case, we will toss the nested
|
|
|
|
* output to avoid deadlocks and infinite loops.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv - Driver data structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2014-04-14 00:22:22 +02:00
|
|
|
*
|
2012-03-30 00:20:47 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-09-20 23:53:28 +02:00
|
|
|
int nxterm_semwait(FAR struct nxterm_state_s *priv)
|
2012-03-30 00:20:47 +02:00
|
|
|
{
|
|
|
|
pid_t me;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Does I already hold the semaphore */
|
|
|
|
|
|
|
|
me = getpid();
|
|
|
|
if (priv->holder != me)
|
|
|
|
{
|
2021-02-05 09:05:48 +01:00
|
|
|
/* No..
|
|
|
|
* then wait until the thread that does hold it is finished with it
|
|
|
|
*/
|
2012-03-30 00:20:47 +02:00
|
|
|
|
2017-10-04 23:22:27 +02:00
|
|
|
ret = nxsem_wait(&priv->exclsem);
|
2012-03-30 00:20:47 +02:00
|
|
|
if (ret == OK)
|
|
|
|
{
|
|
|
|
/* No I hold the semaphore */
|
|
|
|
|
|
|
|
priv->holder = me;
|
|
|
|
}
|
2017-10-04 23:22:27 +02:00
|
|
|
|
2012-03-30 00:20:47 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Abort, abort, abort! I have been re-entered */
|
|
|
|
|
2017-10-04 23:22:27 +02:00
|
|
|
return -EBUSY;
|
2012-03-30 00:20:47 +02:00
|
|
|
}
|
|
|
|
|
2014-09-20 23:53:28 +02:00
|
|
|
int nxterm_sempost(FAR struct nxterm_state_s *priv)
|
2012-03-30 00:20:47 +02:00
|
|
|
{
|
|
|
|
/* Make sure that I really hold the semaphore */
|
|
|
|
|
2019-05-04 20:34:47 +02:00
|
|
|
DEBUGASSERT(priv->holder == getpid());
|
2012-03-30 00:20:47 +02:00
|
|
|
|
|
|
|
/* Then let go of it */
|
|
|
|
|
|
|
|
priv->holder = NO_HOLDER;
|
2017-10-03 23:35:24 +02:00
|
|
|
return nxsem_post(&priv->exclsem);
|
2012-03-30 00:20:47 +02:00
|
|
|
}
|
|
|
|
|
2019-03-17 18:34:45 +01:00
|
|
|
#endif /* CONFIG_DEBUG_GRAPHICS */
|