1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
17 *******************************************************************************/
19 /********************************************************************20**
21 Name: Radisys Logging Framework
23 Desc: This file contains logging framework implementation.
26 *********************************************************************21*/
27 /**************************************************************************
28 @ description: This is source file which has implementaion of logging
30 ****************************************************************************/
32 #include "rl_interface.h"
36 #include <sys/socket.h>
37 #include <sys/types.h>
39 #include <sys/resource.h>
45 #include <netinet/in.h>
49 #include "rl_platform.h"
51 /* VARIABLE DECLARATION SECTION */
53 /* Thread-specific data key visible to all threads */
54 static pthread_key_t g_threadkey;
56 extern pthread_mutex_t g_logmutex;
57 extern THREAD_DATA* g_pCirList[RLOG_MAX_THREADS];
58 void* rlAlloc(size_t mem_size)
60 return malloc(mem_size);
63 void rlFree(void* pMem)
68 void* rlCalloc(size_t mem_size)
70 return calloc(mem_size, 1);
73 void rlSetThreadSpecificData(const void *pThrData)
75 int retVal = pthread_setspecific(g_threadkey, pThrData);
78 fprintf(stderr, "Failed to associate the value with the key or invalid key");
83 #ifdef RLOG_USE_CIRCULAR_BUFFER
84 /*******************************************************************************************
85 @param[in] pThreadData - Thread specific data
86 @brief This function is called whenever thread is being destroyed. This function will delete
87 thread specific data allocated during thread registration.
88 ********************************************************************************************/
89 void deInitThread(void* pThreadData)
92 THREAD_DATA* pThrData = (THREAD_DATA*)(pThreadData);
94 if( pThreadData == NULL )
97 /* lock the mutex, to make sure no one is accessing this buffer */
98 pthread_mutex_lock(&g_logmutex);
100 g_pCirList[pThrData->listIndex] = NULL;
102 if( pThrData->logBuff != NULL )
103 rlFree(pThrData->logBuff);
107 /* unlock the mutex */
108 pthread_mutex_unlock(&g_logmutex);
112 void* rlGetThreadSpecData(void)
114 return (void*) pthread_getspecific(g_threadkey);
117 void rlInitPlatformSpecific(void)
119 #ifdef RLOG_USE_CIRCULAR_BUFFER
120 pthread_key_create(&g_threadkey, &deInitThread);
124 /**********************************************************************
126 **********************************************************************/