Changeset 62 in libcf
- Timestamp:
- 04/08/13 11:03:03 (11 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/cf_debug.h
r54 r62 55 55 56 56 /** 57 * 디버깅 모듈 초기화 58 * 59 * @see CF_Debug_Initialize 60 */ 61 # define CF_DEBUG_INITIALIZE \ 62 CF_Debug_Initialize () 63 64 /** 65 * 디버깅 모듈 해제 66 * 67 * @see CF_Debug_Finalize 68 */ 69 # define CF_DEBUG_FINALIZE \ 70 CF_Debug_Finalize () 71 72 /** 57 73 * 함수에 진입 58 74 * 59 75 * @see CF_Debug_EnterFunction 60 76 */ 61 # define CF_DEBUG_BEGIN_FUNCTION \77 # define CF_DEBUG_BEGIN_FUNCTION \ 62 78 CF_Debug_EnterFunction (__FILE__,__func__,__LINE__) 63 79 … … 67 83 * @see CF_Debug_LeaveFunction 68 84 */ 69 # define CF_DEBUG_END_FUNCTION \85 # define CF_DEBUG_END_FUNCTION \ 70 86 CF_Debug_LeaveFunction () 71 87 … … 73 89 # define CF_DEBUG_PRINT(__fp,__fmt,...) 74 90 # define CF_DEBUG_PRINT_BIN(__fp,__bin,__len,__fmt,...) 91 # define CF_DEBUG_INITIALIZE 92 # define CF_DEBUG_FINALIZE 75 93 # define CF_DEBUG_BEGIN_FUNCTION 76 94 # define CF_DEBUG_END_FUNCTION … … 98 116 99 117 CF_EXPORT int 118 CF_Debug_Initialize (void); 119 120 CF_EXPORT int 121 CF_Debug_Finalize (void); 122 123 CF_EXPORT int 100 124 CF_Debug_PrintCallStack (FILE * fp); 101 125 -
trunk/src/cf_debug.c
r55 r62 26 26 return CF_ERROR_DEBUG_INVALID_CTX 27 27 28 #define GET_CTX_OSTREAM(__ctx) \29 ((((CF_DEBUG_CTX *)__ctx)->fp == NULL) \30 ? stderr \31 : ((CF_DEBUG_CTX *)__ctx)->fp)32 33 28 /** 34 29 * 디버그 컨텍스트 … … 66 61 int line; 67 62 68 FILE * fp;69 63 CF_Mutex mutex; 70 64 … … 135 129 } 136 130 fprintf (fp, "\n"); 137 }138 139 return CF_OK;140 }141 142 /**143 * 디버그 컨텍스트를 해제144 *145 * @return 성공 시, CF_OK; 실패 시, 오류 코드146 *147 * @param ctx 디버그 컨텍스트148 *149 * @see CF_DEBUG_DESTROY_CTX150 */151 static int152 CF_Debug_DestroyCtx (CF_Debug_Ctx ctx)153 {154 CF_DEBUG_CTX * context = (CF_DEBUG_CTX *) ctx;155 CF_DEBUG_CALLSTACK * pop = NULL;156 CF_DEBUG_CALLSTACK * next = NULL;157 158 ASSERT_CTX (ctx);159 160 if (context->fp != NULL)161 fclose (context->fp);162 163 for (pop = next = context->callstack.caller ; pop ; pop = next)164 {165 next = next->caller;166 free (pop);167 }168 169 if (context->mutex)170 CF_Mutex_Destory (&context->mutex);171 172 free (context);173 174 return CF_OK;175 }176 177 /**178 * 디버그 컨텍스트를 생성179 *180 * @return 성공 시, CF_Debug_Ctx 형태의 컨텍스트; 실패 시, NULL181 * @see CF_DEBUG_CREATE_CTX182 */183 static int184 CF_Debug_CreateCtx (CF_Debug_Ctx * ctx)185 {186 int result = 0;187 CF_DEBUG_CTX * context = NULL;188 189 TRY190 {191 context = (CF_DEBUG_CTX *) calloc (sizeof (CF_DEBUG_CTX), 1);192 if (context == NULL)193 {194 result = CF_ERROR_DEBUG_ALLOCATE_CTX;195 TRY_BREAK;196 }197 198 result = CF_Mutex_Create (&context->mutex);199 if (result < 0)200 {201 TRY_BREAK;202 }203 204 *ctx = (CF_Debug_Ctx) context;205 }206 CATCH_IF (result < 0)207 {208 CF_Debug_DestroyCtx (context);209 131 } 210 132 … … 395 317 396 318 /** 397 * 현재 콜스택을 출력 319 * 디버그 컨텍스트를 해제 320 * 321 * @return 성공 시, CF_OK; 실패 시, 오류 코드 322 * 323 * @param ctx 디버그 컨텍스트 324 * 325 * @see CF_DEBUG_DESTROY_CTX 326 */ 327 static int 328 CF_Debug_DestroyCtx (CF_Debug_Ctx ctx) 329 { 330 CF_DEBUG_CTX * context = (CF_DEBUG_CTX *) ctx; 331 332 ASSERT_CTX (ctx); 333 334 while (context->callstack.caller) 335 CF_Debug_CallStackPop (ctx, NULL); 336 337 if (context->mutex) 338 CF_Mutex_Destory (&context->mutex); 339 340 free (context); 341 342 return CF_OK; 343 } 344 345 /** 346 * 디버그 컨텍스트를 생성 347 * 348 * @return 성공 시, CF_Debug_Ctx 형태의 컨텍스트; 실패 시, NULL 349 * @see CF_DEBUG_CREATE_CTX 350 */ 351 static int 352 CF_Debug_CreateCtx (CF_Debug_Ctx * ctx) 353 { 354 int result = 0; 355 CF_DEBUG_CTX * context = NULL; 356 357 TRY 358 { 359 context = (CF_DEBUG_CTX *) calloc (sizeof (CF_DEBUG_CTX), 1); 360 if (context == NULL) 361 { 362 result = CF_ERROR_DEBUG_ALLOCATE_CTX; 363 TRY_BREAK; 364 } 365 366 result = CF_Mutex_Create (&context->mutex); 367 if (result < 0) 368 { 369 TRY_BREAK; 370 } 371 372 *ctx = (CF_Debug_Ctx) context; 373 } 374 CATCH_IF (result < 0) 375 { 376 CF_Debug_DestroyCtx (context); 377 } 378 379 return CF_OK; 380 } 381 382 /** 383 * 콜스택 매니저 초기화 (글로벌 컨텍스트) 384 * 385 * @return 성공 시, CF_OK; 실패 시, 오류 코드 386 * 387 * @see CF_Debug_Finalize 388 */ 389 int 390 CF_Debug_Initialize (void) 391 { 392 int result = 0; 393 394 if (gDebugSingleCtx == NULL) 395 { 396 result = CF_Debug_CreateCtx (&gDebugSingleCtx); 397 if (result != CF_OK) 398 return result; 399 } 400 401 return CF_OK; 402 } 403 404 /** 405 * 콜스택 매니저 해제 (글로벌 컨텍스트) 406 * 407 * @return 성공 시, CF_OK; 실패 시, 오류 코드 408 */ 409 int 410 CF_Debug_Finalize (void) 411 { 412 return CF_Debug_DestroyCtx (gDebugSingleCtx); 413 } 414 415 /** 416 * 현재 콜스택을 출력 (글로벌 컨텍스트) 398 417 * 399 418 * @return 성공 시, CF_OK; 실패 시, 오류 코드 … … 427 446 428 447 /** 429 * 함수 진입을 명시 448 * 함수 진입을 명시 (글로벌 컨텍스트) 430 449 * 431 450 * @return 성공 시, CF_OK; 실패 시, 오류 코드 … … 442 461 const int line) 443 462 { 444 int result = 0; 445 CF_DEBUG_CTX * ctx = NULL; 446 447 if (gDebugSingleCtx == NULL) 448 { 449 result = CF_Debug_CreateCtx (&gDebugSingleCtx); 450 if (result != CF_OK) 451 return result; 452 } 453 ctx = (CF_DEBUG_CTX *)gDebugSingleCtx; 463 CF_DEBUG_CTX * ctx = (CF_DEBUG_CTX *)gDebugSingleCtx; 464 465 ASSERT_CTX (ctx); 454 466 455 467 CF_Mutex_Lock (&ctx->mutex); … … 461 473 462 474 /** 463 * 함수 종료를 명시 475 * 함수 종료를 명시 (글로벌 컨텍스트) 464 476 * 465 477 * @return 성공 시, CF_OK; 실패 시, 오류 코드 … … 472 484 CF_DEBUG_CTX * ctx = (CF_DEBUG_CTX *)gDebugSingleCtx; 473 485 474 if (ctx == NULL) 475 return CF_ERROR_DEBUG_INVALID_CTX; 486 ASSERT_CTX (ctx); 476 487 477 488 CF_Mutex_Lock (&ctx->mutex); -
trunk/test/debug.c
r51 r62 23 23 "『 절원의 템페스트 OP2 Theme 』\n"; 24 24 25 CF_DEBUG_INITIALIZE; 25 26 CF_DEBUG_BEGIN_FUNCTION; 26 27 … … 32 33 33 34 CF_DEBUG_END_FUNCTION; 35 CF_DEBUG_FINALIZE; 34 36 35 37 return 0; -
trunk/test/test.c
r61 r62 114 114 if (CF_Thread_Join (&tid[i]) < 0) 115 115 CF_DEBUG_PRINT (stderr, "failed to join %dth thread\n", i); 116 if (CF_Thread_Release (&tid[i]) < 0) 117 CF_DEBUG_PRINT (stderr, "failed to release %dth thread\n", i); 116 118 } 117 119 … … 255 257 void test_socket (void) 256 258 { 257 CF_Thread tid[THREAD_POOL]; 259 CF_Thread stid[THREAD_POOL]; 260 CF_Thread ctid[THREAD_POOL]; 258 261 259 262 int sock = 0; … … 289 292 for (iter = 0 ; iter < THREAD_POOL ; iter++) 290 293 { 291 if (CF_Thread_Create (& tid[iter], socket_echo_server, &sock) < 0)294 if (CF_Thread_Create (&stid[iter], socket_echo_server, &sock) < 0) 292 295 { 293 296 CF_DEBUG_PRINT (stderr, "failed to create %dth thread\n", iter); … … 299 302 for (iter = 0 ; iter < THREAD_POOL ; iter++) 300 303 { 301 CF_Thread dummy; 302 if (CF_Thread_Create (&dummy, socket_echo_client, &sock) < 0) 304 if (CF_Thread_Create (&ctid[iter], socket_echo_client, &sock) < 0) 303 305 { 304 306 CF_DEBUG_PRINT (stderr, "failed to create %dth thread\n", iter); … … 310 312 for (iter = 0 ; iter < THREAD_POOL ; iter++) 311 313 { 312 CF_Thread_Join (&tid[iter]); 313 CF_Thread_Release (&tid[iter]); 314 CF_Thread_Join (&ctid[iter]); 315 CF_Thread_Release (&ctid[iter]); 316 317 CF_Thread_Join (&stid[iter]); 318 CF_Thread_Release (&stid[iter]); 319 314 320 CF_Log_Write (LOG_SOCKET, "SOCKET", "join server thread-%d\n", iter); 315 321 } … … 327 333 int main (int argc, char ** argv) 328 334 { 335 CF_DEBUG_INITIALIZE; 329 336 CF_DEBUG_BEGIN_FUNCTION; 330 337 … … 348 355 349 356 CF_DEBUG_END_FUNCTION; 357 CF_DEBUG_FINALIZE; 350 358 351 359 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.