@@ -113,6 +113,17 @@ static void sig_handler(int sig)
113
113
ros::shutdown ();
114
114
}
115
115
116
+ /* *
117
+ * Memory barrier. unfortunatly we can't use C stdatomic.h
118
+ * So only one option: asm magick
119
+ *
120
+ * from gpsd compiler.h
121
+ */
122
+ static inline void memory_barrier (void )
123
+ {
124
+ asm volatile (" " : : : " memory" );
125
+ }
126
+
116
127
static void time_ref_cb (const sensor_msgs::TimeReference::ConstPtr &time_ref)
117
128
{
118
129
if (g_shm == NULL ) {
@@ -122,24 +133,27 @@ static void time_ref_cb(const sensor_msgs::TimeReference::ConstPtr &time_ref)
122
133
123
134
/* header */
124
135
g_shm->mode = 1 ;
125
- g_shm->leap = 0 ; // LEAP_NOWARNING
126
- g_shm->precision = -1 ; // initially 0.5 sec
127
136
g_shm->nsamples = 3 ; // stages of median filter
128
137
129
- /* ntpshm.c recommends add barrier before inc count */
130
138
g_shm->valid = 0 ;
131
139
g_shm->count += 1 ;
132
- g_shm->receiveTimeStampSec = time_ref->header .stamp .sec ;
133
- g_shm->receiveTimeStampUSec = time_ref->header .stamp .nsec / 1000 ;
134
- g_shm->receiveTimeStampNSec = time_ref->header .stamp .nsec ;
140
+ /* barrier */
141
+ memory_barrier ();
135
142
g_shm->clockTimeStampSec = time_ref->time_ref .sec ;
136
143
g_shm->clockTimeStampUSec = time_ref->time_ref .nsec / 1000 ;
137
144
g_shm->clockTimeStampNSec = time_ref->time_ref .nsec ;
145
+ g_shm->receiveTimeStampSec = time_ref->header .stamp .sec ;
146
+ g_shm->receiveTimeStampUSec = time_ref->header .stamp .nsec / 1000 ;
147
+ g_shm->receiveTimeStampNSec = time_ref->header .stamp .nsec ;
148
+ g_shm->leap = 0 ; // LEAP_NOWARNING
149
+ g_shm->precision = -1 ; // initially 0.5 sec
150
+ memory_barrier ();
138
151
/* barrier again */
139
152
g_shm->count += 1 ;
140
153
g_shm->valid = 1 ;
141
154
142
- ROS_DEBUG_THROTTLE (10 , " Got time_ref: %lu.%09lu" ,
155
+ ROS_DEBUG_THROTTLE (10 , " Got time_ref: %s: %lu.%09lu" ,
156
+ time_ref->source .c_str (),
143
157
(long unsigned ) time_ref->time_ref .sec ,
144
158
(long unsigned ) time_ref->time_ref .nsec );
145
159
@@ -204,6 +218,10 @@ int main(int argc, char *argv[])
204
218
nh.param (" fixup_date" , g_set_date, false );
205
219
nh.param <std::string>(" time_ref_topic" , time_ref_topic, " time_ref" );
206
220
221
+ // Report settings
222
+ ROS_INFO_STREAM (" NTP time source: " << ros::names::resolve (time_ref_topic, true ));
223
+ ROS_INFO_STREAM (" NTP date fixup: " << ((g_set_date) ? " enabled" : " disabled" ));
224
+
207
225
g_shm = get_shmTime (shm_unit);
208
226
if (g_shm == NULL )
209
227
return 1 ;
0 commit comments