Welcome, weary internet traveller. You’ve stumbled onto a great slice of the internet.

Keyframes is a creative community. Share your #wip, get #feedback, find inspiration, and chat with people who make things. It is a bunker from the rest of the garbage internet. No popularity contests here. No circle jerks. No regular jerks. Just a wholesome place to shoot the shit and be real about what you’re making.

You can post in public, or private (with a Plus account). Use it to improve your work, or just feel good about creating things again.

Come on in! We hope you enjoy your stay.

Register here for a very fun time ✨️

Or log in if you’re returning. (Welcome back!)

All posts tagged “swift”

Hello Keyframes,

I've started learning Swift for macOS dev recently. And this is one of my recent projects. Simple pattern generator that uses regular Unicode symbols (including Emoji).

It is still pretty much a work in progress. Currently trying to figure out how to make a decent symbol picker.

swift mutexes
final class NoStarveMutex { private final let _semaphoreA = DispatchSemaphore(value: 1) private final let _semaphoreB = DispatchSemaphore(value: 0) private final var _countA = Int64(0) private final var _countB = Int64(0) final func lockAndWait() { lock() waitForLock() } final func lock() { OSAtomicIncrement64(&_countA) _semaphoreA.wait(timeout: DispatchTime.distantFuture) _countB += 1 if OSAtomicDecrement64(&_countA) == 0 { _semaphoreB.signal() } else { _semaphoreA.signal() } } final func waitForLock() { _semaphoreB.wait(timeout: DispatchTime.distantFuture) _countB -= 1 } final func unlock() { if _countB == 0 { _semaphoreA.signal() } else { _semaphoreB.signal() } } } final class ReadWriteMutex { private final let _readMutex = NoStarveMutex() private final let _writeMutex = NoStarveMutex() private final var _count = Int64(0) final func lock() { _readMutex.lock() } final func lockForReadingAndWait() { lock() waitForReadLock() } final func waitForReadLock() { _readMutex.waitForLock() if OSAtomicIncrement64(&_count) == 1 { _writeMutex.lockAndWait() } _readMutex.unlock() } final func unlockForReading() { if OSAtomicDecrement64(&_count) == 1 { _writeMutex.unlock() } } final func lockForWritingAndWait() { lock() waitForWriteLock() } final func waitForWriteLock() { _readMutex.waitForLock() _writeMutex.lockAndWait() } final func unlockForWriting() { _writeMutex.unlock() _readMutex.unlock() } }

popping and locking