mirror of
https://github.com/textmate/textmate.git
synced 2026-04-28 03:00:34 -04:00
Only lock mutex for critical code
This commit is contained in:
@@ -124,11 +124,15 @@ namespace
|
||||
|
||||
typedef std::shared_ptr<stream_t> stream_ptr;
|
||||
std::vector<stream_ptr> streams;
|
||||
std::mutex streams_mutex;
|
||||
|
||||
void watch (std::string const& path, fs::event_callback_t* cb, uint64_t eventId, CFTimeInterval latency)
|
||||
{
|
||||
stream_ptr stream(new stream_t(path, cb, eventId, latency));
|
||||
|
||||
streams_mutex.lock();
|
||||
streams.push_back(stream);
|
||||
streams_mutex.unlock();
|
||||
|
||||
ASSERT(*stream);
|
||||
if(*stream)
|
||||
@@ -142,6 +146,7 @@ namespace
|
||||
|
||||
void unwatch (std::string const& path, fs::event_callback_t* cb)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(streams_mutex);
|
||||
iterate(stream, streams)
|
||||
{
|
||||
if((*stream)->_requested.path() == path && (*stream)->_callback == cb)
|
||||
@@ -224,8 +229,6 @@ namespace
|
||||
|
||||
namespace fs
|
||||
{
|
||||
std::mutex EventsMutex;
|
||||
|
||||
static events_t& events ()
|
||||
{
|
||||
static events_t events;
|
||||
@@ -235,14 +238,12 @@ namespace fs
|
||||
void watch (std::string const& path, event_callback_t* callback, uint64_t eventId, CFTimeInterval latency)
|
||||
{
|
||||
D(DBF_FS_Events, bug("%s, %p\n", path.c_str(), callback););
|
||||
std::lock_guard<std::mutex> lock(EventsMutex);
|
||||
events().watch(path, callback, eventId, latency);
|
||||
}
|
||||
|
||||
void unwatch (std::string const& path, event_callback_t* callback)
|
||||
{
|
||||
D(DBF_FS_Events, bug("%s, %p\n", path.c_str(), callback););
|
||||
std::lock_guard<std::mutex> lock(EventsMutex);
|
||||
events().unwatch(path, callback);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user