You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
2.3 KiB

//
// Feb21
//
// GO Active Thing
// Framework
//
// http://activething.com/dev/goat
//
// Dev : Juan V.Navarro
// Email: juanvnl@activething.com
// Date : 16/02/2021
//
// Copyright 2021 the GOAT Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package syncs
import (
"sync/atomic"
)
type (
// ABool
// Type: Struct
// Desc: Atomic Bool, estructura para realizar operaciones atomicas
// sobre un valor de tipo Bool
//
ABool struct {
// value: valor sobre el que se realizaran las operaciones
// atomicas.
//
value uint32
}
)
// NewABool
// Desc: Función constructor para ABool
//
// Prms: val, valor inicial
// Rets: Puntero al nuevo objeto creado.
//
func NewABool(val bool) *ABool { return &ABool{value: boolAsUint32(val)} }
// ABool.Get
// Desc:
// Rets:
//
func (b *ABool) Get() bool { return atomic.LoadUint32(&b.value) == 1 }
// ABool.Set
// Desc:
// Prms:
//
func (b *ABool) Set(val bool) { atomic.StoreUint32(&b.value, boolAsUint32(val)) }
// ABool.Swap
// Desc:
// Prms:
//
func (b *ABool) Swap(new bool) bool { return atomic.SwapUint32(&b.value, boolAsUint32(new)) == 1 }
// ABool.CAS
// Desc:
// Prms:
// Rets:
//
func (b *ABool) CAS(old, new bool) bool {
return atomic.CompareAndSwapUint32(&b.value, boolAsUint32(old), boolAsUint32(new))
}
// boolAsUint32
// Desc: Convierte un valor de tipo bool a uint32
// Prms: val, valor a convertir
// Rets: uint32, El valor segun sea true = 1 o
// false = *
//
func boolAsUint32(val bool) uint32 {
if val {
return 1
}
return 0
}
/*
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA.
"LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS.
SIDDHARTA
- HERMANN HESSE -
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/

Powered by TurnKey Linux.