2014-10-10 22:52:04 +02:00
|
|
|
/****************************************************************************
|
2018-05-29 21:21:26 +02:00
|
|
|
* libs/libc/wqueue/work_lock.c
|
2014-10-10 22:52:04 +02:00
|
|
|
*
|
2021-03-02 15:54:21 +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
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* 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.
|
2014-10-10 22:52:04 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "wqueue/wqueue.h"
|
|
|
|
|
2014-10-11 23:59:40 +02:00
|
|
|
#if defined(CONFIG_LIB_USRWORK) && !defined(__KERNEL__)
|
2014-10-10 22:52:04 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: work_lock
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Lock the user-mode work queue.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2014-10-10 22:52:04 +02:00
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) on success, a negated errno on failure. This error may be
|
|
|
|
* reported:
|
|
|
|
*
|
|
|
|
* -EINTR - Wait was interrupted by a signal
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int work_lock(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
#ifdef CONFIG_BUILD_PROTECTED
|
2020-08-13 20:59:16 +02:00
|
|
|
ret = _SEM_WAIT(&g_usrsem);
|
2014-10-10 22:52:04 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2020-08-13 20:59:16 +02:00
|
|
|
DEBUGASSERT(_SEM_ERRNO(ret) == EINTR ||
|
|
|
|
_SEM_ERRNO(ret) == ECANCELED);
|
2014-10-10 22:52:04 +02:00
|
|
|
return -EINTR;
|
|
|
|
}
|
|
|
|
#else
|
2020-08-13 20:59:16 +02:00
|
|
|
ret = pthread_mutex_lock(&g_usrmutex);
|
|
|
|
if (ret != 0)
|
|
|
|
{
|
|
|
|
DEBUGASSERT(ret == EINTR);
|
|
|
|
return -EINTR;
|
|
|
|
}
|
2014-10-10 22:52:04 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: work_unlock
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Unlock the user-mode work queue.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2014-10-10 22:52:04 +02:00
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void work_unlock(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_BUILD_PROTECTED
|
2020-08-13 20:59:16 +02:00
|
|
|
_SEM_POST(&g_usrsem);
|
2014-10-10 22:52:04 +02:00
|
|
|
#else
|
2020-01-02 17:49:34 +01:00
|
|
|
pthread_mutex_unlock(&g_usrmutex);
|
2014-10-10 22:52:04 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-10-11 23:59:40 +02:00
|
|
|
#endif /* CONFIG_LIB_USRWORK && !__KERNEL__*/
|