mirror of
https://github.com/yudai/gotty.git
synced 2026-03-08 06:32:35 +01:00
Simplify title format output procedure
This commit is contained in:
parent
46e33887c4
commit
f72b18052a
9 changed files with 147 additions and 232 deletions
38
Godeps/_workspace/src/github.com/yudai/umutex/umutex.go
generated
vendored
Normal file
38
Godeps/_workspace/src/github.com/yudai/umutex/umutex.go
generated
vendored
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
// Package umutex provides unblocking mutex
|
||||
package umutex
|
||||
|
||||
// UnblockingMutex represents an unblocking mutex.
|
||||
type UnblockingMutex struct {
|
||||
// Raw channel
|
||||
C chan bool
|
||||
}
|
||||
|
||||
// New returnes a new unblocking mutex instance.
|
||||
func New() *UnblockingMutex {
|
||||
return &UnblockingMutex{
|
||||
C: make(chan bool, 1),
|
||||
}
|
||||
}
|
||||
|
||||
// TryLock tries to lock the mutex.
|
||||
// When the mutex is free at the time, the function locks the mutex and return
|
||||
// true. Otherwise false will be returned. In the both cases, this function
|
||||
// doens't block and return the result immediately.
|
||||
func (m UnblockingMutex) TryLock() (result bool) {
|
||||
select {
|
||||
case m.C <- true:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Unlock unclocks the mutex.
|
||||
func (m UnblockingMutex) Unlock() {
|
||||
<-m.C
|
||||
}
|
||||
|
||||
// ForceLock surely locks the mutex, however, this function blocks when the mutex is locked at the time.
|
||||
func (m UnblockingMutex) ForceLock() {
|
||||
m.C <- false
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue