X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fjtag%2Fcommands.c;h=750ebab0d6eab01bd661aaa79e8a00aae09f8d38;hb=8f26fa3c0ff7f3f43920165c75e757399742c1c8;hp=546b12f8bfef0d935018b806895f3c0e9c34c8bc;hpb=38f8e5eefac748a30a4bf5e9d7a7313c8ae0e4e9;p=fw%2Fopenocd diff --git a/src/jtag/commands.c b/src/jtag/commands.c index 546b12f8b..750ebab0d 100644 --- a/src/jtag/commands.c +++ b/src/jtag/commands.c @@ -25,7 +25,7 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * ***************************************************************************/ #ifdef HAVE_CONFIG_H @@ -36,13 +36,14 @@ #include "commands.h" struct cmd_queue_page { + struct cmd_queue_page *next; void *address; size_t used; - struct cmd_queue_page *next; }; #define CMD_QUEUE_PAGE_SIZE (1024 * 1024) static struct cmd_queue_page *cmd_queue_pages; +static struct cmd_queue_page *cmd_queue_pages_tail; struct jtag_command *jtag_command_queue; static struct jtag_command **next_command_pointer = &jtag_command_queue; @@ -100,8 +101,7 @@ void *cmd_queue_alloc(size_t size) /* Done... */ if (*p_page) { - while ((*p_page)->next) - p_page = &((*p_page)->next); + p_page = &cmd_queue_pages_tail; if (CMD_QUEUE_PAGE_SIZE - (*p_page)->used < size) p_page = &((*p_page)->next); } @@ -109,14 +109,17 @@ void *cmd_queue_alloc(size_t size) if (!*p_page) { *p_page = malloc(sizeof(struct cmd_queue_page)); (*p_page)->used = 0; - (*p_page)->address = malloc(CMD_QUEUE_PAGE_SIZE); + size_t alloc_size = (size < CMD_QUEUE_PAGE_SIZE) ? + CMD_QUEUE_PAGE_SIZE : size; + (*p_page)->address = malloc(alloc_size); (*p_page)->next = NULL; + cmd_queue_pages_tail = *p_page; } offset = (*p_page)->used; (*p_page)->used += size; - t = (uint8_t *)((*p_page)->address); + t = (*p_page)->address; return t + offset; } @@ -132,6 +135,7 @@ static void cmd_queue_free(void) } cmd_queue_pages = NULL; + cmd_queue_pages_tail = NULL; } void jtag_command_queue_reset(void)