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.
125 lines
2.4 KiB
125 lines
2.4 KiB
|
2 years ago
|
//
|
||
|
|
// 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.
|
||
|
|
//
|
||
|
|
|
||
|
|
// +build amd64 arm64 ppc64 ppc64le mips64 mips64le s390x
|
||
|
|
|
||
|
|
package syns
|
||
|
|
|
||
|
|
import (
|
||
|
|
"sync/atomic"
|
||
|
|
)
|
||
|
|
|
||
|
|
type (
|
||
|
|
|
||
|
|
// AUInt
|
||
|
|
// Type: Struct
|
||
|
|
// Desc:
|
||
|
|
//
|
||
|
|
AUInt struct {
|
||
|
|
value uint64
|
||
|
|
}
|
||
|
|
)
|
||
|
|
|
||
|
|
// NewAInt
|
||
|
|
// Desc: Función constructor para AUInt
|
||
|
|
//
|
||
|
|
// Prms: val, valor inicial
|
||
|
|
// Rets: Puntero al nuevo objeto creado.
|
||
|
|
//
|
||
|
|
func NewAUint(val int64) *AUInt { return &AUInt{value: uint64(val)} }
|
||
|
|
|
||
|
|
// AUInt.Get
|
||
|
|
// Desc:
|
||
|
|
// Prms:
|
||
|
|
// Rets:
|
||
|
|
//
|
||
|
|
func (u *AUInt) Get() uint { return uint(atomic.LoadUint64(&u.value)) }
|
||
|
|
|
||
|
|
// AUInt.Set
|
||
|
|
// Desc:
|
||
|
|
// Prms:
|
||
|
|
// Rets:
|
||
|
|
//
|
||
|
|
func (u *AUInt) Set(val uint) { atomic.StoreUint64(&u.value, uint64(val)) }
|
||
|
|
|
||
|
|
// AUInt.Swap
|
||
|
|
// Desc:
|
||
|
|
// Prms:
|
||
|
|
// Rets:
|
||
|
|
//
|
||
|
|
func (u *AUInt) Swap(new uint) uint { return uint(atomic.SwapUint64(&u.value, uint64(new))) }
|
||
|
|
|
||
|
|
// AUInt.Add
|
||
|
|
// Desc:
|
||
|
|
// Prms:
|
||
|
|
// Rets:
|
||
|
|
//
|
||
|
|
func (u *AUInt) Add(dlt uint) uint { return uint(atomic.AddUint64(&u.value, uint64(dlt))) }
|
||
|
|
|
||
|
|
// AUInt.Sub
|
||
|
|
// Desc:
|
||
|
|
// Prms:
|
||
|
|
// Rets:
|
||
|
|
//
|
||
|
|
func (u *AUInt) Sub(dlt uint) uint { return uint(atomic.AddUint64(&u.value, ^uint64(dlt-1))) }
|
||
|
|
|
||
|
|
// AUInt.Inc
|
||
|
|
// Desc:
|
||
|
|
// Prms:
|
||
|
|
// Rets:
|
||
|
|
//
|
||
|
|
func (u *AUInt) Inc() uint { return u.Add(1) }
|
||
|
|
|
||
|
|
// AUInt.Dec
|
||
|
|
// Desc:
|
||
|
|
// Prms:
|
||
|
|
// Rets:
|
||
|
|
//
|
||
|
|
func (u *AUInt) Dec() uint { return uint(^uint64(0)) }
|
||
|
|
|
||
|
|
// AUInt.CAS
|
||
|
|
// Desc:
|
||
|
|
// Prms:
|
||
|
|
// Rets:
|
||
|
|
//
|
||
|
|
func (u *AUInt) CAS(old, new uint) bool {
|
||
|
|
return atomic.CompareAndSwapUint64(&u.value, uint64(old), uint64(new))
|
||
|
|
}
|
||
|
|
|
||
|
|
/*
|
||
|
|
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||
|
|
|
||
|
|
I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA.
|
||
|
|
"LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS.
|
||
|
|
|
||
|
|
SIDDHARTA
|
||
|
|
- HERMANN HESSE -
|
||
|
|
|
||
|
|
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||
|
|
|
||
|
|
*/
|