summaryrefslogtreecommitdiff
path: root/lib/pthreadpool/pthreadpool_tevent.c
AgeCommit message (Collapse)AuthorFilesLines
2026-01-18lib/pthreadpool: protect jobs list from concurrent thread accessNoel Power1-0/+40
ThreadSanitizer identifies a data race with pool->jobs with concurrent threads in test added in previous commit. This commit protects the pool->jobs list (trace and line numbers are from before glue fix in previous commit) WARNING: ThreadSanitizer: data race (pid=13574) Write of size 8 at 0x7b6000020260 by thread T16: #0 pthreadpool_tevent_job_done ../../lib/pthreadpool/pthreadpool_tevent.c:405 (pthreadpool_tevent_unit_test_san+0x407080) #1 tevent_common_invoke_immediate_handler ../../lib/tevent/tevent_immediate.c:190 (libtevent-private-samba.so+0x8dbf) #2 pthreadpool_tevent_job_fn ../../lib/pthreadpool/pthreadpool_tevent.c:351 (pthreadpool_tevent_unit_test_san+0x406bc4) #3 pthreadpool_server ../../lib/pthreadpool/pthreadpool.c:655 (pthreadpool_tevent_unit_test_san+0x4043bd) #4 <null> <null> (libtsan.so.0+0x323cf) Previous write of size 8 at 0x7b6000020260 by thread T13: #0 pthreadpool_tevent_job_send ../../lib/pthreadpool/pthreadpool_tevent.c:342 (pthreadpool_tevent_unit_test_san+0x406a09) #1 do_nested_pthread_job ../../lib/pthreadpool/test_pthreadpool_tevent.c:463 (pthreadpool_tevent_unit_test_san+0x408932) #2 pthreadpool_tevent_job_fn ../../lib/pthreadpool/pthreadpool_tevent.c:351 (pthreadpool_tevent_unit_test_san+0x406bc4) #3 pthreadpool_server ../../lib/pthreadpool/pthreadpool.c:655 (pthreadpool_tevent_unit_test_san+0x4043bd) #4 <null> <null> (libtsan.so.0+0x323cf) Thread T16 (tid=13591, running) created by main thread at: #0 pthread_create <null> (libtsan.so.0+0x5ed75) #1 pthreadpool_create_thread ../../lib/pthreadpool/pthreadpool.c:711 (pthreadpool_tevent_unit_test_san+0x4045ac) #2 pthreadpool_add_job ../../lib/pthreadpool/pthreadpool.c:792 (pthreadpool_tevent_unit_test_san+0x40496f) #3 pthreadpool_tevent_job_send ../../lib/pthreadpool/pthreadpool_tevent.c:329 (pthreadpool_tevent_unit_test_san+0x4065e2) #4 test_pthreadpool_tevent_job_send_multiple_3 ../../lib/pthreadpool/test_pthreadpool_tevent.c:515 (pthreadpool_tevent_unit_test_san+0x408c25) #5 cmocka_run_one_test_or_fixture ../../third_party/cmocka/cmocka.c:2948 (libcmocka-private-samba.so+0x6f92) #6 __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 (libc.so.6+0x40e6b) Thread T13 (tid=13588, running) created by main thread at: #0 pthread_create <null> (libtsan.so.0+0x5ed75) #1 pthreadpool_create_thread ../../lib/pthreadpool/pthreadpool.c:711 (pthreadpool_tevent_unit_test_san+0x4045ac) #2 pthreadpool_add_job ../../lib/pthreadpool/pthreadpool.c:792 (pthreadpool_tevent_unit_test_san+0x40496f) #3 pthreadpool_tevent_job_send ../../lib/pthreadpool/pthreadpool_tevent.c:329 (pthreadpool_tevent_unit_test_san+0x4065e2) #4 test_pthreadpool_tevent_job_send_multiple_3 ../../lib/pthreadpool/test_pthreadpool_tevent.c:515 (pthreadpool_tevent_unit_test_san+0x408c25) #5 cmocka_run_one_test_or_fixture ../../third_party/cmocka/cmocka.c:2948 (libcmocka-private-samba.so+0x6f92) #6 __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 (libc.so.6+0x40e6b) SUMMARY: ThreadSanitizer: data race ../../lib/pthreadpool/pthreadpool_tevent.c:405 in pthreadpool_tevent_job_done BUG: https://bugzilla.samba.org/show_bug.cgi?id=15958 Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Stefan Metzmacher <metze@samba.org> Autobuild-User(master): Stefan Metzmacher <metze@samba.org> Autobuild-Date(master): Sun Jan 18 15:16:59 UTC 2026 on atb-devel-224
2026-01-18lib/pthreadpool: Fix possible concurrent access to pool->glue_listNoel Power1-1/+79
ThreadSanitizer run against tests added in previous commit identify a race condition with pool->glue_list with concurrent thread access WARNING: ThreadSanitizer: data race (pid=13574) Read of size 8 at 0x7b2000000368 by thread T7: #0 pthreadpool_tevent_job_signal ../../lib/pthreadpool/pthreadpool_tevent.c:370 (pthreadpool_tevent_unit_test_san+0x406c6e) #1 pthreadpool_server ../../lib/pthreadpool/pthreadpool.c:657 (pthreadpool_tevent_unit_test_san+0x40443b) #2 <null> <null> (libtsan.so.0+0x323cf) Previous write of size 8 at 0x7b2000000368 by main thread: #0 pthreadpool_tevent_glue_destructor ../../lib/pthreadpool/pthreadpool_tevent.c:165 (pthreadpool_tevent_unit_test_san+0x405aed) #1 _tc_free_internal ../../lib/talloc/talloc.c:1158 (libtalloc-private-samba.so+0x3419) #2 _tc_free_internal ../../lib/talloc/talloc.c:1158 (libtalloc-private-samba.so+0x3419) #3 cmocka_run_one_test_or_fixture ../../third_party/cmocka/cmocka.c:2948 (libcmocka-private-samba.so+0x6f92) #4 __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 (libc.so.6+0x40e6b) Location is heap block of size 120 at 0x7b2000000300 allocated by main thread: #0 malloc <null> (libtsan.so.0+0x35799) #1 __talloc_with_prefix ../../lib/talloc/talloc.c:783 (libtalloc-private-samba.so+0x2a99) #2 test_pthreadpool_tevent_job_send_multiple_2 ../../lib/pthreadpool/test_pthreadpool_tevent.c:399 (pthreadpool_tevent_unit_test_san+0x40856f) #3 cmocka_run_one_test_or_fixture ../../third_party/cmocka/cmocka.c:2948 (libcmocka-private-samba.so+0x6f92) #4 __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 (libc.so.6+0x40e6b) Thread T7 (tid=13582, running) created by main thread at: #0 pthread_create <null> (libtsan.so.0+0x5ed75) #1 pthreadpool_create_thread ../../lib/pthreadpool/pthreadpool.c:711 (pthreadpool_tevent_unit_test_san+0x4045ac) #2 pthreadpool_add_job ../../lib/pthreadpool/pthreadpool.c:792 (pthreadpool_tevent_unit_test_san+0x40496f) #3 pthreadpool_tevent_job_send ../../lib/pthreadpool/pthreadpool_tevent.c:329 (pthreadpool_tevent_unit_test_san+0x4065e2) #4 test_pthreadpool_tevent_job_send_multiple_2 ../../lib/pthreadpool/test_pthreadpool_tevent.c:423 (pthreadpool_tevent_unit_test_san+0x4086b2) #5 cmocka_run_one_test_or_fixture ../../third_party/cmocka/cmocka.c:2948 (libcmocka-private-samba.so+0x6f92) #6 __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 (libc.so.6+0x40e6b) SUMMARY: ThreadSanitizer: data race ../../lib/pthreadpool/pthreadpool_tevent.c:370 in pthreadpool_tevent_job_signal BUG: https://bugzilla.samba.org/show_bug.cgi?id=15958 Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2026-01-18lib/pthreadpool: fix free of already freed glue objectNoel Power1-1/+0
The lines are a bit skewed from actual sources (due to temp debug lines) but I have inserted the relevant source code below basically if we free ev_link then this will free the glue object, so deleting the glue object on the next line is not what we want to do. ==14263== Invalid read of size 4 ==14263== at 0x4D13E90: talloc_chunk_from_ptr (talloc.c:527) ==14263== by 0x4D1621E: _talloc_free (talloc.c:1770) 249 #ifdef HAVE_PTHREAD 250 glue->tctx = tevent_threaded_context_create(glue, ev); 251 if (glue->tctx == NULL) { 252 TALLOC_FREE(ev_link); * 253 TALLOC_FREE(glue); 254 return ENOMEM; 250 } ==14263== by 0x51FA0AF: pthreadpool_tevent_register_ev (pthreadpool_tevent.c:253) ==14263== by 0x51FA302: pthreadpool_tevent_job_send (pthreadpool_tevent.c:324) ==14263== by 0x4B01E68: vfswrap_fsync_send (vfs_default.c:1104) ==14263== by 0x49CD9B1: smb_vfs_call_fsync_send (vfs.c:1998) ==14263== by 0x49CDBF9: smb_vfs_fsync_sync (vfs.c:2057) ==14263== by 0x494B1E5: sync_file (fileio.c:320) ==14263== by 0x497CC77: reply_flush (reply.c:5398) ==14263== by 0x49E28CB: switch_message (process.c:1726) ==14263== by 0x49E2AA4: construct_reply (process.c:1762) ==14263== by 0x49E37F8: process_smb (process.c:2017) ==14263== Address 0xcb415d0 is 0 bytes inside a block of size 144 free'd ==14263== at 0x484494B: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==14263== by 0x4D14F81: _tc_free_internal (talloc.c:1222) ==14263== by 0x4D15025: _talloc_free_internal (talloc.c:1248) ==14263== by 0x4D162ED: _talloc_free (talloc.c:1792) 190 static int pthreadpool_tevent_glue_link_destructor( 191 struct pthreadpool_tevent_glue_ev_link *ev_link) 192 { * 193 TALLOC_FREE(ev_link->glue); 194 return 0; 195 } ==14263== by 0x51F9EC3: pthreadpool_tevent_glue_link_destructor (pthreadpool_tevent.c:193) ==14263== by 0x4D14CA9: _tc_free_internal (talloc.c:1158) ==14263== by 0x4D15025: _talloc_free_internal (talloc.c:1248) ==14263== by 0x4D162ED: _talloc_free (talloc.c:1792) 249 #ifdef HAVE_PTHREAD 250 glue->tctx = tevent_threaded_context_create(glue, ev); 251 if (glue->tctx == NULL) { * 252 TALLOC_FREE(ev_link); 253 TALLOC_FREE(glue); 254 return ENOMEM; 250 } ==14263== by 0x51FA08D: pthreadpool_tevent_register_ev (pthreadpool_tevent.c:252) ==14263== by 0x51FA302: pthreadpool_tevent_job_send (pthreadpool_tevent.c:324) ==14263== by 0x4B01E68: vfswrap_fsync_send (vfs_default.c:1104) ==14263== by 0x49CD9B1: smb_vfs_call_fsync_send (vfs.c:1998) ==14263== Block was alloc'd at ==14263== at 0x4841984: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==14263== by 0x4D14339: __talloc_with_prefix (talloc.c:783) ==14263== by 0x4D144D3: __talloc (talloc.c:825) ==14263== by 0x4D1486C: _talloc_named_const (talloc.c:982) ==14263== by 0x4D1734D: _talloc_zero (talloc.c:2421) ==14263== by 0x51F9F46: pthreadpool_tevent_register_ev (pthreadpool_tevent.c:222) ==14263== by 0x51FA302: pthreadpool_tevent_job_send (pthreadpool_tevent.c:324) ==14263== by 0x4B01E68: vfswrap_fsync_send (vfs_default.c:1104) ==14263== by 0x49CD9B1: smb_vfs_call_fsync_send (vfs.c:1998) ==14263== by 0x49CDBF9: smb_vfs_fsync_sync (vfs.c:2057) ==14263== by 0x494B1E5: sync_file (fileio.c:320) ==14263== by 0x497CC77: reply_flush (reply.c:5398) ==14263== ==14263== Invalid read of size 4 ==14263== at 0x4D13EAE: talloc_chunk_from_ptr (talloc.c:528) ==14263== by 0x4D1621E: _talloc_free (talloc.c:1770) ==14263== by 0x51FA0AF: pthreadpool_tevent_register_ev (pthreadpool_tevent.c:253) ==14263== by 0x51FA302: pthreadpool_tevent_job_send (pthreadpool_tevent.c:324) ==14263== by 0x4B01E68: vfswrap_fsync_send (vfs_default.c:1104) ==14263== by 0x49CD9B1: smb_vfs_call_fsync_send (vfs.c:1998) ==14263== by 0x49CDBF9: smb_vfs_fsync_sync (vfs.c:2057) ==14263== by 0x494B1E5: sync_file (fileio.c:320) ==14263== by 0x497CC77: reply_flush (reply.c:5398) ==14263== by 0x49E28CB: switch_message (process.c:1726) ==14263== by 0x49E2AA4: construct_reply (process.c:1762) ==14263== by 0x49E37F8: process_smb (process.c:2017) ==14263== Address 0xcb415d0 is 0 bytes inside a block of size 144 free'd ==14263== at 0x484494B: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-l BUG: https://bugzilla.samba.org/show_bug.cgi?id=15957 Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2023-04-11lib:pthreadpool: Fix code spellingAndreas Schneider1-1/+1
Best reviewed with: `git show --word-diff`. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2019-01-11Revert "pthreadpool: split out pthreadpool_tevent_job from ↵Ralph Boehme1-172/+66
pthreadpool_tevent_job_state" This reverts commit 245d684d28dab630f3d47ff61006a1fe3e5eeefa. See the discussion in https://lists.samba.org/archive/samba-technical/2018-December/131731.html for the reasoning behind this revert. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-01-11Revert "pthreadpool: add pthreadpool_tevent_job_cancel()"Ralph Boehme1-40/+0
This reverts commit 791c05144ee9296024cc0fdebe4afeaaf67e26bc. See the discussion in https://lists.samba.org/archive/samba-technical/2018-December/131731.html for the reasoning behind this revert. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-01-11Revert "pthreadpool: maintain a global list of orphaned pthreadpool_tevent_jobs"Ralph Boehme1-41/+0
This reverts commit 25756425aaf5465e56ea809cd415b6a387848919. See the discussion in https://lists.samba.org/archive/samba-technical/2018-December/131731.html for the reasoning behind this revert. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-01-11Revert "pthreadpool: add some lockless coordination between the main and job ↵Ralph Boehme1-207/+5
threads" This reverts commit 9656b8d8ee11ee351870286f16ea8fbe49112292. See the discussion in https://lists.samba.org/archive/samba-technical/2018-December/131731.html for the reasoning behind this revert. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-01-11Revert "pthreadpool: add helgrind magic to PTHREAD_TEVENT_JOB_THREAD_FENCE_*()"Ralph Boehme1-34/+0
This reverts commit 9b73fda926eb8493e80012794483039be66d4e6c. See the discussion in https://lists.samba.org/archive/samba-technical/2018-December/131731.html for the reasoning behind this revert. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-01-11Revert "pthreadpool: maintain a list of job_states on each ↵Ralph Boehme1-78/+24
pthreadpool_tevent_glue" This reverts commit aa9b64eccfd037941512bad108c4e3946714a502. See the discussion in https://lists.samba.org/archive/samba-technical/2018-December/131731.html for the reasoning behind this revert. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-01-11Revert "pthreadpool: add a comment about a further optimization in ↵Ralph Boehme1-17/+0
pthreadpool_tevent_job_destructor()" This reverts commit f23cac39b36b026650e0922c78fe0fd3fe567e35. See the discussion in https://lists.samba.org/archive/samba-technical/2018-December/131731.html for the reasoning behind this revert. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-01-11Revert "pthreadpool: add pthreadpool_tevent_[current_job_]per_thread_cwd()"Ralph Boehme1-26/+0
This reverts commit 12a45ee1a66379ba7562729b835ce0e2e4bfb3b3. See the discussion in https://lists.samba.org/archive/samba-technical/2018-December/131731.html for the reasoning behind this revert. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-01-11Revert "pthreadpool: implement pthreadpool_tevent_wrapper_create() ↵Ralph Boehme1-401/+1
infrastructure" This reverts commit f9745d8b5234091c38e93ed57a255120b61f3ad7. See the discussion in https://lists.samba.org/archive/samba-technical/2018-December/131731.html for the reasoning behind this revert. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-01-11Revert "pthreadpool: we need to use pthreadpool_tevent_per_thread_cwd() on ↵Ralph Boehme1-2/+1
the callers pool" This reverts commit ff863f2d98ac5e12073af824b794404c3d7198c5. See the discussion in https://lists.samba.org/archive/samba-technical/2018-December/131731.html for the reasoning behind this revert. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-01-11Revert "pthreadpool: ignore the return value of poll(NULL, 0UL, 1)"Ralph Boehme1-2/+2
This reverts commit 6da0d68f49bbd82f5a08427779c9f5ebd6f755aa. See the discussion in https://lists.samba.org/archive/samba-technical/2018-December/131731.html for the reasoning behind this revert. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2019-01-11Revert "pthreadpool: reset monitor_fd after calling tevent_fd_set_auto_close()"Ralph Boehme1-1/+0
This reverts commit f68b5ee75f002ed542a8423070fb01e3b0e83f65. See the discussion in https://lists.samba.org/archive/samba-technical/2018-December/131731.html for the reasoning behind this revert. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2018-07-31pthreadpool: reset monitor_fd after calling tevent_fd_set_auto_close()Stefan Metzmacher1-0/+1
This tries to convince Coverity that we don't have a resource leak: CID 1438157: (RESOURCE_LEAK) Handle variable "monitor_fd" going out of scope leaks the handle. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
2018-07-31pthreadpool: ignore the return value of poll(NULL, 0UL, 1)Stefan Metzmacher1-2/+2
Otherwise Coverity reports this: CID 1438160: (CHECKED_RETURN) Calling "poll(NULL, 0UL, 1)" without checking return value. This library function may fail and return an error code. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
2018-07-27pthreadpool: we need to use pthreadpool_tevent_per_thread_cwd() on the ↵Stefan Metzmacher1-1/+2
callers pool In pthreadpool_tevent_job_send() we remember if the job will be chdir safe. It means we means we need to ask the callers pool when calling pthreadpool_tevent_per_thread_cwd(), as the callers pool might be a wrapper using pthreadpool_tevent_force_per_thread_cwd(). Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-25pthreadpool: add a missing includeRalph Boehme1-0/+1
Reported-by: David Disseldorp <ddiss@samba.org> Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: David Disseldorp <ddiss@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2018-07-24pthreadpool: implement pthreadpool_tevent_wrapper_create() infrastructureStefan Metzmacher1-1/+401
This can be used implement a generic per thread impersonation for thread pools. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-24pthreadpool: add pthreadpool_tevent_[current_job_]per_thread_cwd()Stefan Metzmacher1-0/+26
This can be used to check if worker threads run with unshare(CLONE_FS). Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-24pthreadpool: add a comment about a further optimization in ↵Stefan Metzmacher1-0/+17
pthreadpool_tevent_job_destructor() This seems to be a really rare race, it's likely that the immediate event will still trigger and cleanup. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-24pthreadpool: maintain a list of job_states on each pthreadpool_tevent_glueStefan Metzmacher1-24/+78
We should avoid traversing a linked list within a thread without holding a mutex! Using a mutex would be very tricky as we'll likely deadlock with the mutexes at the raw pthreadpool layer. So we use somekind of spinlock using atomic_thread_fence in order to protect the access to job->state->glue->{tctx,ev} in pthreadpool_tevent_job_signal(). Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-24pthreadpool: add helgrind magic to PTHREAD_TEVENT_JOB_THREAD_FENCE_*()Stefan Metzmacher1-0/+34
This avoids the expected helgrind/drd warnings on the job states which are protected by the thread fence. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-24pthreadpool: add some lockless coordination between the main and job threadsStefan Metzmacher1-5/+207
In the direction from the main process to the job thread, we have: - 'maycancel', which is set when tevent_req_cancel() is called, - 'orphaned' is the job request, tevent_context or pthreadpool_tevent was talloc_free'ed. The job function can consume these by using: /* * return true - if tevent_req_cancel() was called. */ bool pthreadpool_tevent_current_job_canceled(void); /* * return true - if talloc_free() was called on the job request, * tevent_context or pthreadpool_tevent. */ bool pthreadpool_tevent_current_job_orphaned(void); /* * return true if canceled and orphaned are both false. */ bool pthreadpool_tevent_current_job_continue(void); In the other direction we remember the following points in the job execution: - 'started' - set when the job is picked up by a worker thread - 'executed' - set once the job function returned. - 'finished' - set when pthreadpool_tevent_job_signal() is entered - 'dropped' - set when pthreadpool_tevent_job_signal() leaves with orphaned - 'signaled' - set when pthreadpool_tevent_job_signal() leaves normal There're only one side writing each element, either the main process or the job thread. This means we can do the coordination with a full memory barrier using atomic_thread_fence(memory_order_seq_cst). lib/replace provides fallbacks if C11 stdatomic.h is not available. A real pthreadpool requires pthread and atomic_thread_fence() (or an replacement) to be available, otherwise we only have pthreadpool_sync.c. But this should not make a real difference, as at least __sync_synchronize() is availabe since 2005 in gcc. We also require __thread which is available since 2002. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-12pthreadpool: allocate glue->tctx on glue as memory context.Stefan Metzmacher1-1/+1
This means it will go aways together with glue and thte event context. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org> Autobuild-User(master): Stefan Metzmacher <metze@samba.org> Autobuild-Date(master): Thu Jul 12 17:18:01 CEST 2018 on sn-devel-144
2018-07-12pthreadpool: maintain a global list of orphaned pthreadpool_tevent_jobsStefan Metzmacher1-0/+41
Instead of leaking the memory forever, we retry the cleanup, if other pthreadpool_tevent_*() functions are used. pthreadpool_tevent_cleanup_orphaned_jobs() could also be called by external callers. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-12pthreadpool: make use of pthreadpool_stop() in pthreadpool_tevent_destructor()Stefan Metzmacher1-2/+7
Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-12pthreadpool: add pthreadpool_tevent_job_cancel()Stefan Metzmacher1-0/+40
Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-12pthreadpool: split out pthreadpool_tevent_job from pthreadpool_tevent_job_stateStefan Metzmacher1-66/+172
This makes it much easier to handle orphaned jobs, we either wait for the immediate tevent to trigger or we just keep leaking the memory. The next commits will improve this further. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-12pthreadpool: let pthreadpool_tevent_job_send() fail with an invalid poolStefan Metzmacher1-0/+9
Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-12pthreadpool: add pthreadpool_tevent_max_threads() and ↵Stefan Metzmacher1-0/+18
pthreadpool_tevent_queued_jobs() These can be used to implement some kind of flow control in the caller. E.g. unless pthreadpool_tevent_queued_jobs() is lower than pthreadpool_tevent_max_threads() is good to prepare new jobs. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2018-07-12pthreadpool: correctly handle pthreadpool_tevent_register_ev() failuresStefan Metzmacher1-2/+1
It returns errno values instead of setting 'errno'. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2017-11-17pthreadpool: create a tevent_threaded_context per registered event contextRalph Boehme1-17/+167
We just need one tevent_threaded_context per unique combintation of tevent event contexts and pthreadpool_tevent pools, not multiple copies for identical combinations of a tevent contexts and a pthreadpool_tevent pools. With this commit we register tevent contexts in a list in the pthreadpool_tevent structure and will only have one tevent_threaded_context object per tevent context per pool. With many pthreadpool_tevent_job_send reqs this pays off, I've seen a small decrease in cpu-ticks with valgrind callgrind and a modified local.messaging.ping-speed torture test. The test modification ensured messages we never directly send, but always submitted via pthreadpool_tevent_job_send. Pair-Programmed-With: Jeremy Allison <jra@samba.org> Signed-off-by: Ralph Boehme <slow@samba.org> Signed-off-by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Ralph Böhme <slow@samba.org> Autobuild-Date(master): Fri Nov 17 02:35:52 CET 2017 on sn-devel-144
2017-02-09Move pthreadpool to top of the tree.Matthieu Patou1-0/+246
Signed-off-by: Matthieu Patou <mat@matws.net> Reviewed-by: Jeremy Allison <jra@samba.org>