PUD: remove unneeded mutex on the position average list
authorFerry Huberts <ferry.huberts@pelagic.nl>
Tue, 6 Mar 2012 11:52:15 +0000 (12:52 +0100)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Tue, 6 Mar 2012 13:17:15 +0000 (14:17 +0100)
The list is only accesses from a single place

Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/pud/src/posAvg.c
lib/pud/src/posAvg.h
lib/pud/src/receiver.c

index 6892670..132ce96 100644 (file)
@@ -31,8 +31,6 @@
 void flushPositionAverageList(PositionAverageList * positionAverageList) {
        assert (positionAverageList != NULL);
 
-       (void) pthread_mutex_lock(&positionAverageList->mutex);
-
        positionAverageList->entriesCount = 0;
        memset(&positionAverageList->counters, 0,
                        sizeof(positionAverageList->counters));
@@ -40,8 +38,6 @@ void flushPositionAverageList(PositionAverageList * positionAverageList) {
        nmea_zero_INFO(&positionAverageList->positionAverageCumulative.nmeaInfo);
        nmea_zero_INFO(&positionAverageList->positionAverage.nmeaInfo);
 
-       (void) pthread_mutex_unlock(&positionAverageList->mutex);
-
 #if defined(PUD_DUMP_AVERAGING)
        olsr_printf(0, "flushPositionAverageList: Flushed the averaging list\n");
 #endif /* PUD_DUMP_AVERAGING */
@@ -63,7 +59,6 @@ void flushPositionAverageList(PositionAverageList * positionAverageList) {
  */
 bool initPositionAverageList(PositionAverageList * positionAverageList,
                unsigned long long maxEntries) {
-       pthread_mutexattr_t attr;
        void * p;
 
        if (positionAverageList == NULL) {
@@ -73,16 +68,6 @@ bool initPositionAverageList(PositionAverageList * positionAverageList,
                return false;
        }
 
-       if (pthread_mutexattr_init(&attr)) {
-               return false;
-       }
-       if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP)) {
-               return false;
-       }
-       if (pthread_mutex_init(&positionAverageList->mutex, &attr)) {
-               return false;
-       }
-
        p = olsr_malloc((maxEntries + 1) * sizeof(PositionUpdateEntry),
                        "PositionAverageEntry entries for PositionAverageList (PUD)");
        if (p == NULL) {
@@ -107,8 +92,6 @@ bool initPositionAverageList(PositionAverageList * positionAverageList,
 void destroyPositionAverageList(PositionAverageList * positionAverageList) {
        assert (positionAverageList != NULL);
 
-       (void) pthread_mutex_lock(&positionAverageList->mutex);
-
        flushPositionAverageList(positionAverageList);
 
        if (positionAverageList->entries != NULL) {
@@ -118,10 +101,6 @@ void destroyPositionAverageList(PositionAverageList * positionAverageList) {
 
        positionAverageList->entriesMaxCount = 0;
        positionAverageList->newestEntryIndex = 0;
-
-       (void) pthread_mutex_unlock(&positionAverageList->mutex);
-
-       pthread_mutex_destroy(&positionAverageList->mutex);
 }
 
 /**
@@ -140,7 +119,6 @@ PositionUpdateEntry * getPositionAverageEntry(
                AverageEntryPositionType positionType) {
        PositionUpdateEntry * r = NULL;
 
-       (void) pthread_mutex_lock(&positionAvgList->mutex);
        switch (positionType) {
                case OLDEST:
                        assert(positionAvgList->entriesCount >= positionAvgList->entriesMaxCount);
@@ -167,7 +145,6 @@ PositionUpdateEntry * getPositionAverageEntry(
                        r = NULL;
                        break;
        }
-       (void) pthread_mutex_unlock(&positionAvgList->mutex);
 
        return r;
 }
@@ -523,8 +500,6 @@ void addNewPositionToAverage(PositionAverageList * positionAverageList,
        dump_nmeaInfo(&positionAverageList->positionAverageCumulative.nmeaInfo, "addNewPositionToAverage: positionAverageList->positionAverageCumulative.nmeaInfo (before)");
 #endif /* PUD_DUMP_AVERAGING */
 
-       (void) pthread_mutex_lock(&positionAverageList->mutex);
-
        if (positionAverageList->entriesCount
                        >= positionAverageList->entriesMaxCount) {
                /* list is full, so first remove the oldest from the average */
@@ -550,6 +525,4 @@ void addNewPositionToAverage(PositionAverageList * positionAverageList,
 #if defined(PUD_DUMP_AVERAGING)
        dump_nmeaInfo(&positionAverageList->positionAverage.nmeaInfo, "addNewPositionToAverage: positionAverageList->positionAverage.nmeaInfo (after)");
 #endif /* PUD_DUMP_AVERAGING */
-
-       (void) pthread_mutex_unlock(&positionAverageList->mutex);
 }
index 488288f..052b258 100644 (file)
@@ -59,8 +59,6 @@ typedef struct _PositionUpdateCounters {
  calculations to be performed.
  */
 typedef struct _PositionAverageList {
-               pthread_mutex_t mutex; /**< access mutex */
-
                unsigned long long entriesMaxCount; /**< the maximum number of entries in the list */
                PositionUpdateEntry * entries; /**< the list entries */
 
index 3f8fd2a..e67d8af 100644 (file)
@@ -724,8 +724,6 @@ bool receiverUpdateGpsInformation(unsigned char * rxBuffer, size_t rxCount) {
        memcpy(&txGateway, &transmitGpsInformation.txGateway, olsr_cnf->ipsize);
        (void) pthread_mutex_unlock(&transmitGpsInformation.mutex);
 
-       (void) pthread_mutex_lock(&positionAverageList.mutex);
-
        /* parse all NMEA strings in the rxBuffer into the incoming entry */
        incomingEntry = getPositionAverageEntry(&positionAverageList, INCOMING);
        nmea_zero_INFO(&incomingEntry->nmeaInfo);
@@ -893,7 +891,7 @@ bool receiverUpdateGpsInformation(unsigned char * rxBuffer, size_t rxCount) {
 
        retval = true;
 
-       end: (void) pthread_mutex_unlock(&positionAverageList.mutex);
+       end:
        return retval;
 }