summaryrefslogtreecommitdiff
path: root/main/sched.c
AgeCommit message (Collapse)Author
2016-03-15sched.c: Ensure oldest expiring entry runs first.Richard Mudgett
This patch is part of a series to resolve deadlocks in chan_sip.c. * Updated sched unit test to check new behavior. ASTERISK-25023 Change-Id: Ib69437327b3cda5e14c4238d9ff91b2531b34ef3
2015-12-01sched.c: Make not return a sched id of 0.Richard Mudgett
According to the API doxygen a sched ID of 0 is valid. Unfortunately, 0 was never returned historically and several users incorrectly coded usage of the returned sched ID assuming that 0 was invalid. ASTERISK-25476 Change-Id: Ib19c7ebb44ec9fd393ef6646dea806d4f34e3a20
2015-09-30sched.c: Add warning about negative time interval request.Richard Mudgett
Change-Id: Ib91435fb45b7f5f7c0fc83d0eec20b88098707bc
2015-09-15scheduler: Use queue for allocating sched IDs.Mark Michelson
It has been observed that on long-running busy systems, a scheduler context can eventually hit INT_MAX for its assigned IDs and end up overflowing into a very low negative number. When this occurs, this can result in odd behaviors, because a negative return is interpreted by callers as being a failure. However, the item actually was successfully scheduled. The result may be that a freed item remains in the scheduler, resulting in a crash at some point in the future. The scheduler can overflow because every time that an item is added to the scheduler, a counter is bumped and that counter's current value is assigned as the new item's ID. This patch introduces a new method for assigning scheduler IDs. Instead of assigning from a counter, a queue of available IDs is maintained. When assigning a new ID, an ID is pulled from the queue. When a scheduler item is released, its ID is pushed back onto the queue. This way, IDs may be reused when they become available, and the growth of ID numbers is directly related to concurrent activity within a scheduler context rather than the uptime of the system. Change-Id: I532708eef8f669d823457d7fefdad9a6078b99b2
2015-08-28sched: ast_sched_del may return prematurely due to spurious wakeupJoshua Colp
When deleting a scheduled item if the item in question is currently executing the ast_sched_del function waits until it has completed. This is accomplished using ast_cond_wait. Unfortunately the ast_cond_wait function can suffer from spurious wakeups so the predicate needs to be checked after it returns to make sure it has really woken up as a result of being signaled. This change adds a loop around the ast_cond_wait to make sure that it only exits when the executing task has really completed. ASTERISK-25355 #close Change-Id: I51198270eb0b637c956c61aa409f46283432be61
2015-06-10chan_iax2: Prevent deadlock between hangup and sending lagrq/pingYousf Ateya
channels/chan_iax.c: Prevent the deadlock between iax2_hangup and send_lagrq/ send_ping. This deadlock happens because the scheduled task send_lagrq(or send_ping) starts execution after the call hangup procedure starts but before it deletes the tasks in the scheduler. The solution is to delete scheduled lagrq (and ping) task asynchronously (i.e. schedule AST_SCHED_DEL for these tasks); By this, AST_SCHED_DEL will be called in a new context (doesn't have callno locked). This commit also cleans up the procedure of sending LAGRQ and PING. main/sched.c: Do not assert when deleting non existant entry from scheduler. This assert seems to be the reason for a lot of awkward code to avoid it. ASTERISK-24983 #close Reported by: Y Ateya Change-Id: I03bec1fc8faacb89630269e935fa667c6d6c080c
2015-02-19Create work around for scheduler leaks during shutdown.Corey Farrell
* Added ast_sched_clean_by_callback for cleanup of scheduled events that have not yet fired. * Run all pending peercnt_remove_cb and replace_callno events in chan_iax2. Cleanup of replace_callno events is only run 11, since it no longer releases any references or allocations in 13+. ASTERISK-24451 #close Reported by: Corey Farrell Review: https://reviewboard.asterisk.org/r/4425/ ........ Merged revisions 431916 from http://svn.asterisk.org/svn/asterisk/branches/11 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@431917 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-10-14Scheduler: Fix a nasty scheduler caching bug which makes new tasks not executeJonathan Rose
Tasks that were marked for pending deletion in the scheduler would be moved to the cache for later reuse, but after being recycled the deleted mark wouldn't be removed resulting in fresh tasks being deleted without reason... and immediately moved back into the cache where they could be reused again. This could cause horrendous things to happen in just about anything that used a scheduler. ASTERISK-24321 #close Reported by: Steve Pitts Review: https://reviewboard.asterisk.org/r/4071/ ........ Merged revisions 425503 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@425504 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-08-28sched: Fix typo and whitespace change.Richard Mudgett
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@422200 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-08-26Fix race condition in the scheduler when deleting a running entry.Mark Michelson
When scheduled tasks run, they are removed from the heap (or hashtab). When a scheduled task is deleted, if the task can't be found in the heap (or hashtab), an assertion is triggered. If DO_CRASH is enabled, this assertion causes a crash. The problem is, sometimes it just so happens that someone attempts to delete a scheduled task at the time that it is running, leading to a crash. This change corrects the issue by tracking which task is currently running. If that task is attempted to be deleted, then we mark the task, and then wait for the task to complete. This way, we can be sure to coordinate task deletion and memory freeing. ASTERISK-24212 Reported by Matt Jordan Review: https://reviewboard.asterisk.org/r/3927 ........ Merged revisions 422070 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@422071 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-05-09Allow Asterisk to compile under GCC 4.10Kinsey Moore
This resolves a large number of compiler warnings from GCC 4.10 which cause the build to fail under dev mode. The vast majority are signed/unsigned mismatches in printf-style format strings. ........ Merged revisions 413586 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 413587 from http://svn.asterisk.org/svn/asterisk/branches/11 ........ Merged revisions 413588 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@413589 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-02-11scheduler: Remove hashtab usage.Joshua Colp
This is a first stab at tweaking the performance profile of the scheduler. Removing the hashtab usage removes an extra memory allocation when scheduling something and makes it so rescheduling does not incur any memory allocation at all. Review: https://reviewboard.asterisk.org/r/3199/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@407958 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-03-14Fix inaccurate sizeof() in sched.c.Russell Bryant
This code just needed sizeof(int), not sizeof(int *). ........ Merged revisions 359157 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 359162 from http://svn.asterisk.org/svn/asterisk/branches/10 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@359166 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-12-20Some scheduler API cleanup and improvements.Russell Bryant
Previously, I had added the ast_sched_thread stuff that was a generic scheduler thread implementation. However, if you used it, it required using different functions for modifying scheduler contents. This patch reworks how this is done and just allows you to optionally start a thread on the original scheduler context structure that has always been there. This makes it trivial to switch to the generic scheduler thread implementation without having to touch any of the other code that adds or removes scheduler entries. In passing, I made some naming tweaks to add ast_ prefixes where they were not there before. Review: https://reviewboard.asterisk.org/r/1007/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@299091 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-08-10Merged revisions 281575 via svnmerge from Russell Bryant
https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r281575 | russell | 2010-08-10 13:05:07 -0500 (Tue, 10 Aug 2010) | 16 lines Merged revisions 281574 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ........ r281574 | russell | 2010-08-10 13:04:32 -0500 (Tue, 10 Aug 2010) | 9 lines Don't move the time threshold for running scheduled events on every iteration. Instead, only calculate the time threshold each time ast_sched_runq() is called. (closes issue #17742) Reported by: schmidts Patches: sched.c.patch uploaded by schmidts (license 1077) ........ ................ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@281576 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-07-16Finally, a method that really fixes the assertions in chan_iax2.c related to ↵Tilghman Lesher
cancelling lagid. No, replacing usleep(1) with sched_yield() did not have an effect. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@277484 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-02-03Initialize counters in ast_sched_report so that resulting data is not bogus.Mark Michelson
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@244547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-02-23Fix a regression in scheduler entry ordering, and add a regression test for it.Russell Bryant
(closes issue #14522) Reported by: pj Tested by: russell git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@178022 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-02-17Significantly improve scheduler performance under high load.Russell Bryant
This patch changes the scheduler to use a max-heap to store pending scheduler entries instead of a fully sorted doubly linked list. When the number of entries in the scheduler gets large, this will perform much better. For much more detailed information on this change, see the review request. Review: http://reviewboard.digium.com/r/160/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@176639 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-02-15Make ast_sched_report() and ast_sched_dump() thread safe.Russell Bryant
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@175882 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-02-15Fix a number of problems with ast_sched_report().Russell Bryant
1) It had numerous coding guidelines violations with regards to formatting. 2) It allocated memory using ast_calloc() that was never freed. 3) It didn't check for failure from the allocation. 4) It used sprintf() and strcat() to build the result, doing zero checking to prevent writing past the end of the provided buffer. The function also lacks API documentation, but that has not been addressed in this commit. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@175829 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-02-06Add a common implementation of a scheduler context with a dedicated thread.Russell Bryant
This commit expands the Asterisk scheduler API to include a common implementation of a scheduler context being processed by a dedicated thread. chan_iax2 has been updated to use this new code. Also, as a result, this resolves some race conditions related to the previous chan_iax2 scheduler handling. Related to rev 171452 which resolved the same issues in 1.4. Code from team/russell/sched_thread2 Review: http://reviewboard.digium.com/r/129/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@173858 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-09-10Merged revisions 142354 via svnmerge from Russell Bryant
https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r142354 | russell | 2008-09-10 11:39:53 -0500 (Wed, 10 Sep 2008) | 7 lines It is a normal situation that a task gets put in the scheduler that should run as soon as possible. Accept "0" as an acceptable time to run, and also treat negative as "run now", and don't print a debug message about it. (inspired by a message asking about the "request to schedule in the past" debug message on the -dev list) ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@142355 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-07-30Oops, wrong defineTilghman Lesher
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@134703 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-18Merged revisions 131988 via svnmerge from Tilghman Lesher
https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r131988 | tilghman | 2008-07-18 12:10:01 -0500 (Fri, 18 Jul 2008) | 2 lines Oops ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@131989 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-18Merged revisions 131985 via svnmerge from Tilghman Lesher
https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r131985 | tilghman | 2008-07-18 11:46:23 -0500 (Fri, 18 Jul 2008) | 2 lines Preserve ABI compatibility with last change ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@131986 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-07-18Merged revisions 131970 via svnmerge from Tilghman Lesher
https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r131970 | tilghman | 2008-07-18 11:30:31 -0500 (Fri, 18 Jul 2008) | 2 lines Make the ast_assert call within ast_sched_del report something useful. ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@131982 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-06-11Merged revisions 121861 via svnmerge from Tilghman Lesher
https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r121861 | tilghman | 2008-06-11 13:18:16 -0500 (Wed, 11 Jun 2008) | 3 lines Make calls to ast_assert() actually test something, so that the error message printed is not nonsensical (reported by mvanbaak via #asterisk-bugs). ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@121867 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-14Merged revisions 116463 via svnmerge from Russell Bryant
https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r116463 | russell | 2008-05-14 16:32:00 -0500 (Wed, 14 May 2008) | 4 lines Add ast_assert(), which can be used to handle fatal errors. It is only compiled in if dev-mode is enabled, and only aborts if DO_CRASH is defined. (inspired by issue #12650) ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@116469 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-05-07Fix up a problem that was introduced into the scheduler when it was convertedRussell Bryant
to use doubly linked lists. The schedule() function had an optimization that had it try to guess which direction would be better for the traversal to insert the task into the scheduler queue. However, if the code chose the path where it traversed the queue in reverse, and the result was that the task should be at the head of the queue, then the code would actually put it at the tail, instead. (Problem found by bbryant, debugged and fixed by bbryant and me) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@115537 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-05-02Add attributes to various API calls, to help track down bugs (and remove a ↵Tilghman Lesher
deprecated function) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@115157 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2008-04-16Introducing a small upgrade to the ast_sched_xxx facility, to keep it from ↵Steve Murphy
eating up lots of cpu cycles. See CHANGES. From the team/murf/bug11210 branch. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@114182 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-21remove a bunch of useless #include "options.h"Luigi Rizzo
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89511 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-19another bunch of include removals (errno.h and asterisk/logger.h)Luigi Rizzo
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89425 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-16Start untangling header inclusion in a way that does not affectLuigi Rizzo
build times - tested, there is no measureable difference before and after this commit. In this change: use asterisk/compat.h to include a small set of system headers: inttypes.h, unistd.h, stddef.h, stddint.h, sys/types.h, stdarg.h, stdlib.h, alloca.h, stdio.h Where available, the inclusion is conditional on HAVE_FOO_H as determined by autoconf. Normally, source files should not include any of the above system headers, and instead use either "asterisk.h" or "asterisk/compat.h" which does it better. For the time being I have left alone second-level directories (main/db1-ast, etc.). git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89333 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-11-08improve linked-list macros in two ways:Kevin P. Fleming
- the *_CURRENT macros no longer need the list head pointer argument - add AST_LIST_MOVE_CURRENT to encapsulate the remove/add operation when moving entries between lists git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89106 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-09-21Merged revisions 83432 via svnmerge from Russell Bryant
https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r83432 | russell | 2007-09-21 09:37:20 -0500 (Fri, 21 Sep 2007) | 4 lines gcc 4.2 has a new set of warnings dealing with cosnt pointers. This set of changes gets all of Asterisk (minus chan_alsa for now) to compile with gcc 4.2. (closes issue #10774, patch from qwell) ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@83433 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-08-30A schedule id of 0 is not possible and is used to flag that we want to add a ↵Tilghman Lesher
new item git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@81390 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-08-17This commit adds a scheduler API call, ast_sched_replace that can be usedRussell Bryant
in place of a very common construct. I also used it in a number of places in chan_sip. if (id > -1) ast_sched_del(sched, id); id = ast_sched_add(sched, ...); changes to: ast_sched_replace(id, sched, ...); git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@79861 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-06-25Convert so more logging to ast_debug (issue #10045, dimas)Russell Bryant
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@71557 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-06-24Conversions to ast_debug()Russell Bryant
(issue #9984, patches from eliel and dimas) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@71338 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-06-06Issue 9869 - replace malloc and memset with ast_calloc, and other coding ↵Tilghman Lesher
guidelines changes git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@67864 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-02-23Merged revisions 56457 via svnmerge from Joshua Colp
https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r56457 | file | 2007-02-23 16:53:41 -0500 (Fri, 23 Feb 2007) | 2 lines Change log notice to debug. It is possible for a scheduled item to execute and be deleted at close to the same time and unavoidable. If this happens this message creeps up. ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@56458 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-10-03bug #8076 check option_debug before printing to debug channel.Matt O'Gorman
patch provided in bugnote, with minor changes. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@44253 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2006-08-21merge new_loader_completion branch, including (at least):Kevin P. Fleming
- restructured build tree and makefiles to eliminate recursion problems - support for embedded modules - support for static builds - simpler cross-compilation support - simpler module/loader interface (no exported symbols) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@40722 65c4cc65-6c06-0410-ace0-fbb531ad65f3