{"id":543,"date":"2013-03-27T02:13:56","date_gmt":"2013-03-26T17:13:56","guid":{"rendered":"http:\/\/dev.activebasic.com\/egtra\/?p=543"},"modified":"2015-05-05T22:23:05","modified_gmt":"2015-05-05T13:23:05","slug":"%e3%83%9e%e3%82%a4atlccommultithreadmodel%e3%82%92%e4%bd%9c%e3%82%8b","status":"publish","type":"post","link":"https:\/\/dev.activebasic.com\/egtra\/2013\/03\/27\/543\/","title":{"rendered":"\u30de\u30a4ATL::CComMultiThreadModel\u3092\u4f5c\u308b"},"content":{"rendered":"<p><a href=\"https:\/\/msdn.microsoft.com\/ja-jp\/library\/w412ebfa(v=vs.100).aspx\">ATL::CComMultiThreadModel\u30af\u30e9\u30b9<\/a>\uff08\u30ea\u30f3\u30af\u5148\u306fMSDN\u30e9\u30a4\u30d6\u30e9\u30ea\uff09\u306e\u5b9f\u88c5\u3092\u898b\u3066\u3044\u308b\u3068\u3001\u3082\u3046\u5c11\u3057\u4eca\u6642\u3063\u307d\u3044\u611f\u3058\u306b\u3057\u305f\u3044\u306a\u3068\u601d\u3044\u307e\u3057\u305f\u3002\u3068\u3044\u3046\u308f\u3051\u3067\u3001\u3055\u304f\u3063\u3068\u66f8\u3044\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<pre lang=\"cpp\">\r\n#define _ATL_NO_AUTOMATIC_NAMESPACE\r\n\r\n#include <atlbase.h>\r\n#include <atlcom.h>\r\n#include <mutex>\r\n\r\nclass ComMultiThreadModelExNoCS\r\n{\r\npublic:\r\n  static ULONG WINAPI Increment(_Inout_ LPLONG p) throw()\r\n  {\r\n    return ::_InterlockedIncrement(p);\r\n  }\r\n  static ULONG WINAPI Decrement(_Inout_ LPLONG p) throw()\r\n  {\r\n    return ::_InterlockedDecrement(p);\r\n  }\r\n  typedef ATL::CComFakeCriticalSection AutoCriticalSection;\r\n  typedef ATL::CComFakeCriticalSection AutoDeleteCriticalSection;\r\n  typedef ATL::CComFakeCriticalSection CriticalSection;\r\n  typedef ComMultiThreadModelExNoCS ThreadModelNoCS;\r\n};\r\n\r\nclass RecursiveMutexForAtl\r\n{\r\npublic:\r\n  RecursiveMutexForAtl() {}\r\n  ~RecursiveMutexForAtl() {}\r\n\r\n  HRESULT Lock()\r\n  {\r\n    m_mutex.lock();\r\n    return S_OK;\r\n  }\r\n  HRESULT Unlock()\r\n  {\r\n    m_mutex.unlock();\r\n    return S_OK;\r\n  }\r\n\r\n  HRESULT Init() throw() { return S_OK; }\r\n  HRESULT Term() throw() { return S_OK; }\r\n\r\n  std::recursive_mutex m_mutex;\r\n};\r\n\r\nclass ComMultiThreadModelEx\r\n{\r\npublic:\r\n  static ULONG WINAPI Increment(_Inout_ long* p) throw()\r\n  {\r\n    return ::_InterlockedIncrement(p);\r\n  }\r\n  static ULONG WINAPI Decrement(_Inout_ long* p) throw()\r\n  {\r\n    return ::_InterlockedDecrement(p);\r\n  }\r\n  typedef RecursiveMutexForAtl AutoCriticalSection;\r\n  typedef RecursiveMutexForAtl AutoDeleteCriticalSection;\r\n  typedef RecursiveMutexForAtl CriticalSection;\r\n  typedef ComMultiThreadModelExNoCS ThreadModelNoCS;\r\n};\r\n<\/pre>\n<p>\u7279\u5fb4\u306f2\u3064\u3067\u3059\u3002<\/p>\n<ul>\n<li>\u30a4\u30f3\u30af\u30ea\u30e1\u30f3\u30c8\u30fb\u30c7\u30af\u30ea\u30e1\u30f3\u30c8\u3092\u30b3\u30f3\u30d1\u30a4\u30e9\u7d44\u307f\u8fbc\u307f\u7248\u306b\u3057\u305f\u3002<\/li>\n<li>\u30af\u30ea\u30c6\u30a3\u30ab\u30eb\u30bb\u30af\u30b7\u30e7\u30f3\u306e\u4ee3\u308f\u308a\u306b\u3001std::recursive_mutex\u3092\u63a1\u7528\u3057\u3066\u307f\u305f\u3002<\/li>\n<\/ul>\n<p>Windows\u306e\u30af\u30ea\u30c6\u30a3\u30ab\u30eb\u30bb\u30af\u30b7\u30e7\u30f3\u306f\u518d\u5165OK\u306a\u306e\u3067\u3001\u305d\u308c\u306b\u3042\u308f\u305b\u3066recursive_mutex\u3092\u9078\u3073\u307e\u3057\u305f\u3002std::mutex\u3084VC++\u306eConcurrency Runtime\u306e<a href=\"https:\/\/msdn.microsoft.com\/ja-jp\/library\/vstudio\/dd492843(v=vs.100).aspx\">critical_section\u30af\u30e9\u30b9<\/a>\u306a\u3069\u3082\u3044\u3044\u3067\u3059\u306d\u3002\u3042\u308b\u3044\u306f\u3001Windows\u306eCRITICAL_SECTION\u3092\u4f7f\u3046\u3051\u3069\u3001<a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/ms683476.aspx\">InitializeCriticalSectionAndSpinCount\u95a2\u6570<\/a>\u3092\u547c\u3073\u51fa\u3059\u3088\u3046\u306b\u3057\u3066\u3001\u30b9\u30d4\u30f3\u30ed\u30c3\u30af\u306e\u5024\u3092\u6307\u5b9a\u3059\u308b\u3068\u3044\u3046\u6539\u826f\u3082\u8003\u3048\u3089\u308c\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ATL::CComMultiThreadModel\u306e\u6539\u826f\u7248\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[5,12],"tags":[142],"class_list":["post-543","post","type-post","status-publish","format-standard","hentry","category-cpp","category-vc","tag-atl"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u30de\u30a4ATL::CComMultiThreadModel\u3092\u4f5c\u308b - \u30a4\u30b0\u30c8\u30e9\u30f3\u30b9\u306e\u982d\u306e\u4e2d<\/title>\n<meta name=\"description\" content=\"ATL::CComMultiThreadModel\u306e\u6539\u826f\u7248\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/dev.activebasic.com\/egtra\/2013\/03\/27\/543\/\" \/>\n<meta property=\"og:locale\" content=\"ja_JP\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u30de\u30a4ATL::CComMultiThreadModel\u3092\u4f5c\u308b - \u30a4\u30b0\u30c8\u30e9\u30f3\u30b9\u306e\u982d\u306e\u4e2d\" \/>\n<meta property=\"og:description\" content=\"ATL::CComMultiThreadModel\u306e\u6539\u826f\u7248\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/dev.activebasic.com\/egtra\/2013\/03\/27\/543\/\" \/>\n<meta property=\"og:site_name\" content=\"\u30a4\u30b0\u30c8\u30e9\u30f3\u30b9\u306e\u982d\u306e\u4e2d\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ysk.noh\" \/>\n<meta property=\"article:published_time\" content=\"2013-03-26T17:13:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2015-05-05T13:23:05+00:00\" \/>\n<meta name=\"author\" content=\"egtra\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@egtra\" \/>\n<meta name=\"twitter:site\" content=\"@egtra\" \/>\n<meta name=\"twitter:label1\" content=\"\u57f7\u7b46\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"egtra\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u63a8\u5b9a\u8aad\u307f\u53d6\u308a\u6642\u9593\" \/>\n\t<meta name=\"twitter:data2\" content=\"1\u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/dev.activebasic.com\/egtra\/2013\/03\/27\/543\/\",\"url\":\"https:\/\/dev.activebasic.com\/egtra\/2013\/03\/27\/543\/\",\"name\":\"\u30de\u30a4ATL::CComMultiThreadModel\u3092\u4f5c\u308b - \u30a4\u30b0\u30c8\u30e9\u30f3\u30b9\u306e\u982d\u306e\u4e2d\",\"isPartOf\":{\"@id\":\"https:\/\/dev.activebasic.com\/egtra\/#website\"},\"datePublished\":\"2013-03-26T17:13:56+00:00\",\"dateModified\":\"2015-05-05T13:23:05+00:00\",\"author\":{\"@id\":\"https:\/\/dev.activebasic.com\/egtra\/#\/schema\/person\/8de756b2ff20b964f64594dfe8f18164\"},\"description\":\"ATL::CComMultiThreadModel\u306e\u6539\u826f\u7248\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002\",\"breadcrumb\":{\"@id\":\"https:\/\/dev.activebasic.com\/egtra\/2013\/03\/27\/543\/#breadcrumb\"},\"inLanguage\":\"ja\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/dev.activebasic.com\/egtra\/2013\/03\/27\/543\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/dev.activebasic.com\/egtra\/2013\/03\/27\/543\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u30db\u30fc\u30e0\",\"item\":\"https:\/\/dev.activebasic.com\/egtra\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u30de\u30a4ATL::CComMultiThreadModel\u3092\u4f5c\u308b\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/dev.activebasic.com\/egtra\/#website\",\"url\":\"https:\/\/dev.activebasic.com\/egtra\/\",\"name\":\"\u30a4\u30b0\u30c8\u30e9\u30f3\u30b9\u306e\u982d\u306e\u4e2d\",\"description\":\"\u982d\u306e\u4e2d\u306e\u304b\u3051\u3089\u3002ActiveBasic\u3092\u4e2d\u5fc3\u306b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u8a71\u3092\u307c\u3061\u307c\u3061\u3068\u3002\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/dev.activebasic.com\/egtra\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"ja\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/dev.activebasic.com\/egtra\/#\/schema\/person\/8de756b2ff20b964f64594dfe8f18164\",\"name\":\"egtra\",\"sameAs\":[\"https:\/\/x.com\/egtra\"],\"url\":\"https:\/\/dev.activebasic.com\/egtra\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u30de\u30a4ATL::CComMultiThreadModel\u3092\u4f5c\u308b - \u30a4\u30b0\u30c8\u30e9\u30f3\u30b9\u306e\u982d\u306e\u4e2d","description":"ATL::CComMultiThreadModel\u306e\u6539\u826f\u7248\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/dev.activebasic.com\/egtra\/2013\/03\/27\/543\/","og_locale":"ja_JP","og_type":"article","og_title":"\u30de\u30a4ATL::CComMultiThreadModel\u3092\u4f5c\u308b - \u30a4\u30b0\u30c8\u30e9\u30f3\u30b9\u306e\u982d\u306e\u4e2d","og_description":"ATL::CComMultiThreadModel\u306e\u6539\u826f\u7248\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002","og_url":"https:\/\/dev.activebasic.com\/egtra\/2013\/03\/27\/543\/","og_site_name":"\u30a4\u30b0\u30c8\u30e9\u30f3\u30b9\u306e\u982d\u306e\u4e2d","article_publisher":"https:\/\/www.facebook.com\/ysk.noh","article_published_time":"2013-03-26T17:13:56+00:00","article_modified_time":"2015-05-05T13:23:05+00:00","author":"egtra","twitter_card":"summary_large_image","twitter_creator":"@egtra","twitter_site":"@egtra","twitter_misc":{"\u57f7\u7b46\u8005":"egtra","\u63a8\u5b9a\u8aad\u307f\u53d6\u308a\u6642\u9593":"1\u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/dev.activebasic.com\/egtra\/2013\/03\/27\/543\/","url":"https:\/\/dev.activebasic.com\/egtra\/2013\/03\/27\/543\/","name":"\u30de\u30a4ATL::CComMultiThreadModel\u3092\u4f5c\u308b - \u30a4\u30b0\u30c8\u30e9\u30f3\u30b9\u306e\u982d\u306e\u4e2d","isPartOf":{"@id":"https:\/\/dev.activebasic.com\/egtra\/#website"},"datePublished":"2013-03-26T17:13:56+00:00","dateModified":"2015-05-05T13:23:05+00:00","author":{"@id":"https:\/\/dev.activebasic.com\/egtra\/#\/schema\/person\/8de756b2ff20b964f64594dfe8f18164"},"description":"ATL::CComMultiThreadModel\u306e\u6539\u826f\u7248\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002","breadcrumb":{"@id":"https:\/\/dev.activebasic.com\/egtra\/2013\/03\/27\/543\/#breadcrumb"},"inLanguage":"ja","potentialAction":[{"@type":"ReadAction","target":["https:\/\/dev.activebasic.com\/egtra\/2013\/03\/27\/543\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/dev.activebasic.com\/egtra\/2013\/03\/27\/543\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u30db\u30fc\u30e0","item":"https:\/\/dev.activebasic.com\/egtra\/"},{"@type":"ListItem","position":2,"name":"\u30de\u30a4ATL::CComMultiThreadModel\u3092\u4f5c\u308b"}]},{"@type":"WebSite","@id":"https:\/\/dev.activebasic.com\/egtra\/#website","url":"https:\/\/dev.activebasic.com\/egtra\/","name":"\u30a4\u30b0\u30c8\u30e9\u30f3\u30b9\u306e\u982d\u306e\u4e2d","description":"\u982d\u306e\u4e2d\u306e\u304b\u3051\u3089\u3002ActiveBasic\u3092\u4e2d\u5fc3\u306b\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u8a71\u3092\u307c\u3061\u307c\u3061\u3068\u3002","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/dev.activebasic.com\/egtra\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"ja"},{"@type":"Person","@id":"https:\/\/dev.activebasic.com\/egtra\/#\/schema\/person\/8de756b2ff20b964f64594dfe8f18164","name":"egtra","sameAs":["https:\/\/x.com\/egtra"],"url":"https:\/\/dev.activebasic.com\/egtra\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/dev.activebasic.com\/egtra\/wp-json\/wp\/v2\/posts\/543"}],"collection":[{"href":"https:\/\/dev.activebasic.com\/egtra\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.activebasic.com\/egtra\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.activebasic.com\/egtra\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.activebasic.com\/egtra\/wp-json\/wp\/v2\/comments?post=543"}],"version-history":[{"count":0,"href":"https:\/\/dev.activebasic.com\/egtra\/wp-json\/wp\/v2\/posts\/543\/revisions"}],"wp:attachment":[{"href":"https:\/\/dev.activebasic.com\/egtra\/wp-json\/wp\/v2\/media?parent=543"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.activebasic.com\/egtra\/wp-json\/wp\/v2\/categories?post=543"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.activebasic.com\/egtra\/wp-json\/wp\/v2\/tags?post=543"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}