{"action":"created","issue":{"url":"https://api.github.com/repos/polotek/libxmljs/issues/300","labels_url":"https://api.github.com/repos/polotek/libxmljs/issues/300/labels{/name}","comments_url":"https://api.github.com/repos/polotek/libxmljs/issues/300/comments","events_url":"https://api.github.com/repos/polotek/libxmljs/issues/300/events","html_url":"https://github.com/polotek/libxmljs/pull/300","id":66867682,"number":300,"title":"Implement thread-local memory adjustments","user":{"login":"gagern","id":190759,"avatar_url":"https://avatars.githubusercontent.com/u/190759?v=3","gravatar_id":"","url":"https://api.github.com/users/gagern","html_url":"https://github.com/gagern","followers_url":"https://api.github.com/users/gagern/followers","following_url":"https://api.github.com/users/gagern/following{/other_user}","gists_url":"https://api.github.com/users/gagern/gists{/gist_id}","starred_url":"https://api.github.com/users/gagern/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gagern/subscriptions","organizations_url":"https://api.github.com/users/gagern/orgs","repos_url":"https://api.github.com/users/gagern/repos","events_url":"https://api.github.com/users/gagern/events{/privacy}","received_events_url":"https://api.github.com/users/gagern/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-04-07T12:06:33Z","updated_at":"2015-04-07T13:18:23Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/polotek/libxmljs/pulls/300","html_url":"https://github.com/polotek/libxmljs/pull/300","diff_url":"https://github.com/polotek/libxmljs/pull/300.diff","patch_url":"https://github.com/polotek/libxmljs/pull/300.patch"},"body":"If the current thread is not the main V8 event thread, we don't report memory adjustments back to V8 immediately, but instead keep track of all the changes in a thread-local variable.  The net change will be reported back after the worker is done.\r\n\r\nAll state changes are encapsulated in two RAII sentinels: WorkerParent and WorkerSentinel.  The former is constructed and destroyed on the V8 thread, the latter on the worker thread.  Having these in place helps to make client code thread-safe with respect to the state in question.  It also provides a convenient extension point: if, at some point, we need more code for handling worker threads, all we have to do is extend these two classes.\r\n\r\nThe current delegation to the libxml2 memory management functions has ben completely dropped.  The main use case for these would have been memory debugging, so they do a lot of work (like maintaining linked lists between allocated blocks) that we don't need.  The main thing we could have gained from them, namely the call to xmlMemUsed, was not thread-safe in any case.\r\n\r\nWith [these adjustments](https://github.com/albanm/node-libxslt/compare/master...gagern:threadLocalMemAdjust), node-libxslt works with this code here."},"comment":{"url":"https://api.github.com/repos/polotek/libxmljs/issues/comments/90547849","html_url":"https://github.com/polotek/libxmljs/pull/300#issuecomment-90547849","issue_url":"https://api.github.com/repos/polotek/libxmljs/issues/300","id":90547849,"user":{"login":"gagern","id":190759,"avatar_url":"https://avatars.githubusercontent.com/u/190759?v=3","gravatar_id":"","url":"https://api.github.com/users/gagern","html_url":"https://github.com/gagern","followers_url":"https://api.github.com/users/gagern/followers","following_url":"https://api.github.com/users/gagern/following{/other_user}","gists_url":"https://api.github.com/users/gagern/gists{/gist_id}","starred_url":"https://api.github.com/users/gagern/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gagern/subscriptions","organizations_url":"https://api.github.com/users/gagern/orgs","repos_url":"https://api.github.com/users/gagern/repos","events_url":"https://api.github.com/users/gagern/events{/privacy}","received_events_url":"https://api.github.com/users/gagern/received_events","type":"User","site_admin":false},"created_at":"2015-04-07T13:18:23Z","updated_at":"2015-04-07T13:18:23Z","body":"OK, Travis is still complaining, but now only for ancient Node 0.8, and I don't see my code being responsible for this. Are you willing to merge my approach?"}}