コード例 #1
0
ファイル: log.go プロジェクト: fengshao0907/beanseye
func OpenErrorLog(error_log_path string) (success bool, err error) {
	lock.Lock()
	defer lock.Unlock()
	success = false
	if ErrorLog == nil {
		if ErrorLog, ErrorFd, err = openLog(error_log_path); err == nil {
			success = true
		}
	} else {
		// start swap exist logger and new logger, and Close the older fd in later, if it is Stdout, leave it
		error_log, error_file, e := openLog(error_log_path)
		err = e
		if err == nil {
			success = true
			error_log = (*log.Logger)(atomic.SwapPointer((*unsafe.Pointer)(unsafe.Pointer(&ErrorLog)), unsafe.Pointer(error_log)))
			error_file = (*os.File)(atomic.SwapPointer((*unsafe.Pointer)(unsafe.Pointer(&ErrorFd)), unsafe.Pointer(error_file)))
			if e = error_file.Close(); e != nil {
				log.Println("close the old errorlog fd failure with, ", e)
			}
		} else {
			log.Println("open " + error_log_path + " failed: " + err.Error())
		}
	}
	return
}
コード例 #2
0
ファイル: mmux_connection.go プロジェクト: kevinxusz/momonga
func (self *MmuxConnection) Attach(conn Connection) {
	self.Mutex.Lock()
	defer self.Mutex.Unlock()

	var container Connection
	container = conn
	old := atomic.SwapPointer((*unsafe.Pointer)((unsafe.Pointer)(&self.Connection)), unsafe.Pointer(&container))
	if old != nil {
		// 1.If the ClientId represents a Client already connected to the Server
		// then the Server MUST disconnect the existing Client [MQTT-3.1.4-2].
		(*(*Connection)(old)).Close()
		log.Debug("close existing connection")
	}

	self.CleanSession = conn.ShouldCleanSession()
	if conn.ShouldCleanSession() {
		self.OfflineQueue = self.OfflineQueue[:0]
		self.SubscribeMap = make(map[string]bool)
		self.SubscribedTopics = make(map[string]*SubscribeSet)

		// Should I remove remaining QoS1, QoS2 message at this time?
		self.OutGoingTable.Clean()
	} else {
		if len(self.OfflineQueue) > 0 {
			log.Info("Process Offline Queue: Playback: %d", len(self.OfflineQueue))
			for i := 0; i < len(self.OfflineQueue); i++ {
				self.writeMessageQueue(self.OfflineQueue[i])
			}
			self.OfflineQueue = self.OfflineQueue[:0]
		}
	}
}
コード例 #3
0
ファイル: memdqueue.go プロジェクト: borgstrom/gocb
func (req *memdQRequest) Cancel() bool {
	queue := (*memdQueue)(atomic.SwapPointer(&req.queuedWith, nil))
	if queue == nil {
		return false
	}
	return true
}
コード例 #4
0
ファイル: memdqueue.go プロジェクト: borgstrom/gocb
func (s *memdQueue) QueueRequest(req *memdQRequest) bool {
	s.lock.RLock()
	if s.isDrained {
		s.lock.RUnlock()
		return false
	}

	oldSP := atomic.SwapPointer(&req.queuedWith, unsafe.Pointer(s))
	if oldSP != nil {
		panic("Request was dispatched while already queued somewhere.")
	}

	logDebugf("Writing request to queue!")

	// Try to write the request to the queue, if the queue is full,
	//   we immediately fail the request with a queueOverflow error.
	select {
	case s.reqsCh <- req:
		s.lock.RUnlock()
		return true

	default:
		s.lock.RUnlock()
		// As long as we have not lost ownership, dispatch a queue overflow error.
		if atomic.CompareAndSwapPointer(&req.queuedWith, unsafe.Pointer(s), nil) {
			req.Callback(nil, overloadError{})
		}
		return true
	}
}
コード例 #5
0
func (wrapper *FileJournalChunkWrapper) Dispose() error {
	chunk := (*FileJournalChunk)(atomic.SwapPointer((*unsafe.Pointer)(unsafe.Pointer(&wrapper.chunk)), nil))
	if chunk == nil {
		return errors.New("already disposed")
	}
	return wrapper.journal.deleteRef((*FileJournalChunk)(chunk))
}
コード例 #6
0
ファイル: routedata.go プロジェクト: nullbus/gocb
func (ptr *routeDataPtr) clear() *routeData {
	val := atomic.SwapPointer(&ptr.data, nil)
	if val == nil {
		panic("Attempted to clear a nil routeDataPtr")
	}
	return (*routeData)(val)
}
コード例 #7
0
ファイル: cache.go プロジェクト: sheepkiller/curator-go
func (c *NodeCache) setNewData(newData *ChildData) {
	previousData := (*ChildData)(atomic.SwapPointer((*unsafe.Pointer)(unsafe.Pointer(&c.data)), unsafe.Pointer(newData)))

	if !reflect.DeepEqual(previousData, newData) {
		c.listeners.ForEach(func(listener interface{}) {
			listener.(NodeCacheListener).NodeChanged()
		})
	}
}
コード例 #8
0
ファイル: simple_lru_cache.go プロジェクト: ting-xu/gocommons
func (this *_SimpleLruCache) Dispose() {
	ptr := atomic.SwapPointer((*unsafe.Pointer)(unsafe.Pointer(&this.qpsCounter)), nil)
	if ptr != nil {
		(*_SimpleQpsCounter)(ptr).Stop()
	}
	if this.cleanupTicker != nil {
		this.cleanupTicker.Stop()
		this.cleanupTicker = nil
	}
}
コード例 #9
0
ファイル: dynstring.go プロジェクト: mwitkow/go-flagz
// Set updates the value from a string representation in a thread-safe manner.
// This operation may return an error if the provided `input` doesn't parse, or the resulting value doesn't pass an
// optional validator.
// If a notifier is set on the value, it will be invoked in a separate go-routine.
func (d *DynStringValue) Set(val string) error {
	if d.validator != nil {
		if err := d.validator(val); err != nil {
			return err
		}
	}
	oldPtr := atomic.SwapPointer(&d.ptr, unsafe.Pointer(&val))
	if d.notifier != nil {
		go d.notifier(*(*string)(oldPtr), val)
	}
	return nil
}
コード例 #10
0
ファイル: mcache.go プロジェクト: jackdoe/no
func (mc *mCache) storeDb(p, bucket int, db *database) {
	ptr := (*unsafe.Pointer)(unsafe.Pointer(&mc.dbRings[p][bucket]))
	if odb := (*database)(atomic.SwapPointer(ptr, unsafe.Pointer(db))); odb != nil {
		if db != nil {
			log.Printf("FORCED eviction of db for %d (p%d bucket %d)", odb.time.Unix(), p, bucket)
		}
		if odb.counter() > 0 {
			log.Printf("LEAKED DATABASE STRUCT %d p%d!!!!!!!!", odb.time.Unix(), p)
			mc.dbLeak = append(mc.dbLeak, odb)
		}
	}
}
コード例 #11
0
ファイル: routedata.go プロジェクト: avsej/gocb
func (ptr *routeDataPtr) update(old, new *routeData) bool {
	if new == nil {
		panic("Attempted to update to nil routeData")
	}
	if old != nil {
		return atomic.CompareAndSwapPointer(&ptr.data, unsafe.Pointer(old), unsafe.Pointer(new))
	} else {
		if atomic.SwapPointer(&ptr.data, unsafe.Pointer(new)) != nil {
			panic("Updated from nil attempted on initialized routeDataPtr")
		}
		return true
	}
}
コード例 #12
0
ファイル: mcache.go プロジェクト: jackdoe/no
func (mc *mCache) storeIndex(bucket int, idx *index) {
	ptr := (*unsafe.Pointer)(unsafe.Pointer(&mc.idxRing[bucket]))
	if oidx := (*index)(atomic.SwapPointer(ptr, unsafe.Pointer(idx))); oidx != nil {
		if idx != nil {
			log.Printf("FORCED eviction of idx for %d (bucket %d)", oidx.time.Unix(), bucket)
		}

		if oidx.counter() > 0 {
			log.Printf("LEAKED INDEX STRUCT %d!!!!!!!!", oidx.time.Unix())
			mc.idxLeak = append(mc.idxLeak, oidx)
		}
	}
}
コード例 #13
0
ファイル: client.go プロジェクト: XisiHuang/cockroach
// connect attempts a single connection attempt. On success, updates `c.conn`.
func (c *Client) connect() error {
	conn, err := tlsDialHTTP(c.addr.NetworkField, c.addr.StringField, c.tlsConfig)
	if err != nil {
		return err
	}
	if oldConn := (*internalConn)(atomic.SwapPointer(&c.conn, unsafe.Pointer(&internalConn{
		conn:   conn,
		client: rpc.NewClientWithCodec(codec.NewClientCodec(conn)),
	}))); oldConn != nil {
		oldConn.conn.Close()
	}

	return nil
}
コード例 #14
0
ファイル: dynstringslice.go プロジェクト: mwitkow/go-flagz
// Set updates the value from a string representation in a thread-safe manner.
// This operation may return an error if the provided `input` doesn't parse, or the resulting value doesn't pass an
// optional validator.
// If a notifier is set on the value, it will be invoked in a separate go-routine.
func (d *DynStringSliceValue) Set(val string) error {
	v, err := csv.NewReader(strings.NewReader(val)).Read()
	if err != nil {
		return err
	}
	if d.validator != nil {
		if err := d.validator(v); err != nil {
			return err
		}
	}
	oldPtr := atomic.SwapPointer(&d.ptr, unsafe.Pointer(&v))
	if d.notifier != nil {
		go d.notifier(*(*[]string)(oldPtr), v)
	}
	return nil
}
コード例 #15
0
ファイル: dynfloat64.go プロジェクト: mwitkow/go-flagz
// Set updates the value from a string representation in a thread-safe manner.
// This operation may return an error if the provided `input` doesn't parse, or the resulting value doesn't pass an
// optional validator.
// If a notifier is set on the value, it will be invoked in a separate go-routine.
func (d *DynFloat64Value) Set(input string) error {
	val, err := strconv.ParseFloat(input, 64)
	if err != nil {
		return err
	}
	if d.validator != nil {
		if err := d.validator(val); err != nil {
			return err
		}
	}
	oldPtr := atomic.SwapPointer(&d.ptr, unsafe.Pointer(&val))
	if d.notifier != nil {
		go d.notifier(*(*float64)(oldPtr), val)
	}
	return nil
}
コード例 #16
0
ファイル: dynjson.go プロジェクト: mwitkow/go-flagz
// Set updates the value from a string representation in a thread-safe manner.
// This operation may return an error if the provided `input` doesn't parse, or the resulting value doesn't pass an
// optional validator.
// If a notifier is set on the value, it will be invoked in a separate go-routine.
func (d *DynJSONValue) Set(input string) error {
	someStruct := reflect.New(d.structType).Interface()
	if err := json.Unmarshal([]byte(input), someStruct); err != nil {
		return err
	}
	if d.validator != nil {
		if err := d.validator(someStruct); err != nil {
			return err
		}
	}
	oldPtr := atomic.SwapPointer(&d.ptr, unsafe.Pointer(reflect.ValueOf(someStruct).Pointer()))
	if d.notifier != nil {
		go d.notifier(d.unsafeToStoredType(oldPtr), someStruct)
	}
	return nil
}
コード例 #17
0
ファイル: dynstringset.go プロジェクト: mwitkow/go-flagz
// Set updates the value from a string representation in a thread-safe manner.
// This operation may return an error if the provided `input` doesn't parse, or the resulting value doesn't pass an
// optional validator.
// If a notifier is set on the value, it will be invoked in a separate go-routine.
func (d *DynStringSetValue) Set(val string) error {
	v, err := csv.NewReader(strings.NewReader(val)).Read()
	if err != nil {
		return err
	}
	s := buildStringSet(v)
	if d.validator != nil {
		if err := d.validator(s); err != nil {
			return err
		}
	}
	oldPtr := atomic.SwapPointer(&d.ptr, unsafe.Pointer(&s))
	if d.notifier != nil {
		go d.notifier(*(*map[string]struct{})(oldPtr), s)
	}
	return nil
}
コード例 #18
0
ファイル: dynproto3.go プロジェクト: mwitkow/go-flagz
// Set updates the value from a string representation in a thread-safe manner.
// This operation may return an error if the provided `input` doesn't parse, or the resulting value doesn't pass an
// optional validator.
// If a notifier is set on the value, it will be invoked in a separate go-routine.
func (d *DynProto3Value) Set(input string) error {
	someStruct := reflect.New(d.structType).Interface().(proto.Message)
	if strings.HasPrefix(strings.TrimSpace(input), "{") && strings.HasSuffix(strings.TrimSpace(input), "}") {
		if err := jsonpb.UnmarshalString(input, someStruct); err != nil {
			return err
		}
	} else {
		if err := proto.Unmarshal([]byte(input), someStruct); err != nil {
			return err
		}
	}

	if d.validator != nil {
		if err := d.validator(someStruct); err != nil {
			return err
		}
	}
	oldPtr := atomic.SwapPointer(&d.ptr, unsafe.Pointer(reflect.ValueOf(someStruct).Pointer()))
	if d.notifier != nil {
		go d.notifier(d.unsafeToStoredType(oldPtr).(proto.Message), someStruct)
	}
	return nil
}
コード例 #19
0
ファイル: sync_386.go プロジェクト: nimishzynga/go-couchbase
func SwapPointer(addr *unsafe.Pointer, new unsafe.Pointer) unsafe.Pointer {
	return orig.SwapPointer(addr, new)
}
コード例 #20
0
ファイル: atomic.go プロジェクト: sasha-s/atomic
// Swap atomically stores the new value and returns the old one.
func (a *Pointer) Swap(v unsafe.Pointer) unsafe.Pointer {
	return atomic.SwapPointer(&a.x, v)
}
コード例 #21
0
ファイル: routedata.go プロジェクト: avsej/gocb
func (ptr *routeDataPtr) clear() *routeData {
	val := atomic.SwapPointer(&ptr.data, nil)
	return (*routeData)(val)
}
コード例 #22
0
ファイル: mmux_connection.go プロジェクト: kevinxusz/momonga
func (self *MmuxConnection) Detach(conn Connection, dummy *DummyPlug) {
	var container Connection
	container = dummy

	atomic.SwapPointer((*unsafe.Pointer)((unsafe.Pointer)(&self.Connection)), unsafe.Pointer(&container))
}