From f220250ada50b2fcff4d99b7c3232436f3fc3c5b Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 29 Jan 2017 21:12:23 -0800 Subject: [PATCH] Adopt owning_lock in wgettext --- src/wutil.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/wutil.cpp b/src/wutil.cpp index 3d8c9145f..10122453b 100644 --- a/src/wutil.cpp +++ b/src/wutil.cpp @@ -38,12 +38,8 @@ const file_id_t kInvalidFileID = {(dev_t)-1LL, (ino_t)-1LL, (uint64_t)-1LL, -1, #endif #endif -/// Lock to protect wgettext. -static pthread_mutex_t wgettext_lock; - /// Map used as cache by wgettext. -typedef std::map wgettext_map_t; -static wgettext_map_t wgettext_map; +static owning_lock> wgettext_map; bool wreaddir_resolving(DIR *dir, const std::wstring &dir_path, std::wstring &out_name, bool *out_is_dir) { @@ -405,7 +401,6 @@ wcstring wbasename(const wcstring &path) { // Really init wgettext. static void wgettext_really_init() { - pthread_mutex_init(&wgettext_lock, NULL); fish_bindtextdomain(PACKAGE_NAME, LOCALEDIR); fish_textdomain(PACKAGE_NAME); } @@ -423,8 +418,8 @@ const wcstring &wgettext(const wchar_t *in) { wcstring key = in; wgettext_init_if_necessary(); - scoped_lock locker(wgettext_lock); - wcstring &val = wgettext_map[key]; + auto wmap = wgettext_map.acquire(); + wcstring &val = wmap.value[key]; if (val.empty()) { cstring mbs_in = wcs2string(key); char *out = fish_gettext(mbs_in.c_str());