summaryrefslogtreecommitdiff
path: root/threadproc
Commit message (Collapse)AuthorAgeFilesLines
* apr_thread: Follow up to r1897207: apr_thread_current_create() compilation.Yann Ylavic2022-02-085-2/+7
| | | | | | | | | | | | Fix compilation of apr_thread_current_create() for OS/2 and Windows. Set *current to NULL on failure. Merge r1897879 from trunk. Submitted by: ylavic git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.8.x@1897880 13f79535-47bb-0310-9956-ffa450edef68
* apr_thread: Follow up to r1897207: Provide apr_thread_current_after_fork().Yann Ylavic2022-01-259-0/+47
| | | | | | | | | | | | | | | thread_local variables are not (always?) reset on fork(), so APR (and the user) needs a way to set the current_thread to NULL. Use apr_thread_current_after_fork() in apr_proc_fork()'s child process. Merge r1897470 from trunk. Submitted by: ylavic Reviewed by: ylavic git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.8.x@1897471 13f79535-47bb-0310-9956-ffa450edef68
* apr_thread: Follow up to r1897207: Make APR_HAS_THREAD_LOCAL a boolean..Yann Ylavic2022-01-255-21/+21
| | | | | | | | | | | .. rather than a defined(). Merge r1897447 from trunk. Submitted by: ylavic git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.8.x@1897448 13f79535-47bb-0310-9956-ffa450edef68
* apr_thread: Follow up to r1897207: Don't NULLify current_thread on exit.Yann Ylavic2022-01-255-33/+5
| | | | | | | | | | | It's not needed, when the thread exits it's not accessible anyway. Merge r1897445 from trunk. Submitted by: ylavic git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.8.x@1897446 13f79535-47bb-0310-9956-ffa450edef68
* apr_thread: Follow up to r1897179: abort_fn on apr_allocator_create() failure.Yann Ylavic2022-01-245-10/+20
| | | | | | | | Merge r1897419 from trunk. Submitted by: ylavic git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.8.x@1897420 13f79535-47bb-0310-9956-ffa450edef68
* apr_thread: Use compiler's TLS to track the current apr_thread_t's pointer.Yann Ylavic2022-01-195-55/+397
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | All modern compilers provide a Thread Local Storage keyword that allows to store per-thread data efficiently (C++11 's thread_local, C11's _Thread_local, gcc/clang's __thread or MSVC's __declspec(thread)). Use that to have an apr_thread_t pointer associated with each thread created by apr_thread_create() or any native thread (like the process' initial thread) that registered itself with the new apr_thread_current_create() function. This mechanism allows to implement apr_thread_current() quite efficiently, if available, otherwise the function returns NULL. If available APR_HAS_THREAD_LOCAL is #define'd to 1 and the APR_THREAD_LOCAL macro is the keyword usable to register TLS variables natively. Both APR_HAS_THREAD_LOCAL and APR_THREAD_LOCAL are #undef'ined if the compiler does not provide the mechanism. This allows to test for the functionality at compile time. When APR_HAS_THREAD_LOCAL, the user can load his/her own TLS data with: apr_thread_data_get(&my_data, my_key, apr_thread_current()); and store them with: apr_thread_data_set(my_data, my_key, my_data_cleanup, apr_thread_current()); which can be nice to avoid the proliferation of native TLS keys. Merge r1897207 from trunk: Submitted by: ylavic git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.8.x@1897223 13f79535-47bb-0310-9956-ffa450edef68
* apr_thread: Allocate the apr_thread_t struct on the thread's pool.Yann Ylavic2022-01-195-84/+86
| | | | | | | | | | | | | | | | | | | | | | | | | apr_thread_create() was allocating the created apr_thread_t on the given pool, which caused e.g. short-living threads to leak memory on that pool without a way to clear it (while some threads are still running). Change this by allocating the apr_thread_t on the thread's pool itself, which is safe in the implementations of all archs because none uses the apr_thread_t after the thread exits, and it's safe for the users provided they don't use the apr_thread_t for detached threads or for attached threads after the call to apr_thread_join(). These are hardly new requirements though. apr_thread: Follow up to r1897197: Safer apr_thread_join(). Make sure apr_thread_join() behaves correctly w.r.t. the returned value and pool destroy for all archs. Merge r1897197, r1897198 from trunk. Submitted by: ylavic git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.8.x@1897221 13f79535-47bb-0310-9956-ffa450edef68
* apr_thread: Follow up to r1884078: Unmanaged pools for attached threads too.Yann Ylavic2022-01-195-226/+158
| | | | | | | | | | | | | | | | | | | | | | | | | | | r1884078 fixed lifetime issues with detached threads by using unmanaged pool destroyed by the thread itself on exit, with no binding to the parent pool. This commit makes use of unmanaged pools for attached threads too, they needed their own allocator anyway due to apr_thread_detach() being callable anytime later. apr__pool_unmanage() was a hack to detach a subpool from its parent, but if a subpool needs its own allocator for this to work correctly there is no point in creating a subpool for threads (no memory reuse on destroy for short living threads for instance). Since an attached thread has its own lifetime now, apr_thread_join() must be called to free its resources/pool, though it's no different than before when destroying the parent pool was UB if the thread was still running (i.e. not joined yet). Let's acknoledge that threads want no binding with the pool passed to them at creation time, besides the abort_fn which they can steal :) Merge r1897179 from trunk. Submitted by: ylavic git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.8.x@1897220 13f79535-47bb-0310-9956-ffa450edef68
* Merge r936323, r1460182, r1884077, r1884078 from trunk:Yann Ylavic2020-12-045-37/+278
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | OS/2: Clean up a thread's pool when it terminates. <not backported in 1.7.x> Add apr_pool_owner_set function to allow use of pool debugging with threads Actually this function has been mentioned in the docs for over 10 years but has never been implemented. </not backported in 1.7.x> Also consistently destroy the thread's pool when it exits normally, not only on apr_thread_exit(). This was already done on OS2. Other platforms than unix are untested. apr_thread: destroy the thread's pool at _join() time, unless _detach()ed. Destroying a joinable thread pool from apr_thread_exit() or when the thread function returns, i.e. from inside the thread itself, is racy or deadlocky with APR_POOL_DEBUG, with the parent pool being destroyed. This commit adds a ->detached flag in each arch's apr_thread_t struct to track whether a thread is detached (either at _create() or _detach() time). If detached, the pool is destroyed when the thread exits, otherwise when the thread is joined with apr_thread_join(). apr_thread: use unmanaged pools for detached threads. A detached thread is by definition out of control, unjoinable, unmanaged, and it can terminate/exit after its parent pool is detroyed. To avoid use-after-free in this case, let's use an unmanaged pool for detached threads, either by creating an unmanaged pool from the start if the thread is created detached, or by "unmanaging" the pool if the thread is detached later with apr_thread_detach(). To "umanage" the pool, provide a new internal helper, apr__pool_unmanage() which takes care of removing the pool from its parent's list. Submitted by: bjh, sf, ylavic, ylavic git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.7.x@1884103 13f79535-47bb-0310-9956-ffa450edef68
* Merge r1854123 from trunk:Yann Ylavic2019-03-071-6/+0
| | | | | | | | | | Signals: Allow handling of SIGUSR2 in apr_signal_thread. It's not like users have so many free signals to play with, let's increase this number by 100% here, not so bad :) git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.7.x@1854995 13f79535-47bb-0310-9956-ffa450edef68
* Backport r1710307Christophe Jaillet2015-10-241-3/+3
| | | | git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1710308 13f79535-47bb-0310-9956-ffa450edef68
* Fixed type; fixed comments.Guenter Knauf2014-07-161-4/+4
| | | | git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1611061 13f79535-47bb-0310-9956-ffa450edef68
* Backport r741867 from trunk, which fixes a logic error.Stefan Fritsch2014-05-141-1/+1
| | | | | | | | | | The original commit message was: Fix typo git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1594689 13f79535-47bb-0310-9956-ffa450edef68
* Merge r741862, r741866 from trunk:Jim Jagielski2014-04-285-1/+61
| | | | | | | | | Add object perms set macros and implement them for shm and mutex Submitted by: mturk, rpluem Reviewed/backported by: jim git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1590617 13f79535-47bb-0310-9956-ffa450edef68
* merge r1384764 from trunk:Jeff Trawick2013-10-211-2/+2
| | | | | | | spelling fix git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.5.x@1534104 13f79535-47bb-0310-9956-ffa450edef68
* merge r1372093 from trunk:Jeff Trawick2013-10-211-0/+1
| | | | | | | release critical section before returning on error path git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.5.x@1534103 13f79535-47bb-0310-9956-ffa450edef68
* revret 1533105Jim Jagielski2013-10-175-62/+1
| | | | git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.5.x@1533107 13f79535-47bb-0310-9956-ffa450edef68
* Merge r1533104 from trunk:Jim Jagielski2013-10-175-1/+62
| | | | | | | | | it should really handle src==NULL Reviewed/backported by: jim git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.5.x@1533105 13f79535-47bb-0310-9956-ffa450edef68
* definAtelyRainer Jung2013-10-031-1/+1
| | | | | | | Backport of r1213382 from trunk. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.5.x@1528818 13f79535-47bb-0310-9956-ffa450edef68
* Followup on r1481263: use already existingRainer Jung2013-05-111-1/+1
| | | | | | | | | | platform independent macro instead of pthread define. Backport of r1481265 from trunk. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.5.x@1481266 13f79535-47bb-0310-9956-ffa450edef68
* Use correct pthread constant.Rainer Jung2013-05-111-1/+1
| | | | | | | Backport of r1481262 from trunk. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.5.x@1481263 13f79535-47bb-0310-9956-ffa450edef68
* Clarify what happens to the proc structure used by apr_fork(). Rainer Jung2011-11-081-7/+3
| | | | | | | | | | | Set the proc->pid field to the pid of the newly created child. Note that a mere pid value provides little entropy to mix into the child random pool. Backport of r1198860 from trunk. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.5.x@1199082 13f79535-47bb-0310-9956-ffa450edef68
* backport r979891:Stefan Fritsch2011-10-153-9/+9
| | | | | | | | | | | | | | Fix various issues found by cppcheck - error handling issues - use of uninitialized data - null pointer dereference - unused variables - memory/fd leaks - broken code in threadproc/beos/proc.c git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.5.x@1183724 13f79535-47bb-0310-9956-ffa450edef68
* Backport r1183685:Stefan Fritsch2011-10-151-3/+6
| | | | | | | | | | | | Don't close any of the new stdin/stdout/stderr FDs in the child if it already has the correct FD. PR: 51995 Submitted by: Dan Ports <drkp csail mit edu>] git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.5.x@1183706 13f79535-47bb-0310-9956-ffa450edef68
* merge trunk revs 1083169, 1083177, 1083178, 1083183, and 1083227Jeff Trawick2011-03-212-2/+3
| | | | | | | | | | to resolve some gcc warnings and dead code on Windows (the testlfsabi change from r1083183 is omitted, as the testcases aren't in this branch) git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.5.x@1083869 13f79535-47bb-0310-9956-ffa450edef68
* Fixed NetWare prototype warnings.Guenter Knauf2011-03-102-5/+4
| | | | git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.5.x@1080082 13f79535-47bb-0310-9956-ffa450edef68
* Fixed compilation when APR_HAVE_STRUCT_RLIMIT=0.Guenter Knauf2011-03-102-4/+21
| | | | git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.5.x@1080074 13f79535-47bb-0310-9956-ffa450edef68
* Axed C++ comments and tabs.Guenter Knauf2011-02-181-27/+26
| | | | git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.5.x@1071966 13f79535-47bb-0310-9956-ffa450edef68
* Merge r783722 from trunk:Ruediger Pluem2009-06-113-3/+3
| | | | | | | | | | | | * We need to disable inheritance in the case of success like in the cases for stdout and stdin. Fixes the same issue fixed for unix in r783398 Submitted by: rpluem Reviewed by: rpluem git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.4.x@783725 13f79535-47bb-0310-9956-ffa450edef68
* Merge r783398 from trunk:Ruediger Pluem2009-06-101-1/+1
| | | | | | | | | | | * We need to disable inheritance in the case of success like in the cases for stdout and stdin. Submitted by: rpluem Reviewed by: rpluem git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.4.x@783399 13f79535-47bb-0310-9956-ffa450edef68
* Clear up this wording a bitWilliam A. Rowe Jr2008-11-231-2/+2
| | | | git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@720054 13f79535-47bb-0310-9956-ffa450edef68
* mplement apr_proc_wait_all_procs for windowsMladen Turk2008-04-171-15/+126
| | | | git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@649208 13f79535-47bb-0310-9956-ffa450edef68
* Check for bogus (negative) signal numbersMartin Kraemer2008-02-011-2/+2
| | | | git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@617375 13f79535-47bb-0310-9956-ffa450edef68
* Simplify handling of z/OS pthread API nuances. Beyond theJeff Trawick2007-11-192-13/+17
| | | | | | | | | | | | | simplification, it fixes a compile error in the call to pthread_yield() on z/OS. Submitted by: David Jones I modified it slightly to use AC_DEFINE() as suggested by jorton. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@596402 13f79535-47bb-0310-9956-ffa450edef68
* Fix mismatch, using child_err when dealing with stdout.Brian Havard2007-10-311-1/+1
| | | | git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@590849 13f79535-47bb-0310-9956-ffa450edef68
* OS/2: Fix condition for restoring std handles after spawning a process.Brian Havard2007-10-311-6/+15
| | | | | | | | We still need to restore the std handles if "no file" (filedes == -1) is passed to the child. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@590848 13f79535-47bb-0310-9956-ffa450edef68
* Fix build breakage due to syntax errors in threadproc/os2/proc.c.Brian Havard2007-10-301-9/+10
| | | | | | | | I haven't yet verified that the code works but this is a step in the right direction. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@590037 13f79535-47bb-0310-9956-ffa450edef68
* Fix up a few netware'isms and missing brackets left over from the refactoring.Bradley Nicholes2007-10-161-6/+10
| | | | git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@585260 13f79535-47bb-0310-9956-ffa450edef68
* Backport the std handling improvements to Netware, OS2, BeOS.William A. Rowe Jr2007-10-153-285/+384
| | | | | | | | | | | | | | | | | | | | | These may need massaging and do need review by their respective communities. Note that someone from the OS2 community needs to ping me with resolving the missing apr_arch_inherit.h mess; this should be very easy to translate into DosSetFHState(handle, OPEN_FLAGS_NOINHERIT); bits, but to more thoroughly resolve the issue, we should take it a step further and consider the NT implementation which toggles inheritance on only for handles as they hit proc_create, so that you don't have cross-process handle leakage into the wrong processes. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@584928 13f79535-47bb-0310-9956-ffa450edef68
* Here's my recommendation; upon opening the pipes, always set the parent-endWilliam A. Rowe Jr2007-10-141-15/+18
| | | | | | | | | | | | of the pipe to uninherited. Let it be closed upon cleanup_for_exec. The later dup2() for the parent pipe does not automagically become inherited again, and later dup()'s are never inherited by default. There's no longer an explicit need to close the parent-end in proc_create git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@584570 13f79535-47bb-0310-9956-ffa450edef68
* apr_file_dup() varies from dup2 by not setting the child handle asWilliam A. Rowe Jr2007-10-141-12/+30
| | | | | | | | | | | | | | | inherited. Solve this by setting the duplicated handle to inherit. once finished with the fork(), now that we don't waste pipe creation resources on a single handle, watch out for closing the parent handle inside the child. in fact I believe that toggling parent_* handles apr_file_inherit_unset way back in apr_procattr_io_set / apr_procattr_child_*_set would be more efficient; comments? git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@584569 13f79535-47bb-0310-9956-ffa450edef68
* Solve two potential problems with one shot.William A. Rowe Jr2007-10-141-77/+66
| | | | | | | | | | | | | | | | | | First; we absolutely do NOT want to waste our time creating a pipe, when the caller has their own file descriptors all set up to give to the child process (and use itself). We can also presume a single ended pipe is about as interesting as the sound of one hand clapping. Create the pipe only when we don't already have any child/parent pipes set up, and when the caller passes no files for us to use. Otherwise, we simply dup for our own use rather than dup2. Second; we absolutely cannot dup2 into the static 'no_file' special fd, so we'll guard against this and also dup, instead, for this case. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@584500 13f79535-47bb-0310-9956-ffa450edef68
* With the correction of setting ->timeout = 0 way up in theWilliam A. Rowe Jr2007-10-141-55/+9
| | | | | | | | apr_file_pipe_create_ex() for win32, many lines are redundant. Thanks to Eric for picking up on this mess in the first place! git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@584496 13f79535-47bb-0310-9956-ffa450edef68
* * Remove unnecessary assignment of pool attribute.Ruediger Pluem2007-10-135-5/+0
| | | | | | | | Submitted by: Lucian Adrian Grijincu <lucian.grijincu gmail.com> Reviewed by: rpluem git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@584411 13f79535-47bb-0310-9956-ffa450edef68
* apr_procattr_io_set() on Windows: Set pipe handles non-blocking asJeff Trawick2007-10-101-3/+51
| | | | | | | | | | | appropriate based on the input parameters. PR: 43522 Submitted by: Eric Covener <covener gmail.com> Reviewed by: trawick git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@583421 13f79535-47bb-0310-9956-ffa450edef68
* Close the standard handle in the child, *when* we tagged it with fd -1William A. Rowe Jr2007-10-011-3/+3
| | | | | | | | | | (we aren't trying to close our child_fd's here). Submitted by: David Glasser <glasser@davidglasser.net> git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@581089 13f79535-47bb-0310-9956-ffa450edef68
* Had inverted the logic for closing the handles in the parent, thanks to glasserWilliam A. Rowe Jr2007-10-011-6/+6
| | | | | | | for pointing this out to me on #irc. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@581042 13f79535-47bb-0310-9956-ffa450edef68
* Thanks for catching the unbalanced parens, jerenkrantz.William A. Rowe Jr2007-09-291-3/+3
| | | | | | These can be reduced further and still remain legible. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@580632 13f79535-47bb-0310-9956-ffa450edef68
* Fix compile errors introduced in r580486 due to missing ()s.Justin Erenkrantz2007-09-291-6/+6
| | | | git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@580591 13f79535-47bb-0310-9956-ffa450edef68
* Undo the 'fix' to the unix flaw. Yes, there still are flaws;William A. Rowe Jr2007-09-281-36/+12
| | | | | | | | | | if we use apr_procattr_stderr_set() it will not close out the previous handle parked there by _io_set(). But it also does not attempt to touch the _io_set() no_file STATIC apr_file_t's so there is nothing to otherwise fix here immediately. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@580515 13f79535-47bb-0310-9956-ffa450edef68