diff options
author | unknown <andrey@lmy004.> | 2005-12-12 21:19:19 +0100 |
---|---|---|
committer | unknown <andrey@lmy004.> | 2005-12-12 21:19:19 +0100 |
commit | 81eadfcac18f3adc29c55d440e62823855f5b070 (patch) | |
tree | bb204756d7ec8bb96576f0bacb52879ab6ddddbf /mysys/queues.c | |
parent | 1c5573a47c4ef43558770c1c4e536ba39114dcbb (diff) | |
download | mariadb-git-81eadfcac18f3adc29c55d440e62823855f5b070.tar.gz |
WL#1034 update
QUEUE implementation working now. this should be ready more or less
for testing once the debug output is being cleaned and some things
around DYNAMIC_ARRAY are cleaned
- fix handling in case of errors that lead to crashes, now no more crashes
in case of table corruption and such.
include/queues.h:
introduce a safe version of queue_insert that will extend the queue if
necessary. the auto_extent is passed to the _ex version of init_queue()
mysys/queues.c:
add init_queue_ex() implementation
add queue_insert_safe() implementation
sql/event.cc:
- move mysql_priv.h inclusion to event_priv.h
- use a priority queue instead of DYNAMIC_ARRAY which is sorted
sql/event.h:
reorder
sql/event_executor.cc:
reorder
sql/event_priv.h:
- reorder a bit
- add macroses and functions for queue manipulation which stay on top
of QUEUE (partly implemented for DYNAMIC_ARRAY but will be cleared to be
only for QUEUE).
sql/event_timed.cc:
allocate one more byte and zeroterminate, really
Diffstat (limited to 'mysys/queues.c')
-rw-r--r-- | mysys/queues.c | 67 |
1 files changed, 66 insertions, 1 deletions
diff --git a/mysys/queues.c b/mysys/queues.c index 0e4e251f7e7..8e572a0f195 100644 --- a/mysys/queues.c +++ b/mysys/queues.c @@ -19,7 +19,7 @@ Implemention of queues from "Algoritms in C" by Robert Sedgewick. An optimisation of _downheap suggested in Exercise 7.51 in "Data Structures & Algorithms in C++" by Mark Allen Weiss, Second Edition - was implemented by Mikael Ronström 2005. Also the O(N) algorithm + was implemented by Mikael Ronstrom 2005. Also the O(N) algorithm of queue_fix was implemented. */ @@ -67,6 +67,46 @@ int init_queue(QUEUE *queue, uint max_elements, uint offset_to_key, } + +/* + Init queue, uses init_queue internally for init work but also accepts + auto_extent as parameter + + SYNOPSIS + init_queue_ex() + queue Queue to initialise + max_elements Max elements that will be put in queue + offset_to_key Offset to key in element stored in queue + Used when sending pointers to compare function + max_at_top Set to 1 if you want biggest element on top. + compare Compare function for elements, takes 3 arguments. + first_cmp_arg First argument to compare function + auto_extent When the queue is full and there is insert operation + extend the queue. + + NOTES + Will allocate max_element pointers for queue array + + RETURN + 0 ok + 1 Could not allocate memory +*/ + +int init_queue_ex(QUEUE *queue, uint max_elements, uint offset_to_key, + pbool max_at_top, int (*compare) (void *, byte *, byte *), + void *first_cmp_arg, uint auto_extent) +{ + int ret; + DBUG_ENTER("init_queue_ex"); + + if ((ret= init_queue(queue, max_elements, offset_to_key, max_at_top, compare, + first_cmp_arg))) + DBUG_RETURN(ret); + + queue->auto_extent= auto_extent; + DBUG_RETURN(0); +} + /* Reinitialize queue for other usage @@ -192,6 +232,31 @@ void queue_insert(register QUEUE *queue, byte *element) } } +/* + Does safe insert. If no more space left on the queue resize it. + Return codes: + 0 - OK + 1 - Cannot allocate more memory + 2 - auto_extend is 0, the operation would + +*/ + +int queue_insert_safe(register QUEUE *queue, byte *element) +{ + + if (queue->elements == queue->max_elements) + { + if (!queue->auto_extent) + return 2; + else if (resize_queue(queue, queue->max_elements + queue->auto_extent)) + return 1; + } + + queue_insert(queue, element); + return 0; +} + + /* Remove item from queue */ /* Returns pointer to removed element */ |