From 3a71ecb759576e52dbd35e3221ce74b94810d731 Mon Sep 17 00:00:00 2001
From: Cedric Roux <cedric.roux@eurecom.fr>
Date: Tue, 31 May 2016 15:47:55 +0200
Subject: [PATCH] remove T_USE_SHARED_MEMORY

The T only works when it's TRUE, the version without shared memory
is not supported anymore.
---
 cmake_targets/CMakeLists.txt         |  1 -
 common/utils/T/Makefile              |  2 --
 common/utils/T/T.c                   | 43 ----------------------------
 common/utils/T/T.h                   | 32 ---------------------
 common/utils/T/tracee/Makefile       |  2 +-
 common/utils/T/tracer/Makefile.local |  1 -
 6 files changed, 1 insertion(+), 80 deletions(-)

diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt
index a95994a8b1..2a51f376d8 100644
--- a/cmake_targets/CMakeLists.txt
+++ b/cmake_targets/CMakeLists.txt
@@ -1487,7 +1487,6 @@ set(CMAKE_MODULE_PATH "${OPENAIR_DIR}/cmake_targets/tools/MODULES" "${CMAKE_MODU
 #add the T tracer
 add_boolean_option(T_TRACER True "Activate the T tracer" )
 include_directories("${OPENAIR_DIR}/common/utils/T")
-add_boolean_option(T_USE_SHARED_MEMORY True "Use shared memory to communicate with the T tracer" )
 set(T_SOURCE
     ${OPENAIR_DIR}/common/utils/T/T.c)
 set (T_LIB "-lrt")
diff --git a/common/utils/T/Makefile b/common/utils/T/Makefile
index 6690e7d38d..73c07c7e82 100644
--- a/common/utils/T/Makefile
+++ b/common/utils/T/Makefile
@@ -1,8 +1,6 @@
 CC=gcc
 CFLAGS=-Wall -g -pthread -DT_TRACER
 
-#comment those two lines to NOT use shared memory
-CFLAGS += -DT_USE_SHARED_MEMORY
 LIBS += -lrt
 
 PROG=t
diff --git a/common/utils/T/T.c b/common/utils/T/T.c
index 1a5ff0a54c..61fd554090 100644
--- a/common/utils/T/T.c
+++ b/common/utils/T/T.c
@@ -62,42 +62,6 @@ printf("got mess %d\n", t);
   }
 }
 
-#ifndef T_USE_SHARED_MEMORY
-
-static void *T_send_thread(void *_)
-{
-  while (1) {
-    usleep(5000);
-    __sync_synchronize();
-    while (T_cache[T_busylist_head].busy) {
-      char *b;
-      int l;
-      /* TODO: be sure about those memory barriers - in doubt one is
-       * put here too
-       */
-      __sync_synchronize();
-      b = T_cache[T_busylist_head].buffer;
-      l = T_cache[T_busylist_head].length;
-      while (l) {
-        int done = write(T_socket, b, l);
-        if (done <= 0) {
-          printf("%s:%d:%s: error sending to socket\n",
-                 __FILE__, __LINE__, __FUNCTION__);
-          abort();
-        }
-        b += done;
-        l -= done;
-      }
-      T_cache[T_busylist_head].busy = 0;
-      T_busylist_head++;
-      T_busylist_head &= T_CACHE_SIZE - 1;
-    }
-  }
-  return NULL;
-}
-
-#endif /* T_USE_SHARED_MEMORY */
-
 static void *T_receive_thread(void *_)
 {
   while (1) get_message(T_socket);
@@ -123,9 +87,7 @@ void T_connect_to_tracer(char *addr, int port)
 {
   struct sockaddr_in a;
   int s;
-#ifdef T_USE_SHARED_MEMORY
   int T_shm_fd;
-#endif
   unsigned char *buf;
   int len;
 
@@ -156,7 +118,6 @@ again:
 
   T_socket = s;
 
-#ifdef T_USE_SHARED_MEMORY
   /* setup shared memory */
   T_shm_fd = shm_open(T_SHM_FILENAME, O_RDWR /*| O_SYNC*/, 0666);
   shm_unlink(T_SHM_FILENAME);
@@ -166,11 +127,7 @@ again:
   if (T_cache == NULL)
     { perror(T_SHM_FILENAME); abort(); }
   close(T_shm_fd);
-#endif
 
-#ifndef T_USE_SHARED_MEMORY
-  new_thread(T_send_thread, NULL);
-#endif
   new_thread(T_receive_thread, NULL);
 
   /* trace T_message.txt
diff --git a/common/utils/T/T.h b/common/utils/T/T.h
index 58e0d5a885..13e1cbc3ca 100644
--- a/common/utils/T/T.h
+++ b/common/utils/T/T.h
@@ -127,26 +127,12 @@ extern T_cache_t *T_cache;
 
 #define T_ACTIVE(x) T_active[(intptr_t)x]
 
-#ifdef T_USE_SHARED_MEMORY
-
 #define T_SEND() \
   T_cache[T_LOCAL_slot].length = T_LOCAL_size; \
   __sync_synchronize(); \
   T_cache[T_LOCAL_slot].busy = 1; \
   T_send(T_LOCAL_buf, T_LOCAL_size)
 
-#else /* T_USE_SHARED_MEMORY */
-
-/* when not using shared memory, wait for send to finish */
-#define T_SEND() \
-  T_cache[T_LOCAL_slot].length = T_LOCAL_size; \
-  __sync_synchronize(); \
-  T_cache[T_LOCAL_slot].busy = 1; \
-  T_send(T_LOCAL_buf, T_LOCAL_size); \
-  while (T_cache[T_LOCAL_slot].busy) usleep(1*1000)
-
-#endif /* T_USE_SHARED_MEMORY */
-
 #define T_CHECK_SIZE(len, argnum) \
   if (T_LOCAL_size + (len) > T_BUFFER_MAX) { \
     printf("%s:%d:%s: cannot put argument %d in T macro, not enough space" \
@@ -575,26 +561,8 @@ extern T_cache_t *T_cache;
     } \
   } while (0)
 
-#ifndef T_USE_SHARED_MEMORY
-
-#include <stdio.h>
-
-static inline void T_send(char *buf, int size)
-{
-  int i;
-return;
-  printf("sending %d bytes", size);
-  for (i = 0; i < size; i++)
-    printf("%s%2.2x", i?" ":"\n", (unsigned char)buf[i]);
-  printf("\n");
-}
-
-#else /* T_USE_SHARED_MEMORY */
-
 #define T_send(...) /**/
 
-#endif /* T_USE_SHARED_MEMORY */
-
 extern int *T_active;
 
 void T_connect_to_tracer(char *addr, int port);
diff --git a/common/utils/T/tracee/Makefile b/common/utils/T/tracee/Makefile
index bc7c01d86b..703d49d029 100644
--- a/common/utils/T/tracee/Makefile
+++ b/common/utils/T/tracee/Makefile
@@ -1,5 +1,5 @@
 CC=gcc
-CFLAGS=-Wall -g -pthread -DT_TRACER -DT_USE_SHARED_MEMORY -I.
+CFLAGS=-Wall -g -pthread -DT_TRACER -I.
 
 PROG=tracee
 OBJS=tracee.o ../T.o
diff --git a/common/utils/T/tracer/Makefile.local b/common/utils/T/tracer/Makefile.local
index a34378470b..ae4e248a20 100644
--- a/common/utils/T/tracer/Makefile.local
+++ b/common/utils/T/tracer/Makefile.local
@@ -3,7 +3,6 @@ CFLAGS=-Wall -g -pthread -DT_TRACER
 
 #CFLAGS += -O3 -ffast-math -fomit-frame-pointer
 
-CFLAGS += -DT_USE_SHARED_MEMORY
 LIBS += -lrt
 
 PROG=tracer_local
-- 
GitLab