<commit_before>// +build darwin,kqueue dragonfly freebsd netbsd openbsd

package notify

import (
	"errors"
	"fmt"
	"os"
	"path/filepath"
	"sync"
	"syscall"
)

// TODO: Take into account currently monitored files with those read from dir.

// newWatcher returns `kqueue` Watcher implementation.
func newWatcher(c chan<- EventInfo) watcher {
	k := &kqueue{
		idLkp:  make(map[int]*watched, 0),
		pthLkp: make(map[string]*watched, 0),
		c:      c,
		s:      make(chan struct{}, 1),
	}
	if err := k.init(); err != nil {
		// TODO: Does it really has to be this way?
		panic(err)
	}
	go k.monitor()
	return k
}

// KqEvent represents a single event.
type KqEvent struct {
	Kq *syscall.Kevent_t
	FI os.FileInfo
}

// Close closes all still open file descriptors and kqueue.
func (k *kqueue) Close() error {
	k.s <- struct{}{}
	if k.fd != nil {
		syscall.Close(*k.fd)
		k.fd = nil
	}
	k.Lock()
	for _, w := range k.idLkp {
		syscall.Close(w.fd)
	}
	k.idLkp, k.pthLkp = nil, nil
	k.Unlock()
	return nil
}

// sendEvents sends reported events one by one through chan.
func (k *kqueue) sendEvents(evn []event) {
	for i := range evn {
		k.c <- &evn[i]
	}<commit_msg>kqueue: Fix for data race.<commit_after>// +build darwin,kqueue dragonfly freebsd netbsd openbsd

package notify

import (
	"errors"
	"fmt"
	"os"
	"path/filepath"
	"sync"
	"syscall"
)

// TODO: Take into account currently monitored files with those read from dir.

// newWatcher returns `kqueue` Watcher implementation.
func newWatcher(c chan<- EventInfo) watcher {
	k := &kqueue{
		idLkp:  make(map[int]*watched, 0),
		pthLkp: make(map[string]*watched, 0),
		c:      c,
		s:      make(chan struct{}, 1),
	}
	if err := k.init(); err != nil {
		// TODO: Does it really has to be this way?
		panic(err)
	}
	go k.monitor()
	return k
}

// KqEvent represents a single event.
type KqEvent struct {
	Kq *syscall.Kevent_t
	FI os.FileInfo
}

// Close closes all still open file descriptors and kqueue.
func (k *kqueue) Close() error {
	k.s <- struct{}{}
	k.Lock()
	if k.fd != nil {
		syscall.Close(*k.fd)
	}
	for _, w := range k.idLkp {
		syscall.Close(w.fd)
	}
	k.idLkp, k.pthLkp = nil, nil
	k.Unlock()
	return nil
}

// sendEvents sends reported events one by one through chan.
func (k *kqueue) sendEvents(evn []event) {
	for i := range evn {
		k.c <- &evn[i]
	}
{'fraction_non_alphanumeric': 0.14273356401384082, 'fraction_numerical': 0.0025951557093425604, 'mean_word_length': 3.2054545454545456, 'pattern_counts': {'":': 0, '<': 9, '<?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': '4580455', 'n_tokens_mistral': 971, 'n_tokens_neox': 894, 'n_words': 278}