chore: sync project files

This commit is contained in:
richjohnrambo
2026-08-11 10:29:38 +08:00
parent c9d6a6767f
commit 5aa7733515
310 changed files with 3323 additions and 36 deletions
+30
View File
@@ -0,0 +1,30 @@
package concurrency
// SimpleMutex is a channel used for locking.
type SimpleMutex chan struct{}
// NewSimpleMutex creates and returns a new SimpleMutex object.
func NewSimpleMutex() SimpleMutex {
return make(SimpleMutex, 1)
}
// Lock acquires a lock on the mutex.
func (s SimpleMutex) Lock() {
s <- struct{}{}
}
// TryLock attempts to acquire a lock on the mutex.
// Returns true if the lock has been acquired, false otherwise.
func (s SimpleMutex) TryLock() bool {
select {
case s <- struct{}{}:
return true
default:
return false
}
}
// Unlock releases the mutex.
func (s SimpleMutex) Unlock() {
<-s
}