diff options
author | Jean-Baptiste Maillet <jean-baptiste.maillet@parrot.com> | 2014-11-28 15:24:44 +0100 |
---|---|---|
committer | Jean-Baptiste Maillet <jean-baptiste.maillet@parrot.com> | 2014-11-28 15:24:44 +0100 |
commit | 089b79d59ba2fad239691ce8a7e3b8314f15c1a4 (patch) | |
tree | 3691b49465a4b00ff5a6db756e6c852f77f7284b | |
parent | ab8c2eeca4e10426d176c3543fa2abc0b90afb1d (diff) | |
download | Open-AVB-089b79d59ba2fad239691ce8a7e3b8314f15c1a4.tar.gz |
simple_talker: make igb shared memory not global
-rwxr-xr-x | examples/simple_talker/simple_talker.c | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/examples/simple_talker/simple_talker.c b/examples/simple_talker/simple_talker.c index c4715205..296eb47c 100755 --- a/examples/simple_talker/simple_talker.c +++ b/examples/simple_talker/simple_talker.c @@ -164,7 +164,6 @@ typedef struct __attribute__ ((packed)) { static const char *version_str = "simple_talker v" VERSION_STR "\n" "Copyright (c) 2012, Intel Corporation\n"; -static int glob_shm_fd = -1; static char *glob_memory_offset_buffer = NULL; unsigned char glob_station_addr[] = { 0, 0, 0, 0, 0, 0 }; unsigned char glob_stream_id[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; @@ -255,16 +254,19 @@ static inline uint64_t ST_rdtsc(void) return ret; } -int gptpinit(void) +int gptpinit(int *igb_shm_fd) { - glob_shm_fd = shm_open(SHM_NAME, O_RDWR, 0); - if (glob_shm_fd == -1) { + if (NULL == igb_shm_fd) + return -1; + + *igb_shm_fd = shm_open(SHM_NAME, O_RDWR, 0); + if (*igb_shm_fd == -1) { perror("shm_open()"); return -1; } glob_memory_offset_buffer = (char *)mmap(NULL, SHM_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, - glob_shm_fd, 0); + *igb_shm_fd, 0); if (glob_memory_offset_buffer == (char *)-1) { perror("mmap()"); glob_memory_offset_buffer = NULL; @@ -275,14 +277,20 @@ int gptpinit(void) return 0; } -void gptpdeinit(void) +int gptpdeinit(int *igb_shm_fd) { + if (NULL == igb_shm_fd) + return -1; + if (glob_memory_offset_buffer != NULL) { munmap(glob_memory_offset_buffer, SHM_SIZE); } - if (glob_shm_fd != -1) { - close(glob_shm_fd); + if (*igb_shm_fd != -1) { + close(*igb_shm_fd); + *igb_shm_fd = -1; } + + return 0; } int gptpscaling(gPtpTimeData *td) @@ -433,6 +441,7 @@ int main(int argc, char *argv[]) unsigned i; int err; device_t igb_dev; + int igb_shm_fd = -1; struct igb_dma_alloc a_page; struct igb_packet a_packet; struct igb_packet *tmp_packet; @@ -760,7 +769,7 @@ int main(int argc, char *argv[]) printf("got a listener ...\n"); halt_tx = 0; - if(-1 == gptpinit()) { + if(-1 == gptpinit(&igb_shm_fd)) { return EXIT_FAILURE; } @@ -921,7 +930,7 @@ int main(int argc, char *argv[]) rc = mrp_disconnect(); igb_dma_free_page(&igb_dev, &a_page); - + rc = gptpdeinit(&igb_shm_fd); err = igb_detach(&igb_dev); pthread_exit(NULL); |