|
Lines 71-77
Link Here
|
| 71 |
enum ThreadStatus { IDLE, RUNNING } ; |
71 |
enum ThreadStatus { IDLE, RUNNING } ; |
| 72 |
|
72 |
|
| 73 |
static int acShmMemCount = 0; |
73 |
static int acShmMemCount = 0; |
|
|
74 |
static int shMemInitialized = 0; |
| 74 |
|
75 |
|
|
|
76 |
void destroyMem (mem_map_block_ptr_t pMemBlockInfo); |
| 77 |
|
| 78 |
extern void ossSleep (long ms); |
| 75 |
|
79 |
|
| 76 |
/*====================================================================*/ |
80 |
/*====================================================================*/ |
| 77 |
/* internal function prototypes */ |
81 |
/* internal function prototypes */ |
|
Lines 224-233
Link Here
|
| 224 |
else |
228 |
else |
| 225 |
{ |
229 |
{ |
| 226 |
pServerData->serverMemInfo = memBlockInfo ; |
230 |
pServerData->serverMemInfo = memBlockInfo ; |
|
|
231 |
shMemInitialized = 1; |
| 227 |
|
232 |
|
| 228 |
/* attach to this block so that it will not be deleted */ |
|
|
| 229 |
ipcMemOpen(pServerData->sharedMemName, &memBlockInfo); |
| 230 |
|
| 231 |
/* create new thread to listen to connection request */ |
233 |
/* create new thread to listen to connection request */ |
| 232 |
rc = startNewThread(doListening, |
234 |
rc = startNewThread(doListening, |
| 233 |
(LPVOID) pServerData, &threadId, &threadHandle) ; |
235 |
(LPVOID) pServerData, &threadId, &threadHandle) ; |
|
Lines 250-260
Link Here
|
| 250 |
|
252 |
|
| 251 |
tptp_int32 stopSharedMemListener(server_block_t* pServerData) |
253 |
tptp_int32 stopSharedMemListener(server_block_t* pServerData) |
| 252 |
{ |
254 |
{ |
|
|
255 |
int cnt; |
| 256 |
|
| 253 |
pServerData->threadStatus = IDLE ; |
257 |
pServerData->threadStatus = IDLE ; |
|
|
258 |
ipcStopFlusher (&pServerData->serverMemInfo); |
| 254 |
|
259 |
|
|
|
260 |
cnt = 20; |
| 261 |
while (shMemInitialized && cnt-- > 0) { // wait 2 sec for flusher termination |
| 262 |
ossSleep (100L); |
| 263 |
} |
| 264 |
|
| 265 |
if (shMemInitialized) { |
| 266 |
destroyMem (&pServerData->serverMemInfo); |
| 267 |
} |
| 268 |
|
| 255 |
return 0 ; |
269 |
return 0 ; |
| 256 |
} |
270 |
} |
| 257 |
|
271 |
|
|
|
272 |
/** |
| 273 |
********************************************************* |
| 274 |
* |
| 275 |
* @brief |
| 276 |
* destroy shared memory block |
| 277 |
* |
| 278 |
*********************************************************/ |
| 279 |
|
| 280 |
void destroyMem (mem_map_block_ptr_t pMemBlockInfo) { |
| 281 |
ipcStopFlushing (pMemBlockInfo); // let shared memory get deleted when it is destroyed |
| 282 |
ipcMemDestroy (pMemBlockInfo); |
| 283 |
shMemInitialized = 0; |
| 284 |
} |
| 285 |
|
| 258 |
|
286 |
|
| 259 |
/** |
287 |
/** |
| 260 |
********************************************************* |
288 |
********************************************************* |
|
Lines 321-328
Link Here
|
| 321 |
return 0 ; |
349 |
return 0 ; |
| 322 |
} |
350 |
} |
| 323 |
|
351 |
|
| 324 |
|
|
|
| 325 |
|
| 326 |
/** |
352 |
/** |
| 327 |
********************************************************* |
353 |
********************************************************* |
| 328 |
* |
354 |
* |
|
Lines 376-388
Link Here
|
| 376 |
|
402 |
|
| 377 |
while (pServerData->threadStatus == RUNNING) |
403 |
while (pServerData->threadStatus == RUNNING) |
| 378 |
{ |
404 |
{ |
|
|
405 |
/* attach to this block so that it will not be deleted */ |
| 406 |
ipcMemOpen(pServerData->sharedMemName, pMemBlockInfo); |
| 407 |
|
| 379 |
rc = ipcFlushToFunc(pMemBlockInfo, sharedMemMainDataProcessorFunc, (void *) pServerData) ; |
408 |
rc = ipcFlushToFunc(pMemBlockInfo, sharedMemMainDataProcessorFunc, (void *) pServerData) ; |
| 380 |
ipcMemOpen(pServerData->sharedMemName, pMemBlockInfo); |
409 |
} |
| 381 |
} |
|
|
| 382 |
|
410 |
|
| 383 |
TPTP_LOG_DEBUG_MSG(pServerData, "Shared memory server ends...\n") ; |
411 |
TPTP_LOG_DEBUG_MSG(pServerData, "Shared memory server ends...\n") ; |
| 384 |
|
412 |
|
| 385 |
ipcMemDestroy(pMemBlockInfo); |
413 |
destroyMem (pMemBlockInfo); |
| 386 |
|
414 |
|
| 387 |
return ( rc ) ; |
415 |
return ( rc ) ; |
| 388 |
} |
416 |
} |