* GNU General Public License for more details. *
* *
* 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. *
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#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;
/* 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);
}
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;
}
}
cmd_queue_pages = NULL;
+ cmd_queue_pages_tail = NULL;
}
void jtag_command_queue_reset(void)