1
0
mirror of https://github.com/azure-rtos/threadx synced 2025-01-30 08:02:57 +08:00

115 lines
5.6 KiB
C
Raw Normal View History

2020-09-30 15:42:41 -07:00
/**************************************************************************/
/* */
/* Copyright (c) Microsoft Corporation. All rights reserved. */
/* */
/* This software is licensed under the Microsoft Software License */
/* Terms for Microsoft Azure RTOS. Full text of the license can be */
/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
/* and in the root directory of this software. */
/* */
/**************************************************************************/
/**************************************************************************/
/**************************************************************************/
2021-06-02 06:45:05 +00:00
/** */
/** POSIX wrapper for THREADX */
2020-09-30 15:42:41 -07:00
/** */
/** */
/** */
/**************************************************************************/
/**************************************************************************/
/* Include necessary system files. */
2021-06-02 06:45:05 +00:00
#include "tx_api.h" /* Threadx API */
#include "pthread.h" /* Posix API */
#include "px_int.h" /* Posix helper functions */
2020-09-30 15:42:41 -07:00
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
2021-06-02 06:45:05 +00:00
/* sem_unlink PORTABLE C */
2022-10-26 23:41:13 +00:00
/* 6.2.0 */
2020-09-30 15:42:41 -07:00
/* AUTHOR */
/* */
/* William E. Lamie, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
2021-06-02 06:45:05 +00:00
/* This routine removes the string from the semaphore name table ,and */
/* marks the corresponding semaphore for destruction. */
2020-09-30 15:42:41 -07:00
/* */
/* INPUT */
/* */
2021-06-02 06:45:05 +00:00
/* name Semaphore name. */
2020-09-30 15:42:41 -07:00
/* */
/* OUTPUT */
/* */
2021-06-02 06:45:05 +00:00
/* OK If successful */
/* ERROR IF fails */
2020-09-30 15:42:41 -07:00
/* */
/* CALLS */
/* */
2021-06-02 06:45:05 +00:00
/* posix_find_sem checks the name of semaphore with the names */
/* of the already created semaphore. */
/* posix_sem_reset Resets the semaphore structure */
2020-09-30 15:42:41 -07:00
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */
2022-10-26 23:41:13 +00:00
/* 06-02-2021 William E. Lamie Initial Version 6.1.7 */
/* 10-31-2022 Scott Larson Remove double parenthesis, */
/* resulting in version 6.2.0 */
2020-09-30 15:42:41 -07:00
/* */
/**************************************************************************/
2021-06-02 06:45:05 +00:00
INT sem_unlink(const CHAR * name)
{
struct POSIX_SEMAPHORE_STRUCT * sem;
ULONG len;
/* Checking for the invalid length. */
len = strlen(name);
2020-09-30 15:42:41 -07:00
2021-06-02 06:45:05 +00:00
if(len > SEM_NAME_MAX)
{
/* Return appropriate error. */
posix_errno=ENAMETOOLONG;
posix_set_pthread_errno(ENAMETOOLONG);
/* Return error. */
return(ERROR);
}
2020-09-30 15:42:41 -07:00
2021-06-02 06:45:05 +00:00
if(!(sem=posix_find_sem(name)))
{
/* Set error in global variable. */
posix_errno = ENOENT;
posix_set_pthread_errno(ENOENT);
2020-09-30 15:42:41 -07:00
2021-06-02 06:45:05 +00:00
/* Return Error. */
return(ERROR);
}
if(sem)
2020-09-30 15:42:41 -07:00
2021-06-02 06:45:05 +00:00
sem->unlink_flag =TX_TRUE;
2020-09-30 15:42:41 -07:00
2021-06-02 06:45:05 +00:00
/* Check for the count. */
2022-10-26 23:41:13 +00:00
if(sem->count == 0)
2021-06-02 06:45:05 +00:00
{
posix_sem_reset(sem );
sem = NULL;
}
2020-09-30 15:42:41 -07:00
2021-06-02 06:45:05 +00:00
return(OK);
}