summaryrefslogtreecommitdiff
path: root/main/taskprocessor.c
AgeCommit message (Collapse)Author
2013-04-25Merge the pimp_my_sip branch into trunk.Mark Michelson
The pimp_my_sip branch is being merged at this point because it offers basic functionality, and from an API standpoint, things are complete. SIP work is *not* feature-complete; however, with the completion of the SUBSCRIBE/NOTIFY API, all APIs (except a PUBLISH API) have been created, and thus it is possible for developers to attempt to create new SIP work. API documentation can be found in the doxygen in the code, but usability documentation is still lacking. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@386540 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-02-12Add a serializer interface to the threadpoolDavid M. Lee
This patch adds the ability to create a serializer from a thread pool. A serializer is a ast_taskprocessor with the same contract as a default taskprocessor (tasks execute serially) except instead of executing out of a dedicated thread, execution occurs in a thread from a ast_threadpool. Think of it as a lightweight thread. While it guarantees that each task will complete before executing the next, there is no guarantee as to which thread from the pool individual tasks will execute. This normally only matters if your code relys on thread specific information, such as thread locals. This patch also fixes a bug in how the 'was_empty' parameter is computed for the push callback, and gets rid of the unused 'shutting_down' field. Review: https://reviewboard.asterisk.org/r/2323/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@381326 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-01-15Add doxygen to accessors and increase refcount of taskprocessor before ↵Mark Michelson
returning. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@379127 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-01-15Make ast_taskprocessor_listener opaque.Mark Michelson
git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@379125 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-01-15Address further review feedback from David Lee.Mark Michelson
* Clarify some documentation * Change copyright date of taskprocessor files * Address potential issue of creating taskprocessor with listener if taskprocessor with that name exists already git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@379124 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-01-15Remove alloc and destroy callbacks from the taskprocessor.Mark Michelson
Now user data is allocated by the creator of the taskprocessor listener and that user data is passed into ast_taskprocessor_listener_alloc(). Similarly, freeing of the user data is left up to the user himself. He can free the data when the taskprocessor shuts down, or he can choose to hold onto it if it makes sense to do so. This, unsurprisingly, makes threadpool allocation a LOT cleaner now. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@379120 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-01-07Remove tasks from the taskprocessor and free them when taskprocessor is ↵Mark Michelson
destroyed. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@378654 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-01-07Add some doxygen and remove an unnecessary unlock.Mark Michelson
git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@378653 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-01-07Address review board feedback from Matt and RichardMark Michelson
* Remove extraneous whitespace * Bump up debug levels of messages and add identifying info to messages. * Account for potential failures of ao2_link() * Add additional test and some more test data * Add some comments in places where they could be useful * Make threadpool listeners and their callbacks optional git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@378652 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-13Resolve conflict and reset automerge.Mark Michelson
git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377980 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-10Solve the issue about the "CHANGE THIS" and "XXX CHANGE THIS XXX" ↵Mark Michelson
taskprocessor names. Unfortunately, this required a taskprocessor listener change that makes listener allocation utterly silly. I'm going to change the scheme so that allocation of taskprocessor listeners is done internally within taskprocessor code. This will make it parallel with threadpool code, which is a good thing. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377687 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-07Remove unsafe write of listener member.Mark Michelson
git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377381 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-07Fix infinite looping and crash problem.Mark Michelson
MALLOC_DEBUG is complaining about corrupted memory on taskprocessor listeners, but I'm not seeing it, nor is valgrind. Not sure what's up there. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377377 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-07Add new threadpool test and fix some taskprocessor bugs.Mark Michelson
The new thread creation test fails because Asterisk locks up while trying to lock a taskprocessor. While trying to debug that, I found a race condition during taskprocessor creation where a default taskprocessor listener could try to operate on a partially started taskprocessor. This was fixed by adding a new callback to taskprocessor listeners. Then while testing that change, I found some bugs in the taskprocessor tests where I was not properly unlocking when done with a lock. Scoped locks have spoiled me a bit. I still have not figured out why the threadpool thread creation test is locking up. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377368 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-11-19Get rid of trailing whitespace.Mark Michelson
git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@376500 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-11-19Reorganize code and change behavior of ast_taskprocessor_execute() when ↵Mark Michelson
taskprocessor is shutting down. Moved code around to be easier to follow. ast_taskprocessor_execute() will now return 0 if the taskprocessor is being shut down. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@376499 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-11-16Test that shutdown callback is called when expected.Mark Michelson
git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@376383 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-11-16Add a shutdown callback to taskprocessor listeners.Mark Michelson
This helps account for the fact that it is unknown just how many references may exist for a given taskprocessor listener, so simply unreffing it from the taskprocessor shutdown function is not enough to convey the gravity of the situation. By putting in a shutdown callback, it now becomes clear to the listener not to try to do any further operations on the taskprocessor. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@376381 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-11-09Add doxygen and constify some things.Mark Michelson
git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@376123 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-11-09Genericize the allocation and destruction of taskprocessor listeners.Mark Michelson
The goal of this is to take the responsibility away from individual listeners to be sure to properly unref the taskprocessor. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@376121 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-11-08Get rid of taskprocessor fields no longer necessary.Mark Michelson
This includes changing the taskprocessor to use its builtin ao2_lock instead of having a separate mutex. It can do this now since there is no longer an ast_cond_t associated with the taskprocessor. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@376119 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-11-08Move taskprocessors to use a listener model.Mark Michelson
Taskprocessors are now divided into two units: the task queue and their listeners. When a task is added to the queue, the listener is notified and can take whatever action is desired. This means that taskprocessors are no longer confined to having their tasks executed within a single thread. A default taskprocessor listener has been added that mirrors the old taskprocessor behavior. I've tested it by running Asterisk and placing calls. It appears to work as expected. I'm going to do some cleaning up first and then write some unit tests to be sure everything works as expected. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@376118 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-10-02Fix a variety of ref counting issuesMatthew Jordan
This patch resolves a number of ref leaks that occur primarily on Asterisk shutdown. It adds a variety of shutdown routines to core portions of Asterisk such that they can reclaim resources allocate duringd initialization. Review: https://reviewboard.asterisk.org/r/2137 ........ Merged revisions 374177 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 374178 from http://svn.asterisk.org/svn/asterisk/branches/10 ........ Merged revisions 374196 from http://svn.asterisk.org/svn/asterisk/branches/11 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@374197 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-06-15Multiple revisions 369001-369002Kevin P. Fleming
........ r369001 | kpfleming | 2012-06-15 10:56:08 -0500 (Fri, 15 Jun 2012) | 11 lines Add support-level indications to many more source files. Since we now have tools that scan through the source tree looking for files with specific support levels, we need to ensure that every file that is a component of a 'core' or 'extended' module (or the main Asterisk binary) is explicitly marked with its support level. This patch adds support-level indications to many more source files in tree, but avoids adding them to third-party libraries that are included in the tree and to source files that don't end up involved in Asterisk itself. ........ r369002 | kpfleming | 2012-06-15 10:57:14 -0500 (Fri, 15 Jun 2012) | 3 lines Add a script to enable finding source files without support-levels defined. ........ Merged revisions 369001-369002 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 369005 from http://svn.asterisk.org/svn/asterisk/branches/10 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@369013 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-03-22Kill off red blobs in most of main/*Kinsey Moore
Everything still compiled after making these changes, so I assume these whitespace-only changes didn't break anything (and shouldn't have). git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@360190 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-01-27Audit of ao2_iterator_init() usage for v1.8.Richard Mudgett
Fixes numerous reference leaks and missing ao2_iterator_destroy() calls as a result. Review: https://reviewboard.asterisk.org/r/1697/ ........ Merged revisions 352955 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 352956 from http://svn.asterisk.org/svn/asterisk/branches/10 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@352957 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-02-04Replace ast_log(LOG_DEBUG, ...) with ast_debug()Paul Belanger
(closes issue #18556) Reported by: kkm Review: https://reviewboard.asterisk.org/r/1071/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@306258 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-02-22Minor tweaks to comment blocks and includes.Russell Bryant
Fix the copyright lines, tweak doxygen formatting, and remove some unnecessary includes. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@248226 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-05-21Const-ify the world (or at least a good part of it)Kevin P. Fleming
This patch adds 'const' tags to a number of Asterisk APIs where they are appropriate (where the API already demanded that the function argument not be modified, but the compiler was not informed of that fact). The list includes: - CLI command handlers - CLI command handler arguments - AGI command handlers - AGI command handler arguments - Dialplan application handler arguments - Speech engine API function arguments In addition, various file-scope and function-scope constant arrays got 'const' and/or 'static' qualifiers where they were missing. Review: https://reviewboard.asterisk.org/r/251/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@196072 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-01Merge changes from str_substitution that are unrelated to that branch.Tilghman Lesher
Included is a small bugfix to an ast_str helper, but most of these changes are simply doxygen fixes. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@185912 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-01-13correct a CLI descriptionDwayne M. Hubbard
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@168539 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-11-25This is basically a complete rollback of r155401, as it was determined thatSean Bright
it would be best to maintain API compatibility. Instead, this commit introduces ao2_callback_data() which is functionally identical to ao2_callback() except that it allows you to pass arbitrary data to the callback. Reviewed by Mark Michelson via ReviewBoard: http://reviewboard.digium.com/r/64 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@158959 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-11-15Fix a few more places where the case insensitive hash should be used sinceRussell Bryant
the comparison is case insensitive. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@157041 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-11-07Add ability to pass arbitrary data to the ao2_callback_fn (called fromSean Bright
ao2_callback and ao2_find). Currently, passing OBJ_POINTER to either of these mandates that the passed 'arg' is a hashable object, making searching for an ao2 object based on outside criteria difficult. Reviewed by Russell and Mark M. via ReviewBoard: http://reviewboard.digium.com/r/36/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@155401 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-09-28Merge the cli_cleanup branch.Michiel van Baak
This work is done by lmadsen, junky and mvanbaak during AstriDevCon. This is the second audit the CLI got, and this time lmadsen made sure he had _ALL_ modules loaded that have CLI commands in them. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@145121 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-08-29Merged revisions 140488 via svnmerge from Mark Michelson
https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r140488 | mmichelson | 2008-08-29 12:34:17 -0500 (Fri, 29 Aug 2008) | 22 lines After working on the ao2_containers branch, I noticed something a bit strange. In all cases where we provide a callback function to ao2_container_alloc, the callback function would only return 0 or CMP_MATCH. After inspecting the ao2_callback() code carefully, I found that if you're only looking for one specific item, then you should return CMP_MATCH | CMP_STOP. Otherwise, astobj2 will continue traversing the current bucket until the end searching for more matches. In cases like chan_iax2 where in 1.4, all the peers are shoved into a single bucket, this makes for potentially terrible performance since the entire bucket will be traversed even if the peer is one of the first ones come across in the bucket. All the changes I have made were for cases where the callback function defined was passed to ao2_container_alloc so that calls to ao2_find could find a unique instance of whatever object was being stored in the container. ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@140489 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-08-10That's all, folks. Not going to update the Makefile until res_jabber isSean Bright
converted (snuffy, you there? :)) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@137110 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-08-06move taskprocessor CLI commands into the core namespaceDwayne M. Hubbard
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@136245 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-06-23make solaris happy...pointed out by snuff-home on IRCDwayne M. Hubbard
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@124707 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-06-10Properly initialize the cli_ping condition and lockRussell Bryant
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@121402 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-06-10Change system header includes to be like how it is done in other filesRussell Bryant
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@121401 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-06-09Initialize the lock and destroy lock and cond in the destructor (thanks, ↵Terry Wilson
mmichelson) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@121365 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-05-29Had to move the ASTERISK_FILE_VERSION decl to just after the include of ↵Steve Murphy
"asterisk.h" or you get undefined variable errors when you are compiling under the influence of MTX_PROFILE git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@119074 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-05-15Use casts or intermediate variables to remove a numberLuigi Rizzo
of platform/compiler-dependent warnings when handing struct timeval fields, both reading and printing them. It is a lost battle to handle the different ways struct timeval is handled on the various platforms and compilers, so try to be pragmatic and go through int/long which are universally supported. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@116557 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-05-03A taskprocessor is an object that has a name, a task queue, and an event ↵Dwayne M. Hubbard
processing thread. Modules reference a taskprocessor, push tasks into the taskprocessor as needed, and unreference the taskprocessor when the taskprocessor is no longer needed. A task wraps a callback function pointer and a data pointer and is managed internal to the taskprocessor subsystem. The callback function is responsible for releasing task data. Taskprocessor API * ast_taskprocessor_get(..) - returns a reference to a taskprocessor * ast_taskprocessor_unreference(..) - releases reference to a taskprocessor * ast_taskprocessor_push(..) - push a task into a taskprocessor queue Check doxygen for more details git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@115268 65c4cc65-6c06-0410-ace0-fbb531ad65f3