diff options
| author | Xe Iaso <me@xeiaso.net> | 2023-08-20 09:58:46 -0400 |
|---|---|---|
| committer | Xe Iaso <me@xeiaso.net> | 2023-08-20 09:58:46 -0400 |
| commit | 0f035f34b46be55152ef430f9be66e1ce13eb680 (patch) | |
| tree | 2bb852c81504e640fa9506e5c1300c9988dbe36d /cursed | |
| parent | 6812fc366ed53ed256daea93c48e095587e6c290 (diff) | |
| download | x-0f035f34b46be55152ef430f9be66e1ce13eb680.tar.xz x-0f035f34b46be55152ef430f9be66e1ce13eb680.zip | |
cursed: add Mutex type
Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'cursed')
| -rw-r--r-- | cursed/doc.go | 8 | ||||
| -rw-r--r-- | cursed/mutex.go | 22 |
2 files changed, 30 insertions, 0 deletions
diff --git a/cursed/doc.go b/cursed/doc.go index b613846..4395a3f 100644 --- a/cursed/doc.go +++ b/cursed/doc.go @@ -1,12 +1,20 @@ // Package cursed contains code that should never be used by anyone. // // This place is a message... and part of a system of messages... pay attention to it! +// // Sending this message was important to us. We considered ourselves to be a powerful culture. +// // This place is not a place of honor... no highly esteemed deed is commemorated here... nothing valued is here. +// // What is here was dangerous and repulsive to us. This message is a warning about danger. +// // The danger is in a particular location... it increases towards a center... the center of danger is here... of a particular size and shape, and below us. +// // The danger is still present, in your time, as it was in ours. +// // The danger is to the body, and it can kill. +// // The form of the danger is an emanation of energy. +// // The danger is unleashed only if you substantially disturb this place physically. This place is best shunned and left uninhabited. package cursed diff --git a/cursed/mutex.go b/cursed/mutex.go new file mode 100644 index 0000000..82fe58f --- /dev/null +++ b/cursed/mutex.go @@ -0,0 +1,22 @@ +package cursed + +import "sync" + +// Mutex is a generic locking container for Go much like Rust's std::sync::Mutex<T>. +// +// It differs from a normal sync.Mutex because it guards a value instead of just +// being something you lock and unlock to guard another value. When you are done with +// the value, call the function return to re-lock the mutex. +type Mutex[T any] struct { + val T + lock sync.Mutex +} + +func NewMutex[T any](val T) *Mutex[T] { + return &Mutex[T]{val: val} +} + +func (mu *Mutex[T]) Unlock() (T, func()) { + mu.lock.Lock() + return mu.val, func() { mu.lock.Unlock() } +} |
