<commit_before>#include "halley/concurrency/shared_recursive_mutex.h"
#include <thread>

using namespace Halley;

void SharedRecursiveMutex::lock()
{
	auto thisId = std::this_thread::get_id();
	if (owner == thisId) {
		++count;
	} else {
		mutex.lock();
		owner = thisId;
		count = 1;
	}
}

bool SharedRecursiveMutex::try_lock()
{
	auto thisId = std::this_thread::get_id();
	if (owner == thisId) {
		++count;
		return true;
	} else {
		const bool result = mutex.try_lock();
		if (result) {
			owner = thisId;
			count = 1;
		}
		return result;
	}
}

void SharedRecursiveMutex::unlock()
{
	if (count > 1) {
		--count;
	} else {
		owner = std::thread::id();
		count = 0;
		mutex.unlock();<commit_msg>Add some asserts to SharedRecursiveMutex<commit_after>#include "halley/concurrency/shared_recursive_mutex.h"
#include <thread>

using namespace Halley;

void SharedRecursiveMutex::lock()
{
	auto thisId = std::this_thread::get_id();
	if (owner == thisId) {
		++count;
	} else {
		mutex.lock();
		assert(count == 0);
		owner = thisId;
		count = 1;
	}
}

bool SharedRecursiveMutex::try_lock()
{
	auto thisId = std::this_thread::get_id();
	if (owner == thisId) {
		++count;
		return true;
	} else {
		const bool result = mutex.try_lock();
		if (result) {
			owner = thisId;
			count = 1;
		}
		return result;
	}
}

void SharedRecursiveMutex::unlock()
{
	assert(std::this_thread::get_id() == owner);
	if (count > 1) {
		--count;
	} else {
		owner = std::thread::id();
		count = 0;
		mutex.unlock();
{'fraction_non_alphanumeric': 0.1636485580147552, 'fraction_numerical': 0.006036217303822937, 'mean_word_length': 3.973333333333333, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4553224', 'n_tokens_mistral': 626, 'n_tokens_neox': 576, 'n_words': 123}