<commit_before>// +build windows

package pid

import (
	"errors"
	"sync"
)

type Pool struct {
	sync.Mutex
	pool map[uint32]struct{}
	cur  uint32
}

func NewPool() *Pool {
	return &Pool{
		pool: make(map[uint32]struct{}),
	}
}

func (p *Pool) Get() (uint32, error) {
	p.Lock()
	defer p.Unlock()

	pid := p.cur + 1
	for pid != p.cur {
		// 0 is reserved and invalid
		if pid == 0 {
			pid = 1
		}
		if _, ok := p.pool[pid]; !ok {
			p.cur = pid
			return pid, nil
		}
		pid++
	}

	return 0, errors.New("pid pool exhausted")
}

func (p *Pool) Put(pid uint32) {
	p.Lock()
	delete(p.pool, pid)
	p.Unlock()
}<commit_msg>windows: Ensure pids are not reused if active<commit_after>// +build windows

package pid

import (
	"errors"
	"sync"
)

type Pool struct {
	sync.Mutex
	pool map[uint32]struct{}
	cur  uint32
}

func NewPool() *Pool {
	return &Pool{
		pool: make(map[uint32]struct{}),
	}
}

func (p *Pool) Get() (uint32, error) {
	p.Lock()
	defer p.Unlock()

	pid := p.cur + 1
	for pid != p.cur {
		// 0 is reserved and invalid
		if pid == 0 {
			pid = 1
		}
		if _, ok := p.pool[pid]; !ok {
			p.cur = pid
			p.pool[pid] = struct{}{}
			return pid, nil
		}
		pid++
	}

	return 0, errors.New("pid pool exhausted")
}

func (p *Pool) Put(pid uint32) {
	p.Lock()
	delete(p.pool, pid)
	p.Unlock()
}
{'fraction_non_alphanumeric': 0.16950464396284828, 'fraction_numerical': 0.02321981424148607, 'mean_word_length': 2.8597014925373134, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1956705', 'n_tokens_mistral': 591, 'n_tokens_neox': 540, 'n_words': 153}