This repository has been archived by the owner on Nov 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix semaphore implementation on non-Android Unix. (#67)
The current implementation uses sem_open(), which creates semaphores in a global system namespace; if the caller asks for a process-private semaphore, it appends a random number to the name to avoid collisions. Unlike on Windows, these semaphores are not destroyed when the last handle is closed; they stay around until someone explicitly calls sem_unlink(). Unfortunately, this means that if the hosting app crashes, it'll leak semaphores until the system reboots. On Android, the code uses sem_init() instead. This is another standard POSIX function, which has the capability to create true process-private semaphores, but is not implemented on some platforms, such as macOS where it just returns ENOSYS - presumably the reason the code path is limited to Android. As an entirely separate issue, on macOS, POSIX semaphore names are limited to only 31 characters. One of the semaphores created is named "/ConnectionThreadShutdown", which is 25 characters by itself; after adding an underscore and a random number, it'll only fit if the random number happens to be <= 99999! This commit abandons POSIX semaphores entirely in favor of emulating process-private semaphores using pthread condition variables. This avoids the leak issue and should also be faster. As for global semaphores, well - nothing in the FTL SDK actually uses them, so I decided to just remove the is_global argument from os_semaphore_create() and only support process-private semaphores.
- Loading branch information
1 parent
b89829c
commit 98289f7
Showing
7 changed files
with
70 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters