Merge pull request #8776 from Robyt3/Base-Semaphore-macOS-Unique-Name

Make macOS semaphore names more unique, improve assertion
This commit is contained in:
Dennis Felsing 2024-08-20 18:50:17 +00:00 committed by GitHub
commit 54271aef2a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -867,10 +867,15 @@ void sphore_destroy(SEMAPHORE *sem)
#elif defined(CONF_PLATFORM_MACOS)
void sphore_init(SEMAPHORE *sem)
{
char aBuf[32];
str_format(aBuf, sizeof(aBuf), "%p", (void *)sem);
char aBuf[64];
str_format(aBuf, sizeof(aBuf), "/%d.%p", pid(), (void *)sem);
*sem = sem_open(aBuf, O_CREAT | O_EXCL, S_IRWXU | S_IRWXG, 0);
dbg_assert(*sem != SEM_FAILED, "sem_open failure");
if(*sem == SEM_FAILED)
{
char aError[128];
str_format(aError, sizeof(aError), "sem_open failure, errno=%d, name='%s'", errno, aBuf);
dbg_assert(false, aError);
}
}
void sphore_wait(SEMAPHORE *sem)
{
@ -888,8 +893,8 @@ void sphore_signal(SEMAPHORE *sem)
void sphore_destroy(SEMAPHORE *sem)
{
dbg_assert(sem_close(*sem) == 0, "sem_close failure");
char aBuf[32];
str_format(aBuf, sizeof(aBuf), "%p", (void *)sem);
char aBuf[64];
str_format(aBuf, sizeof(aBuf), "/%d.%p", pid(), (void *)sem);
dbg_assert(sem_unlink(aBuf) == 0, "sem_unlink failure");
}
#elif defined(CONF_FAMILY_UNIX)