// // 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 syns import ( "sync/atomic" "time" ) type ( // ANanos // Type: Struct // Desc: // // ANanos struct { value int64 } ) // NewANanos // Desc: Función constructor para ANanos // // Prms: val, valor inicial // Rets: Puntero al nuevo objeto creado. // func NewANanos(val time.Duration) *ANanos { return &ANanos{value: int64(val)} } // ANanos.Get // Desc: // Prms: // Rets: // func (i *ANanos) Get() time.Duration { return time.Duration(atomic.LoadInt64(&i.value)) } // ANanos.Set // Desc: // Prms: // Rets: // func (i *ANanos) Set(val time.Duration) { atomic.StoreInt64(&i.value, int64(val)) } // ANanos.Swap // Desc: // Prms: // Rets: // func (i *ANanos) Swap(new time.Duration) time.Duration { return time.Duration(atomic.SwapInt64(&i.value, int64(new))) } // ANanos.Add // Desc: // Prms: // Rets: // func (i *ANanos) Add(dlt time.Duration) time.Duration { return time.Duration(atomic.AddInt64(&i.value, int64(dlt))) } // ANanos.Sub // Desc: // Prms: // Rets: // func (i *ANanos) Sub(dlt time.Duration) time.Duration { return time.Duration(atomic.AddInt64(&i.value, int64(-dlt))) } // ANanos.CAS // Desc: // Prms: // Rets: // func (i *ANanos) CAS(old, new time.Duration) bool { return atomic.CompareAndSwapInt64(&i.value, int64(old), int64(new)) } // ANanos.GetTime // Desc: // Prms: // Rets: // func (i *ANanos) GetTime() time.Time { return time.Unix(0, atomic.LoadInt64(&i.value)) } // ANanos.SetTime // Desc: // Prms: // Rets: // func (i *ANanos) SetTime(val time.Time) { atomic.StoreInt64(&i.value, val.UnixNano()) } // ANanos.GetNanos // Desc: // Prms: // Rets: // func (i *ANanos) GetNanos() int64 { return atomic.LoadInt64(&i.value) } // ANanos.SetNanos // Desc: // Prms: // Rets: // func (i *ANanos) SetNanos(val int64) { atomic.StoreInt64(&i.value, val) } // ANanos.SetNow // Desc: // Prms: // Rets: // func (i *ANanos) SetNow() time.Time { nw := time.Now() i.SetTime(nw) return nw } /* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA. "LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS. SIDDHARTA - HERMANN HESSE - ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */