refclock_shm.c (82498) | refclock_shm.c (132451) |
---|---|
1/* 2 * refclock_shm - clock driver for utc via shared memory 3 * - under construction - 4 * To add new modes: Extend or union the shmTime-struct. Do not 5 * extend/shrink size, because otherwise existing implementations 6 * will specify wrong size of shared memory-segment 7 * PB 18.3.97 8 */ --- 73 unchanged lines hidden (view full) --- 82 time_t receiveTimeStampSec; 83 int receiveTimeStampUSec; 84 int leap; 85 int precision; 86 int nsamples; 87 int valid; 88 int dummy[10]; 89}; | 1/* 2 * refclock_shm - clock driver for utc via shared memory 3 * - under construction - 4 * To add new modes: Extend or union the shmTime-struct. Do not 5 * extend/shrink size, because otherwise existing implementations 6 * will specify wrong size of shared memory-segment 7 * PB 18.3.97 8 */ --- 73 unchanged lines hidden (view full) --- 82 time_t receiveTimeStampSec; 83 int receiveTimeStampUSec; 84 int leap; 85 int precision; 86 int nsamples; 87 int valid; 88 int dummy[10]; 89}; |
90 91struct shmTime *getShmTime(int); 92 |
|
90struct shmTime *getShmTime (int unit) { 91#ifndef SYS_WINNT 92 int shmid=0; 93 94 assert (unit<10); /* MAXUNIT is 4, so should never happen */ 95 shmid=shmget (0x4e545030+unit, sizeof (struct shmTime), 96 IPC_CREAT|(unit<2?0700:0777)); 97 if (shmid==-1) { /*error */ --- 46 unchanged lines hidden (view full) --- 144 FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, 145 0, GetLastError (), 0, buf, sizeof (buf), 0); 146 msyslog(LOG_ERR,"SHM MapViewOfFile (unit %d): %s",unit,buf); 147 return 0; 148 } 149 return p; 150 } 151#endif | 93struct shmTime *getShmTime (int unit) { 94#ifndef SYS_WINNT 95 int shmid=0; 96 97 assert (unit<10); /* MAXUNIT is 4, so should never happen */ 98 shmid=shmget (0x4e545030+unit, sizeof (struct shmTime), 99 IPC_CREAT|(unit<2?0700:0777)); 100 if (shmid==-1) { /*error */ --- 46 unchanged lines hidden (view full) --- 147 FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, 148 0, GetLastError (), 0, buf, sizeof (buf), 0); 149 msyslog(LOG_ERR,"SHM MapViewOfFile (unit %d): %s",unit,buf); 150 return 0; 151 } 152 return p; 153 } 154#endif |
152 return 0; | |
153} 154/* 155 * shm_start - attach to shared memory 156 */ 157static int 158shm_start( 159 int unit, 160 struct peer *peer --- 35 unchanged lines hidden (view full) --- 196 ) 197{ 198 register struct shmTime *up; 199 struct refclockproc *pp; 200 201 pp = peer->procptr; 202 up = (struct shmTime *)pp->unitptr; 203#ifndef SYS_WINNT | 155} 156/* 157 * shm_start - attach to shared memory 158 */ 159static int 160shm_start( 161 int unit, 162 struct peer *peer --- 35 unchanged lines hidden (view full) --- 198 ) 199{ 200 register struct shmTime *up; 201 struct refclockproc *pp; 202 203 pp = peer->procptr; 204 up = (struct shmTime *)pp->unitptr; 205#ifndef SYS_WINNT |
204 shmdt (up); | 206 /* HMS: shmdt()wants char* or const void * */ 207 (void) shmdt (up); |
205#else 206 UnmapViewOfFile (up); 207#endif 208} 209 210 211/* 212 * shm_poll - called by the transmit procedure --- 54 unchanged lines hidden (view full) --- 267 pp->lastrec.l_ui += JAN_1970; 268 /* pp->lasttime = current_time; */ 269 pp->polls++; 270 t=gmtime (&tvt.tv_sec); 271 pp->day=t->tm_yday+1; 272 pp->hour=t->tm_hour; 273 pp->minute=t->tm_min; 274 pp->second=t->tm_sec; | 208#else 209 UnmapViewOfFile (up); 210#endif 211} 212 213 214/* 215 * shm_poll - called by the transmit procedure --- 54 unchanged lines hidden (view full) --- 270 pp->lastrec.l_ui += JAN_1970; 271 /* pp->lasttime = current_time; */ 272 pp->polls++; 273 t=gmtime (&tvt.tv_sec); 274 pp->day=t->tm_yday+1; 275 pp->hour=t->tm_hour; 276 pp->minute=t->tm_min; 277 pp->second=t->tm_sec; |
275 pp->msec=0; 276 pp->usec=tvt.tv_usec; | 278 pp->nsec=tvt.tv_usec * 1000; |
277 peer->precision=up->precision; 278 pp->leap=up->leap; 279 } 280 else { 281 refclock_report(peer, CEVNT_FAULT); 282 msyslog (LOG_NOTICE, "SHM: access clash in shared memory"); 283 return; 284 } 285 } 286 else { 287 refclock_report(peer, CEVNT_TIMEOUT); | 279 peer->precision=up->precision; 280 pp->leap=up->leap; 281 } 282 else { 283 refclock_report(peer, CEVNT_FAULT); 284 msyslog (LOG_NOTICE, "SHM: access clash in shared memory"); 285 return; 286 } 287 } 288 else { 289 refclock_report(peer, CEVNT_TIMEOUT); |
290 /* |
|
288 msyslog (LOG_NOTICE, "SHM: no new value found in shared memory"); | 291 msyslog (LOG_NOTICE, "SHM: no new value found in shared memory"); |
292 */ |
|
289 return; 290 } 291 if (!refclock_process(pp)) { 292 refclock_report(peer, CEVNT_BADTIME); 293 return; 294 } | 293 return; 294 } 295 if (!refclock_process(pp)) { 296 refclock_report(peer, CEVNT_BADTIME); 297 return; 298 } |
299 pp->lastref = pp->lastrec; |
|
295 refclock_receive(peer); 296} 297 298#else 299int refclock_shm_bs; 300#endif /* REFCLOCK */ | 300 refclock_receive(peer); 301} 302 303#else 304int refclock_shm_bs; 305#endif /* REFCLOCK */ |