]> rtime.felk.cvut.cz Git - frescor/fna.git/commitdiff
acquire lock when allocating memory.. (TODO: check tlsf to provide locking) and add...
authorsangorrin <sangorrin@35b4ef3e-fd22-0410-ab77-dab3279adceb>
Mon, 24 Nov 2008 16:42:07 +0000 (16:42 +0000)
committersangorrin <sangorrin@35b4ef3e-fd22-0410-ab77-dab3279adceb>
Mon, 24 Nov 2008 16:42:07 +0000 (16:42 +0000)
git-svn-id: http://www.frescor.org/private/svn/frescor/fna/trunk@1408 35b4ef3e-fd22-0410-ab77-dab3279adceb

src_frescan/frescan.c

index 69f3a2396e0f96db5c1a9ce15b72855500657f10..30f02c2ed04827642710d4ccdb884d4c7846d9d5 100644 (file)
@@ -71,6 +71,7 @@
 #include <unistd.h> // ioctl
 #include <stdlib.h> // malloc
 #include <string.h> // memcpy
+#include <assert.h>
 
 #include <drivers/can.h>       // can_chip_t, can_frame_t
 #include "frescan.h"           // frescan_init_params_t, frescan_send_params_t
@@ -288,7 +289,9 @@ int frescan_send(const frescan_send_params_t *params,
                 // NOTE: instead of this we could use a chain of frames but
                 // i think it would be inefficient since each one can only
                 // hold 8 user bytes and we need to write its headers.
-                packet->buffer_head = (uint8_t *)malloc(size*sizeof(uint8_t));
+                FRESCAN_ACQUIRE_LOCK(&frescan_data[params->net].lock);
+                packet->buffer_head = (uint8_t *)malloc(size*sizeof(uint8_t)); // TODO: FREE IT!!!
+                FRESCAN_RELEASE_LOCK(&frescan_data[params->net].lock);
                 memcpy(packet->buffer_head, msg, size);
         } else {
                 packet->buffer_head = (uint8_t *)msg;
@@ -558,6 +561,7 @@ static int frescan_hook_frame_sent(const struct can_chip_t *chip)
         frescan_ss_t id;
 
         packet = frescan_data[chip->minor].last_packet;
+        assert(packet != NULL);
 
         id = frescan_id_get_field(packet->frame->id,
                                   FRESCAN_FIELD_FRAG_ID);
@@ -592,7 +596,7 @@ static int frescan_hook_frame_sent(const struct can_chip_t *chip)
                         pqueue = frescan_data[chip->minor].queues.tx_fp_queue;
                         ret = frescan_pqueue_requeue(pqueue, packet, prio);
                         if (ret != 0) {
-                                FRESCAN_ERROR("could not requeue the packet\n");
+                                FRESCAN_ERROR("could not requeue the packet packet:%p flags:0x%X\n", packet, packet->flags);
                                 return -1;
                         }
                 } else if (packet->flags & FRESCAN_SS) {