<commit_before>package main

import (
	"fmt"
	"io"
	"sync"
)

type PrintResetter interface {
	Print(string) (int, error)
	Reset()
}

func NewPrinter(target io.Writer, maxCol, maxRow int) *Printer {
	return &Printer{
		target:  target,
		maxCol:  maxCol,
		maxRow:  maxRow,
		printed: 0,
		mutex:   &sync.Mutex{},
	}
}

type Printer struct {
	target  io.Writer
	maxCol  int
	maxRow  int
	printed int
	mutex   *sync.Mutex
}

func (p *Printer) Print(line string) (n int, err error) {
	p.mutex.Lock()
	if p.printed == p.maxRow {
		p.mutex.Unlock()
		return 0, nil
	}

	if p.printed == 0 {
		fmt.Fprintf(p.target, "\n")
	}

	// If we're on the last line, cut the newline character off
	if p.printed == p.maxRow-1 && len(line) > 0 && line[len(line)-1] == '\n' {
		n, err = p.printLine(line[:len(line)-1])
	} else {
		n, err = p.printLine(line)
	}

	if err == nil {
		p.printed++
	}

	p.mutex.Unlock()
	return
}

func (p *Printer) printLine(line string) (n int, err error) {
	if len(line) > p.maxCol {
		n, err = fmt.Fprintf(p.target, "%s\n", line[:p.maxCol])
	} else {
		n, err = fmt.Fprintf(p.target, "%s", line)
	}
	return
}

func (p *Printer) Reset() {
	p.mutex.Lock()
	p.printed = 0
	p.mutex.Unlock()
}
<commit_msg>Use  to unlock printer mutex<commit_after>package main

import (
	"fmt"
	"io"
	"sync"
)

type PrintResetter interface {
	Print(string) (int, error)
	Reset()
}

func NewPrinter(target io.Writer, maxCol, maxRow int) *Printer {
	return &Printer{
		target:  target,
		maxCol:  maxCol,
		maxRow:  maxRow,
		printed: 0,
		mutex:   &sync.Mutex{},
	}
}

type Printer struct {
	target  io.Writer
	maxCol  int
	maxRow  int
	printed int
	mutex   *sync.Mutex
}

func (p *Printer) Print(line string) (n int, err error) {
	p.mutex.Lock()
	defer p.mutex.Unlock()

	if p.printed == p.maxRow {
		return 0, nil
	}

	if p.printed == 0 {
		fmt.Fprintf(p.target, "\n")
	}

	// If we're on the last line, cut the newline character off
	if p.printed == p.maxRow-1 && len(line) > 0 && line[len(line)-1] == '\n' {
		n, err = p.printLine(line[:len(line)-1])
	} else {
		n, err = p.printLine(line)
	}

	if err == nil {
		p.printed++
	}

	return
}

func (p *Printer) printLine(line string) (n int, err error) {
	if len(line) > p.maxCol {
		n, err = fmt.Fprintf(p.target, "%s\n", line[:p.maxCol])
	} else {
		n, err = fmt.Fprintf(p.target, "%s", line)
	}
	return
}

func (p *Printer) Reset() {
	p.mutex.Lock()
	p.printed = 0
	p.mutex.Unlock()
}

{'fraction_non_alphanumeric': 0.16879374228077398, 'fraction_numerical': 0.006587072869493619, 'mean_word_length': 3.1396933560477, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2670982', 'n_tokens_mistral': 1082, 'n_tokens_neox': 1025, 'n_words': 264}