cm-kernel /drivers/net/wireless/tiwlan1251/CUDK/OAL/Pform/Linux/TILibLinux.cpp

Language C++ Lines 300
MD5 Hash 31998f6fb6ef374b4a21d22472f6a269 Estimated Cost $2,383 (why?)
Repository git://github.com/CyanogenMod/cm-kernel.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/*******************************************************************************
**+--------------------------------------------------------------------------+**
**|                                                                          |**
**| Copyright 1998-2008 Texas Instruments, Inc. - http://www.ti.com/         |**
**|                                                                          |**
**| Licensed under the Apache License, Version 2.0 (the "License");          |**
**| you may not use this file except in compliance with the License.         |**
**| You may obtain a copy of the License at                                  |**
**|                                                                          |**
**|     http://www.apache.org/licenses/LICENSE-2.0                           |**
**|                                                                          |**
**| Unless required by applicable law or agreed to in writing, software      |**
**| distributed under the License is distributed on an "AS IS" BASIS,        |**
**| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |**
**| See the License for the specific language governing permissions and      |**
**| limitations under the License.                                           |**
**|                                                                          |**
**+--------------------------------------------------------------------------+**
*******************************************************************************/

// TILibLinux.cpp :
//
#include <stdio.h>
#include <errno.h>
#include <time.h>

#include "CommonOAL.h"
#include "TILibLinux.h"
#include <pthread.h>

//////////////////////////////////////////////////////////////////////
// CTI_LibLinux Class
//////////////////////////////////////////////////////////////////////
TIOALib_SINGLETON_CLASS_IMP( CTI_LibLinux )
TIOALib_OBJECT_CREATOR_IMP( CTI_OSCriticalSectionLinux, TI_OSWrapCriticalSection )

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CTI_LibLinux::CTI_LibLinux()
{
}

CTI_LibLinux::~CTI_LibLinux()
{
}

tiVOID        
CTI_LibLinux::TIOutputDebugString (tiCHAR* lpOutputString)
{
    if ( lpOutputString )
        fprintf(stderr, lpOutputString);
}

tiUINT32   
CTI_LibLinux::TILoadLibrary(tiCHAR* lpLibFileName)
{
    return 0;
}
tiUINT32
CTI_LibLinux::TIGetCurrentThreadId()
{
    return pthread_self();
}

tiBOOL        
CTI_LibLinux::TIFreeLibrary( tiUINT32 hLibModule )
{
    return 0;
}

tiUINT32        
CTI_LibLinux::TIRegisterWindowMessage (tiCHAR* lpszMsgName)
{
    return 0;
}

tiBOOL        
CTI_LibLinux::TIPostMessage(tiUINT32 hWnd, tiUINT32 uMsg, tiUINT32 wParam, tiUINT32 lParam)
{
    return 0;
}

tiUINT32 
CTI_LibLinux::TIGetProcAddress(tiUINT32 hModule, tiCHAR* lpProcName )
{
    return 0;
}

tiBOOL
CTI_LibLinux::TIIsBadWritePtr(tiVOID *lp, tiUINT32 ucb )
{
    return FALSE;   //IsBadWritePtr(lp, ucb );
}

tiVOID
CTI_LibLinux::TIPrintLastError(tiCHAR* lpsz)
{
#ifdef DEBUG_MESSAGES    
    tiCHAR szTmp[512];
    sprintf(szTmp,"%s LastError(0x%Xh)\n", lpsz, errno);
    TIOutputDebugString(szTmp);
#endif
}


tiUINT32
CTI_LibLinux::TICreateThread(tiPTHREAD_START_ROUTINE pStartAddress, tiVOID* pParameter )
{
    uxTHREAD_START_ROUTINE  thread_start_address = (uxTHREAD_START_ROUTINE)pStartAddress;
    pthread_t               supp_thread_id;
    pthread_attr_t          supp_thread_attrs;

    pthread_attr_init(&supp_thread_attrs);

    int iRet = pthread_create(&supp_thread_id, &supp_thread_attrs, thread_start_address, pParameter);

    pthread_attr_destroy(&supp_thread_attrs);

    if ( iRet == 0)
        return TI_RESULT_OK;

    return TI_RESULT_FAILED;
}


CTI_OSCriticalSectionLinux::CTI_OSCriticalSectionLinux()
{
  /*  m_pCS = (tiVOID*) new pthread_rwlock_t;

    if ( m_pCS )
    {
        memset( m_pCS, 0, sizeof(pthread_rwlock_t));
        pthread_rwlock_init((pthread_rwlock_t*) m_pCS, NULL )
    }
    */
}

CTI_OSCriticalSectionLinux::~CTI_OSCriticalSectionLinux()
{
    /*
    if (m_pCS)
    {
        pthread_rwlock_destroy((pthread_rwlock_t*) m_pCS);
        delete m_pCS;
        m_pCS = NULL;
    }
    */
}

tiVOID
CTI_OSCriticalSectionLinux::Enter()
{
    /*
    if ( m_pCS )
        pthread_rwlock_wrlock((pthread_rwlock_t*) m_pCS);
    */
}

tiVOID
CTI_OSCriticalSectionLinux::Leave()
{
    /*
    if ( m_pCS )
        pthread_rwlock_unlock((pthread_rwlock_t*) m_pCS);
    */
}

tiVOID
CTI_LibLinux::TISleep(tiUINT32 msec)
{
    struct timespec req;

    req.tv_sec = 0;
    req.tv_nsec = 100000; /* sleep for 100 msec */
    nanosleep( &req, NULL );
}

/*

CTI_OSEventLinux::CTI_OSEventLinux()
{   
    m_bSet = FALSE;

    pthread_condattr_init(&m_CondAttr); 
    pthread_cond_init(&m_Cond, &m_CondAttr);
    
    pthread_mutexattr_init(&m_MutexAttr);
    pthread_mutexattr_settype(&m_MutexAttr, PTHREAD_MUTEX_NORMAL);

    m_pEvent = (tiVOID*) new pthread_mutex_t;

    if ( m_pEvent )
    {
        memset( m_pEvent, 0, sizeof(pthread_mutex_t));
        pthread_mutex_init( (pthread_mutex_t*) m_pEvent, &m_MutexAttr);
    }
}

CTI_OSEventLinux::~CTI_OSEventLinux()
{
    if (m_pEvent)
    {
        pthread_mutex_destroy((pthread_mutex_t*) m_pEvent);
        delete m_pEvent;
        m_pEvent = NULL;
    }

    pthread_mutexattr_destroy(&m_attr);
    pthread_cond_destroy(&m_Cond);
    pthread_condattr_destroy(&m_CondAttr);  
}

tiVOID
CTI_OSEventLinux::Set()
{
    if ( m_pEvent )
        pthread_cond_signal((pthread_mutex_t*) m_pEvent);
}

tiUINT32
CTI_OSEventLinux::Wait(tiUINT32 uTimeout)
{
    if (m_pEvent)
    {
        pthread_mutex_lock((pthread_mutex_t*) m_pEvent);

        if (uTimeout == INFINITE)
        {
            while (!m_bSet) // have to wait for the event
                pthread_cond_wait(&m_Cond, (pthread_mutex_t*) m_pEvent );
        }
        else
        {
            timespec  timeOut;
            clock_gettime(CLOCK_REALTIME, &timeOut);
            
            // if there are seconds involved
            if (uTimeout >= 1000)
            {
                timeOut.tv_sec += uTimeout / 1000;
        
                // get rest
                int nRemain = nMilliseconds % 1000;
                if (nRemain != 0)
                {
                    timeOut.tv_nsec +=  nRemain * 1000000L;
            
                    // wrapped into the next second
                    if (timeOut.tv_nsec > 1000000000L)
                    {
                        timeOut.tv_nsec -= 1000000000L;
                        timeOut.tv_sec++;
                    }
                }
            }
            else
            {
                timeOut.tv_nsec +=  uTimeout * 1000000L;
            }

            while (!m_bSet) // have to wait for the event
            {
                // the following line releases the mutex and waits until the 
                // condition is signalled.  when the call returns, we own the
                // mutex again, unless an exception is thrown, in which case
                // the mutex is unlocked

                int nResult = pthread_cond_timedwait(&m_Cond, (pthread_mutex_t*) m_pEvent , &timeOut));
            
                if ( nResult != 0 ) 
                {
                    pthread_mutex_unlock((pthread_mutex_t*) m_pEvent);
                    // time out, we have the lock
                    pthread_mutex_lock((pthread_mutex_t*) m_pEvent);
                          
                    // return "time out" condition
                    return;  
               }

        }
};

inline _dcfTimeOut::_dcfTimeOut(unsigned int nMilliseconds)
{
    int nResult = clock_gettime(CLOCK_REALTIME, &_tsWhen);
    
#ifdef _DEBUG
    DCF_ASSERT(nResult == 0);
#endif
    
    
}
    }
    return TI_RESULT_OK;
}
*/
Back to Top