summaryrefslogtreecommitdiff
path: root/main/threadpool.c
AgeCommit message (Collapse)Author
2013-06-20Fix threadpool rapid growth problem.Mark Michelson
When a threadpool is set to autoincrement its threadcount, an issue may arise when multiple tasks are queued at once into the threadpool. Since threads start active, each new task would result in autoincrementing the thread count. So if all threads were active, and a thread's autoincrement value were 5, then 3 new tasks would result in 15 threads being created even though the initial autoincrement was sufficient to handle the number of tasks. This change introduces three behavior changes: 1) New threads in the threadpool start idle instead of active. 2) When a threadpool autoincrements, one thread is activated after the growth. 3) When a threadpool's size is incremented manually, all added threads are activated. For a more detailed explanation about the changes, please see the Review Board link at the bottom of this commit. Review: https://reviewboard.asterisk.org/r/2629 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@392318 65c4cc65-6c06-0410-ace0-fbb531ad65f3
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-03-07Changing log level of "Not changing threadpool size" from notice to debug.David M. Lee
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@382648 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-03-07Fix ref leak in threadpool.cKinsey Moore
If ast_threadpool_set_size with a size equal to the current size, a reference to a set_size_data structure would be leaked. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@382555 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-03-06Resolve a ref leak in threadpool.cKinsey Moore
Ownership of the listener reference is not transferred because the listener is reffed when placed into the taskprocessor. Ensure that the listener is dereffed properly. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@382489 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-02-28threadpool: Make ast_threadpool_push() return -1 if shutting_downRichard Mudgett
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@382295 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-02-28threadpool: Whitespace and comment corrections.Richard Mudgett
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@382294 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-17Address David's latest feedback on reviewboard:Mark Michelson
* Add a max_size option for threadpools. Also added a test for this option. * Fixed comments to be more accurate and have fewer typos. * Updated copyright dates on new files. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@379375 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-01-15Make the threadpool listener opaque.Mark Michelson
git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@379126 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-15Make the initial size of the threadpool part of the options passed in.Mark Michelson
git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@379123 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-01-15Remove threadpool listener alloc and destroy callbacks.Mark Michelson
This replaces the destroy callback with a shutdown callback instead. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@379122 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-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-11Some general cleanup, plus we now send state changes when threads activate.Mark Michelson
This is now ready for review board, imo! git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377805 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-11Add threadpool option version check into threadpool creation routine.Mark Michelson
git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377804 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-11Add auto-increment option and accompanying test.Mark Michelson
This allows for the threadpool to automatically grow if tasks are pushed to it and no idle threads are currently available. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377803 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-11Some documentation fixes and function call name fixes.Mark Michelson
The documentation for taskprocessors was incorrect with regards to when a listener's alloc callback was called. I also made the names of queued function calls in the threadpool more uniform. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377802 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-10Add threadpool options and accompanying test.Mark Michelson
The only test added so far is an idle thread timeout option. This will greatly aid threadpool users who wish to maintain a threadpool by allowing for idle threads to die out as necessary. Test passes. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377580 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-10Improve shutdown procedure.Mark Michelson
This helps tests to pass more often than before. They are far less likely to queue extra processes into the control taskprocessor since they are prevented once the threadpool begins to shut down. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377578 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-10Add safeguards to ensure we don't improperly access a destroyed taskprocessor.Mark Michelson
git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377556 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-09Remove unnecessary debugging and add some useful debugging.Mark Michelson
git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377476 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-09Create longer thread destruction test.Mark Michelson
This one involves shrinking the threadpool in such a way that both idle and active threads are affected. This test made me re-realize why the zombie state exists, so I re-added it. We don't want to clog up the control taskprocessor by waiting on active threads to complete what they are doing. Instead, we mark them as zombies so that when they are done, they can clean themselves up properly. Without the zombie state available, the new test actually will deadlock. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377474 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-12-06It helps if we actually assign the listener to the pool.Mark Michelson
git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377352 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-06Add initial simple threadpool test.Mark Michelson
This one simply pushes a task into the threadpool and ensures that the listener gets the callbacks expected. It currently crashes, so I need to figure out what's wrong. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377351 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-04Add better listener support.Mark Michelson
Add some parameters to listener callbacks. Add alloc and destroy callbacks for listeners. Add public function for allocating a listener. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377226 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-04Remove zombie state from threadpool altogether.Mark Michelson
After giving it some consideration, there's no real use for zombie threads. Listeners can't really use the current number of zombie threads as a way of gauging activity, zombifying threads is just an extra step before they die that really serves no purpose, and since there's no way to re-animate zombies, the operation does not need to be around. I also fixed up some miscellaneous compilation errors that were lingering from some past revisions. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377211 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-04Simplify threadpool refcounting a bit.Mark Michelson
Since threadpool shutdown is very strictly controlled, there is no need to be so precise with reference counts in queued operations. Since the threadpool shuts down its own control taskprocessor before doing anything else destructive, it can be guaranteed that all queued tasks will have a valid pointer to the pool. This meant that some destructor functions for helper structs could be removed entirely. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377210 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-04Add some doxygen and rearrange code.Mark Michelson
git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377209 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-03Fix a few miscellaneous thingsMark Michelson
* Renamed some taskprocessor listener callbacks * Fixed what would become a refcounting issue for pools * Removed some XXX comments from allocation failure points git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377061 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-12-03This now compiles.Mark Michelson
That's a milestone, of sorts. Things really need arranging/documenting, and there's no function to be able to push tasks to a threadpool. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377036 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-11-30Some more progress.Mark Michelson
Still does not compile. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@376898 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2012-11-29Commit some progress towards threadpools.Mark Michelson
Does this compile? Not even close. But I figure I don't want to lose this all in the case of some catastrophe. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@376833 65c4cc65-6c06-0410-ace0-fbb531ad65f3