#define FSM(id) (&robot.fsm[FSM_ID_##id])
#define FSM_GET_BY_ID(fsm_id) (&robot.fsm[FSM_ID_##fsm_id])
-/**
- * LOCKING MANIPULATION
- */
-
-/**
- * Locks the robot structure.
- * @param var Field in the structure you are going to work with.
- */
-#define ROBOT_LOCK(var) (pthread_mutex_lock(&robot.__robot_lock_##var))
-
-/**
- * Unlocks the robot structure.
- * @param var Field in the structure, which was locked by ROBOT_LOCK.
- */
-#define ROBOT_UNLOCK(var) (pthread_mutex_unlock(&robot.__robot_lock_##var))
-
/**
* DEBUG MACROS
*/
#SUBDIRS = test
-default_CONFIG = CONFIG_OPEN_LOOP=n
-LOCAL_CONFIG_H = robot_config.h
+default_CONFIG = CONFIG_OPEN_LOOP=n CONFIG_LOCK_CHECKING=n
+
+config_include_HEADERS = robot_config.h
+robot_config_DEFINES = CONFIG_OPEN_LOOP CONFIG_LOCK_CHECKING
bin_PROGRAMS += robomain
robomain_SOURCES = fsmmain.cc
#include <roboevent_eb2008.h>
#include <fsm.h>
#include <servos_eb2008.h>
+#include <robot_config.h>
/* Select robot color. If we are BLUE, no coordinate transformation will
* be performed. */
#define LAS_MEAS_PERI 1 /* period index */
#define LAS_MEAS_DATAI 2 /* data index */
+/**
+ * LOCKING MANIPULATION
+ */
+
+#ifdef CONFIG_LOCK_CHECKING
+#define LOCK_CHECK_COUNT 10
+struct lock_log {
+ pthread_mutex_t *locked[LOCK_CHECK_COUNT];
+ int idx;
+};
+
+extern struct lock_log robot_lock_log;
+
+#define __LOCK_CHECK(mutex) robot_lock_log.locked[robot_lock_log.idx++] = mutex;
+#define __UNLOCK_CHECK(mutex) \
+ if (robot_lock_log.locked[--robot_lock_log.idx] != mutex || \
+ robot_lock_log.idx < 0) \
+ printf("!!! Locking error %s:%d\n", __FILE__, __LINE__);
+#else
+#define __LOCK_CHECK(mutex)
+#define __UNLOCK_CHECK(mutex)
+#endif
+/**
+ * Locks the robot structure.
+ * @param var Field in the structure you are going to work with.
+ */
+#define ROBOT_LOCK(var) \
+ do { \
+ pthread_mutex_lock(&robot.__robot_lock_##var); \
+ __LOCK_CHECK(&robot.__robot_lock_##var); \
+ } while(0)
+
+/**
+ * Unlocks the robot structure.
+ * @param var Field in the structure, which was locked by ROBOT_LOCK.
+ */
+#define ROBOT_UNLOCK(var) \
+ do { \
+ __UNLOCK_CHECK(&robot.__robot_lock_##var); \
+ pthread_mutex_unlock(&robot.__robot_lock_##var); \
+ } while(0)
+
/* Mapping of robot structure fields to locks */
//#define __robot_lock_ lock /* ROBOT_LOCK() */
#define __robot_lock_ref_pos lock_ref_pos