Пример #1
0
func ExampleNewQid() {
	buf := make([]byte, 13)
	qid, buf, err := styxproto.NewQid(buf, 1, 369, 0x84961)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(qid)

	// Output: type=1 ver=369 path=84961
}
Пример #2
0
Файл: pool.go Проект: droyo/styx
// Put creates a new, unique Qid of the given type and adds it to the
// pool. The returned Qid should be considered read-only. Put will not
// overwrite an existing Qid; if there is already a Qid associated with name,
// it is returned instead.
func (p *Pool) Put(name string, qtype uint8) styxproto.Qid {
	buf := make([]byte, styxproto.QidLen)
	path := atomic.AddUint64(&p.path, 1)

	qid, _, err := styxproto.NewQid(buf, qtype, 0, path)
	if err != nil {
		panic(err)
	}

	p.m.Do(func(m map[interface{}]interface{}) {
		if existing, ok := m[name]; ok {
			qid = existing.(styxproto.Qid)
		} else {
			m[name] = qid
		}
	})
	p.m.Put(name, qid)
	return qid
}