// libgcc returns the value of gcc -print-libgcc-file-name.
17673
func libgcc(ctx *Context) (string, error) {
	args := []string{
		"-print-libgcc-file-name",
	}
	var buf bytes.Buffer
	cmd := gccCmd(&Package{Context: ctx}, "") // TODO(dfc) hack
	err := runOut(&buf, ".", nil, cmd[0], args...)
	return strings.TrimSpace(buf.String()), err
}
243149
func (c *VFSContext) getGCSClient() (*storage.Service, error) {
	c.mutex.Lock()
	defer c.mutex.Unlock()

	if c.gcsClient != nil {
		return c.gcsClient, nil
	}

	// TODO: Should we fall back to read-only?
	scope := storage.DevstorageReadWriteScope

	httpClient, err := google.DefaultClient(context.Background(), scope)
	if err != nil {
		return nil, fmt.Errorf("error building GCS HTTP client: %v", err)
	}

	gcsClient, err := storage.New(httpClient)
	if err != nil {
		return nil, fmt.Errorf("error building GCS client: %v", err)
	}

	c.gcsClient = gcsClient
	return gcsClient, nil
}
909693
func GC() {
	gpmLock.Lock()
	if len(garbagePathMap) == 0 {
		// No need for GC if map is empty
		gpmLock.Unlock()
		return
	}
	gpmLock.Unlock()

	// if content exists in the garbage paths
	// we can trigger GC to run, providing a
	// channel to be notified on completion
	waitGC := make(chan struct{})
	gpmChan <- waitGC
	// wait for GC completion
	<-waitGC
}
802556
func GCRepo(
	ctx context.Context, config libkbfs.Config, tlfHandle *tlfhandle.Handle,
	repoName string, options GCOptions) (err error) {
	log := config.MakeLogger("")
	log.CDebugf(ctx, "Checking whether GC is needed for %s/%s",
		tlfHandle.GetCanonicalName(), repoName)

	uniqID, err := makeUniqueID(ctx, config)
	if err != nil {
		return err
	}

	fs, _, err := getOrCreateRepoAndID(
		ctx, config, tlfHandle, repoName, uniqID, getOnly)
	if err != nil {
		return err
	}
	defer func() {
		if err == nil {
			err = markSuccessfulGC(ctx, config, fs)
		}
	}()

	fsStorer, err := filesystem.NewStorage(fs)
	if err != nil {
		return err
	}
	var fsStorage storage.Storer
	fsStorage = fsStorer

	// Wrap it in an on-demand storer, so we don't try to read all the
	// objects of big repos into memory at once.
	var storage storage.Storer
	storage, err = NewOnDemandStorer(fsStorage)
	if err != nil {
		return err
	}

	// Wrap it in an "ephemeral" config with a fixed pack window, so
	// we create packs with delta compression, but don't persist the
	// pack window setting to disk.
	storage = &ephemeralGitConfigWithFixedPackWindow{
		storage,
		fsStorage.(storer.Initializer),
		fsStorage.(storer.PackfileWriter),
		fsStorage.(storer.LooseObjectStorer),
		fsStorage.(storer.PackedObjectStorer),
		10,
	}

	doPackRefs, _, doPruneLoose, doObjectRepack, _, err := NeedsGC(
		storage, options)
	if err != nil {
		return err
	}
	if !doPackRefs && !doPruneLoose && !doObjectRepack {
		log.CDebugf(ctx, "Skipping GC")
		return nil
	}

	doGC, err := canDoGC(ctx, config, fs, log)
	if err != nil {
		return err
	}
	if !doGC {
		log.CDebugf(ctx, "Skipping GC due to other worker")
		return nil
	}

	defer func() {
		removeErr := fs.Remove(repoGCInProgressFileName)
		if err == nil {
			err = removeErr
		}
	}()

	// Check the GC thresholds again since they might have changed
	// while getting the lock.
	doPackRefs, numLooseRefs, doPruneLoose, doObjectRepack,
		numObjectPacks, err := NeedsGC(storage, options)
	if err != nil {
		return err
	}
	if !doPackRefs && !doPruneLoose && !doObjectRepack {
		log.CDebugf(ctx, "GC no longer needed")
		return nil
	}

	if doPackRefs {
		log.CDebugf(ctx, "Packing %s loose refs", numLooseRefs)
		err = storage.PackRefs()
		if err != nil {
			return err
		}
	}

	if doPruneLoose {
		repo, err := gogit.Open(storage, nil)
		if err != nil {
			return err
		}
		err = repo.Prune(gogit.PruneOptions{
			OnlyObjectsOlderThan: options.PruneExpireTime,
			Handler:              repo.DeleteObject,
		})
		if err != nil {
			return err
		}
	}

	if doObjectRepack {
		log.CDebugf(ctx, "Re-packing %d object packs", numObjectPacks)
		repo, err := gogit.Open(storage, nil)
		if err != nil {
			return err
		}
		err = repo.RepackObjects(&gogit.RepackConfig{
			OnlyDeletePacksOlderThan: options.PruneExpireTime,
		})
		if err != nil {
			return err
		}
	}

	// TODO: add object re-packing.
	return nil
}
116771
func GC(m *Map, filter *GCFilter) int {
	if filter.RemoveExpired {
		t, _ := bpf.GetMtime()
		tsec := t / 1000000000
		filter.Time = uint32(tsec)
	}

	return doGC(m, filter)
}
923562
func (ms *AggMetrics) GC() {
	for {
		unix := time.Duration(time.Now().UnixNano())
		diff := ms.gcInterval - (unix % ms.gcInterval)
		time.Sleep(diff + time.Minute)
		log.Info("checking for stale chunks that need persisting.")
		now := uint32(time.Now().Unix())
		chunkMinTs := now - uint32(ms.chunkMaxStale)
		metricMinTs := now - uint32(ms.metricMaxStale)

		// as this is the only goroutine that can delete from ms.Metrics
		// we only need to lock long enough to get the list of orgs, then for each org
		// get the list of active metrics.
		// It doesn't matter if new orgs or metrics are added while we iterate these lists.
		ms.RLock()
		orgs := make([]uint32, 0, len(ms.Metrics))
		for o := range ms.Metrics {
			orgs = append(orgs, o)
		}
		ms.RUnlock()
		for _, org := range orgs {
			orgActiveMetrics := promActiveMetrics.WithLabelValues(strconv.Itoa(int(org)))
			keys := make([]schema.Key, 0, len(ms.Metrics[org]))
			ms.RLock()
			for k := range ms.Metrics[org] {
				keys = append(keys, k)
			}
			ms.RUnlock()
			for _, key := range keys {
				gcMetric.Inc()
				ms.RLock()
				a := ms.Metrics[org][key]
				ms.RUnlock()
				points, stale := a.GC(now, chunkMinTs, metricMinTs)
				if stale {
					log.Debugf("metric %s is stale. Purging data from memory.", key)
					ms.Lock()
					delete(ms.Metrics[org], key)
					orgActiveMetrics.Set(float64(len(ms.Metrics[org])))
					// note: this is racey. if a metric has just become unstale, it may have created a new chunk,
					// pruning an older one. in which case we double-subtract those points
					// hard to fix and super rare. see https://github.com/grafana/metrictank/pull/1242
					totalPoints.DecUint64(uint64(points))
					ms.Unlock()
				}
			}
			ms.RLock()
			orgActive := len(ms.Metrics[org])
			orgActiveMetrics.Set(float64(orgActive))
			ms.RUnlock()

			// If this org has no keys, then delete the org from the map
			if orgActive == 0 {
				// To prevent races, we need to check that there are still no metrics for the org while holding a write lock
				ms.Lock()
				orgActive = len(ms.Metrics[org])
				if orgActive == 0 {
					delete(ms.Metrics, org)
				}
				ms.Unlock()
			}
		}

		// Get the totalActive across all orgs.
		totalActive := 0
		ms.RLock()
		for o := range ms.Metrics {
			totalActive += len(ms.Metrics[o])
		}
		ms.RUnlock()
		metricsActive.Set(totalActive)
	}
}
1077203
func GoDoc(args ...interface{}) string {
	s := args[0].(string)
	if s == "" {
		s = "no documentation yet"
	}

	return "// " + strings.Replace(s, "\n", "\n// ", -1)
}
31438
func (r *MemoryTTL) StartGC(gcInterval time.Duration) {
	if gcInterval <= 0 {
		return
	}

	ticker := time.NewTicker(gcInterval)
	done := make(chan struct{})

	r.Lock()
	r.gcTicker = ticker
	r.done = done
	r.Unlock()

	go func() {
		for {
			select {
			case <-ticker.C:
				now := time.Now()

				r.Lock()
				for key := range r.cache.items {
					if !r.isValidTime(key, now) {
						r.delete(key)
					}
				}
				r.Unlock()
			case <-done:
				return
			}
		}
	}()
}
1026060
func (f *file) lintFuncDoc(fn *ast.FuncDecl) {
	if !ast.IsExported(fn.Name.Name) {
		// func is unexported
		return
	}
	kind := "function"
	name := fn.Name.Name
	if fn.Recv != nil && len(fn.Recv.List) > 0 {
		// method
		kind = "method"
		recv := receiverType(fn)
		if !ast.IsExported(recv) {
			// receiver is unexported
			return
		}
		if commonMethods[name] {
			return
		}
		switch name {
		case "Len", "Less", "Swap":
			if f.pkg.sortable[recv] {
				return
			}
		}
		name = recv + "." + name
	}
	if fn.Doc == nil {
		f.errorf(fn, 1, link(docCommentsLink), category("comments"), "exported %s %s should have comment or be unexported", kind, name)
		return
	}
	s := fn.Doc.Text()
	prefix := fn.Name.Name + " "
	if !strings.HasPrefix(s, prefix) {
		f.errorf(fn.Doc, 1, link(docCommentsLink), category("comments"), `comment on exported %s %s should be of the form "%s..."`, kind, name, prefix)
	}
}
69256
func rungcc3(pkg *Package, dir string, ofile string, ofiles []string) error {
	args := []string{}
	args = append(args, "-o", ofile)
	args = append(args, ofiles...)
	args = append(args, "-Wl,-r", "-nostdlib")
	if gccSupportsNoPie(pkg) {
		args = append(args, "-no-pie")
	}
	var cmd []string
	if len(pkg.CXXFiles) > 0 || len(pkg.SwigCXXFiles) > 0 {
		cmd = gxxCmd(pkg, dir)
	} else {
		cmd = gccCmd(pkg, dir)
	}
	if !strings.HasPrefix(cmd[0], "clang") {
		libgcc, err := libgcc(pkg.Context)
		if err != nil {
			return nil
		}
		args = append(args, libgcc)
	}
	t0 := time.Now()
	var buf bytes.Buffer
	err := runOut(&buf, dir, nil, cmd[0], append(cmd[1:], args...)...)
	if err != nil {
		fmt.Fprintf(os.Stderr, "# %s\n", pkg.ImportPath)
		io.Copy(os.Stderr, &buf)
	}
	pkg.Record("gcc3", time.Since(t0))
	return err
}
1209818
func OCItoGRPC(ociSpec *specs.Spec) (*Spec, error) {
	s := &Spec{}

	err := copyStruct(s, ociSpec)

	return s, err
}
22284
func (s *ProjectsService) RunGC(projectName string, input *GCInput) (*Response, error) {
	u := fmt.Sprintf("projects/%s/gc'", url.QueryEscape(projectName))

	req, err := s.client.NewRequest("POST", u, input)
	if err != nil {
		return nil, err
	}

	resp, err := s.client.Do(req, nil)
	if err != nil {
		return resp, err
	}

	return resp, err
}
1060861
func (p *MemProvider) GC() {
	p.lock.RLock()
	for {
		// No session in the list.
		e := p.list.Back()
		if e == nil {
			break
		}

		if (e.Value.(*MemStore).lastAccess.Unix() + p.maxLifetime) < time.Now().Unix() {
			p.lock.RUnlock()
			p.lock.Lock()
			p.list.Remove(e)
			delete(p.data, e.Value.(*MemStore).sid)
			p.lock.Unlock()
			p.lock.RLock()
		} else {
			break
		}
	}
	p.lock.RUnlock()
}
834908
func (g *Group) PrintFunc(f func(*Group)) *Statement {
	s := PrintFunc(f)
	g.items = append(g.items, s)
	return s
}
1058507
func Gcflags(flags ...string) func(*Context) error {
	return func(c *Context) error {
		c.gcflags = append(c.gcflags, flags...)
		return nil
	}
}
953142
func (gce *Cloud) getDiskByName(diskName string, zone string) (*gceDisk, error) {
	disk, err := gce.findDiskByName(diskName, zone)
	if disk == nil && err == nil {
		return nil, fmt.Errorf("GCE persistent disk not found: diskName=%q zone=%q", diskName, zone)
	}
	return disk, err
}
863553
func compactCCC() {
	m := make(map[uint8]uint8)
	for i := range chars {
		c := &chars[i]
		m[c.ccc] = 0
	}
	cccs := []int{}
	for v, _ := range m {
		cccs = append(cccs, int(v))
	}
	sort.Ints(cccs)
	for i, c := range cccs {
		cccMap[uint8(i)] = uint8(c)
		m[uint8(c)] = uint8(i)
	}
	for i := range chars {
		c := &chars[i]
		c.origCCC = c.ccc
		c.ccc = m[c.ccc]
	}
	if len(m) >= 1<<6 {
		log.Fatalf("too many difference CCC values: %d >= 64", len(m))
	}
}