Changeset 122 in libcf


Ignore:
Timestamp:
06/12/13 11:05:07 (11 years ago)
Author:
cheese
Message:

#1 modify id to context in thread

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/cf_error.h

    r119 r122  
    5454/*------------------------------------------------------------*/
    5555#define CF_ERROR_THREAD_CREATE_CTX          CF_ERROR_THREAD - 1
    56 #define CF_ERROR_THREAD_CREATE              CF_ERROR_THREAD - 2
    57 #define CF_ERROR_THREAD_INVALID_ARGS        CF_ERROR_THREAD - 3
    58 #define CF_ERROR_THREAD_INIT_ATTR           CF_ERROR_THREAD - 4
    59 #define CF_ERROR_THREAD_SET_INHERIT_SCHED   CF_ERROR_THREAD - 5
    60 #define CF_ERROR_THREAD_SET_SCHED_POLICY    CF_ERROR_THREAD - 6
    61 #define CF_ERROR_THREAD_SET_SCHED_PARAM     CF_ERROR_THREAD - 7
     56#define CF_ERROR_THREAD_START               CF_ERROR_THREAD - 2
     57#define CF_ERROR_THREAD_INVALID_CTX         CF_ERROR_THREAD - 3
     58#define CF_ERROR_THREAD_INVALID_ARGS        CF_ERROR_THREAD - 4
     59#define CF_ERROR_THREAD_INIT_ATTR           CF_ERROR_THREAD - 5
     60#define CF_ERROR_THREAD_SET_INHERIT_SCHED   CF_ERROR_THREAD - 6
     61#define CF_ERROR_THREAD_SET_SCHED_POLICY    CF_ERROR_THREAD - 7
     62#define CF_ERROR_THREAD_SET_SCHED_PARAM     CF_ERROR_THREAD - 8
    6263/* }}} thread */
    6364
     
    6566#define CF_ERROR_MUTEX                      CF_ERROR_BASE * 5
    6667/*------------------------------------------------------------*/
    67 #define CF_ERROR_MUTEX_CREATE               CF_ERROR_MUTEX - 1
    68 #define CF_ERROR_MUTEX_INVALID_ARGS         CF_ERROR_MUTEX - 2
     68#define CF_ERROR_MUTEX_CREATE_CTX           CF_ERROR_MUTEX - 1
     69#define CF_ERROR_MUTEX_CREATE               CF_ERROR_MUTEX - 2
     70#define CF_ERROR_MUTEX_INVALID_CTX          CF_ERROR_MUTEX - 3
    6971/* }}} mutex */
    7072
  • trunk/include/cf_thread.h

    r121 r122  
    1515typedef int (* CF_Thread_Function) (void *);
    1616
    17 /** 스레드 아이디 */
     17/** 스레드 컨텍스트 */
    1818typedef void *  CF_Thread_Ctx;
    1919
    20 /** 뮤텍스 아이디 */
     20/** 뮤텍스 컨텍스트 */
    2121typedef void *  CF_Mutex_Ctx;
    2222
     
    2626
    2727CF_EXPORT int
    28 CF_Thread_Create        (CF_Thread_Ctx      * threadID,
     28CF_Thread_CreateCtx     (CF_Thread_Ctx      * ctx,
    2929                         CF_Thread_Function callback,
    3030                         void               * arg);
    3131
    3232CF_EXPORT int
    33 CF_Thread_DestroyCtx    (CF_Thread_Ctx * threadID);
     33CF_Thread_Start         (CF_Thread_Ctx ctx);
    3434
    3535CF_EXPORT int
    36 CF_Thread_Join          (CF_Thread_Ctx * threadID);
     36CF_Thread_DestroyCtx    (CF_Thread_Ctx ctx);
    3737
    3838CF_EXPORT int
    39 CF_Mutex_CreateCtx      (CF_Mutex_Ctx * mutex);
     39CF_Thread_Join          (CF_Thread_Ctx ctx);
    4040
    4141CF_EXPORT int
    42 CF_Mutex_DestoryCtx     (CF_Mutex_Ctx * mutex);
     42CF_Mutex_CreateCtx      (CF_Mutex_Ctx * ctx);
    4343
    4444CF_EXPORT int
    45 CF_Mutex_Lock           (CF_Mutex_Ctx * mutex);
     45CF_Mutex_DestoryCtx     (CF_Mutex_Ctx ctx);
    4646
    4747CF_EXPORT int
    48 CF_Mutex_Unlock         (CF_Mutex_Ctx * mutex);
     48CF_Mutex_Lock           (CF_Mutex_Ctx ctx);
     49
     50CF_EXPORT int
     51CF_Mutex_Unlock         (CF_Mutex_Ctx ctx);
    4952
    5053#ifdef __cplusplus
  • trunk/src/cf_log.c

    r119 r122  
    5252        return CF_ERROR_LOG_NOT_MAPPED_ID
    5353
    54 #define LOCK_LOG_CTX(__ctx)             CF_Mutex_Lock (&__ctx->mutex)
    55 #define UNLOCK_LOG_CTX(__ctx)           CF_Mutex_Unlock (&__ctx->mutex)
     54#define LOCK_LOG_CTX(__ctx)             CF_Mutex_Lock (__ctx->mutex)
     55#define UNLOCK_LOG_CTX(__ctx)           CF_Mutex_Unlock (__ctx->mutex)
    5656
    5757#define LOG_BUFFER_DEFAULT_SIZE         128 * 1024
     
    7676
    7777/** 로그 컨텍스트 (CF_Log_Ctx의 구현) */
    78 typedef struct __cf_log_ctx__ {
     78typedef struct __cf_log_ctx__
     79{
    7980    char            path[NAME_LENGTH + 1];
    8081    int             fd;
     
    8586} CF_LOG_CTX;
    8687
    87 typedef struct __cf_log_array__ {
     88typedef struct __cf_log_array__
     89{
    8890    CF_Log_Ctx  * ctxPool;
    8991    int         ctxSize;
     
    278280    ASSERT_CTX (ctx);
    279281
    280     if (CF_Mutex_DestoryCtx (&context->mutex) < 0)
     282    if (CF_Mutex_DestoryCtx (context->mutex) < 0)
    281283        return CF_ERROR_LOG_UNSET_MULTITHREAD;
     284
     285    context->mutex = NULL;
    282286
    283287    return CF_OK;
     
    370374    CF_File_Close (context->fd);
    371375
    372     CF_Mutex_DestoryCtx (&context->mutex);
     376    CF_Mutex_DestoryCtx (context->mutex);
    373377    context->mutex = NULL;
    374378
     
    381385 * \return 성공 시, 로그 컨텍스트; 실패 시, NULL
    382386 *
     387 * \param ctx       로그 컨텍스트 주소
    383388 * \param path      로그 파일 경로
    384389 * \param memsize   로그 버퍼 크기
    385  * \param ctx       로그 컨텍스트 받을 주소
    386390 *
    387391 * \see CF_LOG_DEFAULT_BUFFER, CF_LOG_NO_BUFFER
    388392 */
    389393static int
    390 CF_Log_CreateCtx (const char    * path,
    391                   const int     memsize,
    392                   CF_Log_Ctx    * ctx)
     394CF_Log_CreateCtx (CF_Log_Ctx    * ctx,
     395                  const char    * path,
     396                  const int     memsize)
    393397{
    394398    int result = 0;
     
    580584    CF_Log_Ctx  ctx = NULL;
    581585
    582     result = CF_Log_CreateCtx (path, memsize, &ctx);
     586    result = CF_Log_CreateCtx (&ctx, path, memsize);
    583587    if (result < 0)
    584588        return result;
  • trunk/src/cf_thread.c

    r121 r122  
    2626#endif // #if defined(_WIN32) || defined(_WIN64)
    2727
    28 #define ASSERT_THREAD(__h)  \
    29     if (__h == NULL)        \
    30         return CF_ERROR_THREAD_INVALID_ARGS
    31 
    32 #define ASSERT_MUTEX(__h)   \
    33     if (__h == NULL)        \
    34         return CF_ERROR_MUTEX_INVALID_ARGS
     28#define ASSERT_THREAD_CTX(__ctx)    \
     29    if (__ctx == NULL)              \
     30        return CF_ERROR_THREAD_INVALID_CTX
     31
     32#define ASSERT_MUTEX_CTX(__ctx) \
     33    if (__ctx == NULL)          \
     34        return CF_ERROR_MUTEX_INVALID_CTX
    3535
    3636typedef THREAD_RETURN (THREAD_CALL * THREAD_WORKER) (void *);
    3737
     38typedef struct __cf_thread_ctx__
     39{
     40    THREAD_TYPE     tid;
     41    THREAD_WORKER   callback;
     42    void            * arg;
     43} CF_THREAD_CTX;
     44
     45typedef struct __cf_ctx_ctx__
     46{
     47    MUTEX_TYPE  mid;
     48} CF_MUTEX_CTX;
     49
    3850static int
    39 CF_Thread_Local_Close (void * ctx)
    40 {
    41 #if defined(_WIN32) || defined(_WIN64)
    42     CloseHandle (ctx);
    43 #else
    44     free (ctx);
    45 #endif
    46 
    47     return CF_OK;
    48 }
    49 
    50 /**
    51  * 스레드를 생성
    52  *
    53  * \return 성공 시, CF_OK; 실패 시, 오류 코드
    54  *
    55  * \param threadID  스레드 아이디 주소
     51CF_Thread_Local_Close (THREAD_TYPE tid)
     52{
     53#if defined(_WIN32) || defined(_WIN64)
     54    CloseHandle (tid);
     55#endif
     56
     57    return CF_OK;
     58}
     59
     60static int
     61CF_Mutex_Local_Close (MUTEX_TYPE mid)
     62{
     63#if defined(_WIN32) || defined(_WIN64)
     64    CloseHandle (mid);
     65#else
     66    pthread_mutex_destroy (&mid);
     67#endif
     68
     69    return CF_OK;
     70}
     71
     72/**
     73 * 스레드 컨텍스트를 생성
     74 *
     75 * \return 성공 시, CF_OK; 실패 시, 오류 코드
     76 *
     77 * \param ctx       스레드 컨텍스트 주소
    5678 * \param callback  스레드 워커 함수 이름
    5779 * \param arg       스레드 함수로 전달할 인자
     80 */
     81int
     82CF_Thread_CreateCtx (CF_Thread_Ctx      * ctx,
     83                     CF_Thread_Function callback,
     84                     void               * arg)
     85{
     86    CF_THREAD_CTX * context = NULL;
     87
     88    context = (CF_THREAD_CTX *) calloc (sizeof (CF_THREAD_CTX), 1);
     89    if (context == NULL)
     90        return CF_ERROR_THREAD_CREATE_CTX;
     91
     92    context->callback   = (THREAD_WORKER) callback;
     93    context->arg        = arg;
     94
     95    *ctx = (CF_Thread_Ctx) context;
     96
     97    return CF_OK;
     98}
     99
     100/**
     101 * 스레드를 실행
     102 *
     103 * \return 성공 시, CF_OK; 실패 시, 오류 코드
     104 *
     105 * \param ctx 스레드 컨텍스트
    58106 *
    59107 * \remarks
    60  * pthread(POSIX Thread)에서 지원되는 스케줄링 정책은 SCHED_OTHER, SCHED_FIFO, SCHED_RR 등이 존재 <br />
     108 * pthread에서 지원되는 스케줄링 정책은 SCHED_OTHER, SCHED_FIFO, SCHED_RR 등이 존재 <br />
    61109 * 일반적으로 설정되는 스케줄링 정책의 기본값은 SCHED_OTHER이며, 솔라리스 환경에서 SCHED_OTHER는 TS(timesharing) 방식으로 명시되어 있음 <br />
    62110 * 그러나 개발 단계에서 테스트된 동작은 SCHED_FIFO와 동일하였으며, 때문에 솔라리스 환경에서는 스케줄링 정책을 SCHED_RR로 명시하도록 함 <br />
     
    67115 */
    68116int
    69 CF_Thread_Create (CF_Thread_Ctx         * threadID,
    70                   CF_Thread_Function    callback,
    71                   void                  * arg)
     117CF_Thread_Start (CF_Thread_Ctx ctx)
    72118{
    73119    int result = 0;
    74120
    75     THREAD_WORKER f = (THREAD_WORKER) callback;
    76 
    77 #if defined(_WIN32) || defined(_WIN64)
    78     *threadID = (THREAD_TYPE) CreateThread (NULL, 0, f, arg, 0, NULL);
    79     if (*threadID == NULL)
    80         return CF_ERROR_THREAD_CREATE;
     121    CF_THREAD_CTX * context = (CF_THREAD_CTX *) ctx;
     122
     123    ASSERT_THREAD_CTX (ctx);
     124
     125#if defined(_WIN32) || defined(_WIN64)
     126    context->tid = CreateThread (NULL, 0, context->callback, context->arg, 0, NULL);
     127    if (context->tid == NULL)
     128        return CF_ERROR_THREAD_START;
    81129#else
    82130
     
    106154# endif // # if defined(_SOLARIS)
    107155
    108     *threadID = (THREAD_TYPE *) calloc (sizeof (THREAD_TYPE), 1);
    109     if (*threadID == NULL)
    110         return CF_ERROR_THREAD_CREATE_CTX;
    111 
    112     result = pthread_create ((THREAD_TYPE *) *threadID, attr, f, arg);
    113     if (result)
     156    result = pthread_create (&context->tid, attr, context->callback, context->arg);
     157    if (result)
     158        return CF_ERROR_THREAD_START;
     159#endif
     160    return result;
     161}
     162
     163/**
     164 * 스레드 컨텍스트를 해제
     165 *
     166 * \return 성공 시, CF_OK; 실패 시, 오류 코드
     167 *
     168 * \param ctx 스레드 컨텍스트
     169 *
     170 * \remarks 스레드 컨텍스트를 해제하는 것이며 워커 스레드가 종료되지 않음
     171 */
     172int
     173CF_Thread_DestroyCtx (CF_Thread_Ctx ctx)
     174{
     175    CF_THREAD_CTX * context = (CF_THREAD_CTX *) ctx;
     176
     177    ASSERT_THREAD_CTX (ctx);
     178
     179    CF_Thread_Local_Close (context->tid);
     180    free (context);
     181
     182    return CF_OK;
     183}
     184
     185/**
     186 * 스레드가 종료될 때 까지 대기
     187 *
     188 * \return CF_OK 반환
     189 *
     190 * \param ctx 스레드 컨텍스트
     191 */
     192int
     193CF_Thread_Join (CF_Thread_Ctx ctx)
     194{
     195    CF_THREAD_CTX * context = (CF_THREAD_CTX *) ctx;
     196
     197    char status[16] = {0x00,};
     198
     199    ASSERT_THREAD_CTX (ctx);
     200
     201#if defined(_WIN32) || defined(_WIN64)
     202    WaitForSingleObject (context->tid, INFINITE);
     203#else
     204    pthread_join (context->tid, (void **)status);
     205#endif
     206
     207    return CF_OK;
     208}
     209
     210/**
     211 * 뮤텍스 컨텍스트를 생성
     212 *
     213 * \return 성공 시, CF_OK; 실패 시, 오류 코드
     214 *
     215 * \param ctx 뮤텍스 컨텍스트 주소
     216 */
     217int
     218CF_Mutex_CreateCtx (CF_Mutex_Ctx * ctx)
     219{
     220    int result = 0;
     221
     222    CF_MUTEX_CTX * context = NULL;
     223
     224    context = (CF_MUTEX_CTX *) calloc (sizeof (CF_MUTEX_CTX), 1);
     225    if (context == NULL)
     226        return CF_ERROR_MUTEX_CREATE_CTX;
     227
     228    TRY
    114229    {
    115         CF_Thread_DestroyCtx (threadID);
    116         return CF_ERROR_THREAD_CREATE;
     230#if defined(_WIN32) || defined(_WIN64)
     231        context->mid = CreateMutexA (NULL, FALSE, NULL);
     232        if (*ctx == NULL)
     233        {
     234            result = CF_ERROR_MUTEX_CREATE;
     235            TRY_BREAK;
     236        }
     237#else
     238        result = pthread_mutex_init (&context->mid, NULL);
     239        if (result)
     240        {
     241            result = CF_ERROR_MUTEX_CREATE;
     242            TRY_BREAK;
     243        }
     244#endif
    117245    }
    118 
    119 #endif
    120     return result;
    121 }
    122 
    123 /**
    124  * 스레드 아이디를 해제
    125  *
    126  * \return 성공 시, CF_OK; 실패 시, 오류 코드
    127  *
    128  * \param threadID 스레드 아이디 주소
    129  *
    130  * \remarks 스레드 아이디를 해제하는 것이며 워커 스레드가 종료되지 않음
    131  */
    132 int
    133 CF_Thread_DestroyCtx (CF_Thread_Ctx * threadID)
    134 {
    135     ASSERT_THREAD (*threadID);
    136 
    137     return CF_Thread_Local_Close (*threadID);
    138 }
    139 
    140 /**
    141  * 스레드가 종료될 때 까지 대기
    142  *
    143  * \return CF_OK 반환
    144  *
    145  * \param threadID 스레드 아이디 주소
    146  */
    147 int
    148 CF_Thread_Join (CF_Thread_Ctx * threadID)
    149 {
    150     ASSERT_THREAD (*threadID);
    151 
    152 #if defined(_WIN32) || defined(_WIN64)
    153     WaitForSingleObject ((THREAD_TYPE) *threadID, INFINITE);
    154 #else
    155     char status[16] = {0x00,};
    156     pthread_join (*((THREAD_TYPE *) *threadID), (void **)status);
    157 #endif
    158 
    159     return CF_OK;
    160 }
    161 
    162 /**
    163  * 뮤텍스 생성
    164  *
    165  * \return 성공 시, CF_OK; 실패 시, 오류 코드
    166  *
    167  * \param mutex 뮤텍스 아이디 주소
    168  *
    169  * \see CF_Thread_Create
    170  */
    171 int
    172 CF_Mutex_CreateCtx (CF_Mutex_Ctx * mutex)
    173 {
    174     int result = 0;
    175 
    176 #if defined(_WIN32) || defined(_WIN64)
    177     *mutex = (MUTEX_TYPE) CreateMutexA (NULL, FALSE, NULL);
    178     if (*mutex == NULL)
    179         return CF_ERROR_MUTEX_CREATE;
    180 #else
    181     *mutex = (MUTEX_TYPE *) calloc (sizeof (MUTEX_TYPE), 1);
    182     if (*mutex == NULL)
    183         return CF_ERROR_MUTEX_CREATE;
    184 
    185     result = pthread_mutex_init (*mutex, NULL);
    186     if (result)
    187         return CF_ERROR_MUTEX_CREATE;
    188 #endif
    189 
    190     return CF_OK;
    191 }
    192 
    193 /**
    194  * 뮤텍스 해제
    195  *
    196  * \return 성공 시, CF_OK; 실패 시, 오류 코드
    197  *
    198  * \param mutex 뮤텍스 아이디 주소
    199  */
    200 int
    201 CF_Mutex_DestoryCtx (CF_Mutex_Ctx * mutex)
    202 {
    203     ASSERT_MUTEX (*mutex);
    204 
    205 #if defined(_WIN32) || defined(_WIN64)
    206 #else
    207     pthread_mutex_destroy (*mutex);
    208 #endif
    209     return CF_Thread_Local_Close (*mutex);
     246    CATCH_IF (result < 0)
     247    {
     248        CF_Mutex_DestoryCtx (ctx);
     249    }
     250
     251    return CF_OK;
     252}
     253
     254/**
     255 * 뮤텍스 컨텍스트 해제
     256 *
     257 * \return 성공 시, CF_OK; 실패 시, 오류 코드
     258 *
     259 * \param ctx 뮤텍스 컨텍스트
     260 */
     261int
     262CF_Mutex_DestoryCtx (CF_Mutex_Ctx ctx)
     263{
     264    CF_MUTEX_CTX * context = ctx;
     265
     266    ASSERT_MUTEX_CTX (ctx);
     267
     268    CF_Mutex_Local_Close (context->mid);
     269    free (context);
     270
     271    return CF_OK;
    210272}
    211273
     
    215277 * \return 성공 시, CF_OK; 실패 시, 오류 코드
    216278 *
    217  * \param mutex 뮤텍스 아이디 주소
    218  */
    219 int
    220 CF_Mutex_Lock (CF_Mutex_Ctx * mutex)
    221 {
    222     ASSERT_MUTEX (*mutex);
    223 
    224 #if defined(_WIN32) || defined(_WIN64)
    225     WaitForSingleObject ((MUTEX_TYPE) *mutex, INFINITE);
    226 #else
    227     pthread_mutex_lock ((MUTEX_TYPE *) *mutex);
     279 * \param ctx 뮤텍스 컨텍스트
     280 */
     281int
     282CF_Mutex_Lock (CF_Mutex_Ctx ctx)
     283{
     284    CF_MUTEX_CTX * context = ctx;
     285
     286    ASSERT_MUTEX_CTX (ctx);
     287
     288#if defined(_WIN32) || defined(_WIN64)
     289    WaitForSingleObject (context->mid, INFINITE);
     290#else
     291    pthread_mutex_lock (&context->mid);
    228292#endif
    229293
     
    236300 * \return 성공 시, CF_OK; 실패 시, 오류 코드
    237301 *
    238  * \param mutex 뮤텍스 아이디 주소
    239  */
    240 int
    241 CF_Mutex_Unlock (CF_Mutex_Ctx * mutex)
    242 {
    243     ASSERT_MUTEX (*mutex);
    244 
    245 #if defined(_WIN32) || defined(_WIN64)
    246     ReleaseMutex (*mutex);
    247 #else
    248     pthread_mutex_unlock ((MUTEX_TYPE *) *mutex);
    249 #endif
    250 
    251     return CF_OK;
    252 }
     302 * \param ctx 뮤텍스 컨텍스트
     303 */
     304int
     305CF_Mutex_Unlock (CF_Mutex_Ctx ctx)
     306{
     307    CF_MUTEX_CTX * context = ctx;
     308
     309    ASSERT_MUTEX_CTX (ctx);
     310
     311#if defined(_WIN32) || defined(_WIN64)
     312    ReleaseMutex (context->mid);
     313#else
     314    pthread_mutex_unlock (&context->mid);
     315#endif
     316
     317    return CF_OK;
     318}
  • trunk/test/log.c

    r121 r122  
    8585    for (i = 0 ; i < 10 ; i++)
    8686    {
    87         if (CF_Thread_Create (&tid[i], test_log_mt, &i) < 0)
     87        if (CF_Thread_CreateCtx (&tid[i], test_log_mt, &i) < 0)
    8888        {
    8989            CF_DEBUG_PRINT (stderr, "failed to create %dth thread\n", i);
     
    9494    for (i = 0 ; i < 10 ; i++)
    9595    {
    96         if (CF_Thread_Join (&tid[i]) < 0)
     96        if (CF_Thread_Start (tid[i]) < 0)
     97        {
     98            CF_DEBUG_PRINT (stderr, "failed to start %dth thread\n", i);
     99            return -3;
     100        }
     101    }
     102
     103    for (i = 0 ; i < 10 ; i++)
     104    {
     105        if (CF_Thread_Join (tid[i]) < 0)
    97106            CF_DEBUG_PRINT (stderr, "failed to join %dth thread\n", i);
    98         if (CF_Thread_DestroyCtx (&tid[i]) < 0)
     107        if (CF_Thread_DestroyCtx (tid[i]) < 0)
    99108            CF_DEBUG_PRINT (stderr, "failed to release %dth thread\n", i);
    100109    }
    101110
    102     if (CF_Mutex_DestoryCtx (&globalMutex) < 0) {
     111    if (CF_Mutex_DestoryCtx (globalMutex) < 0) {
    103112        // error
    104113    }
  • trunk/test/socket.c

    r121 r122  
    135135    for (iter = 0 ; iter < THREAD_POOL ; iter++)
    136136    {
    137         if (CF_Thread_Create (&stid[iter], socket_echo_server, &sock) < 0)
     137        if (CF_Thread_CreateCtx (&stid[iter], socket_echo_server, &sock) < 0)
    138138        {
    139139            CF_DEBUG_PRINT (stderr, "failed to create %dth thread\n", iter);
     
    145145    for (iter = 0 ; iter < THREAD_POOL ; iter++)
    146146    {
    147         if (CF_Thread_Create (&ctid[iter], socket_echo_client, &sock) < 0)
     147        if (CF_Thread_CreateCtx (&ctid[iter], socket_echo_client, &sock) < 0)
    148148        {
    149149            CF_DEBUG_PRINT (stderr, "failed to create %dth thread\n", iter);
     
    155155    for (iter = 0 ; iter < THREAD_POOL ; iter++)
    156156    {
    157         CF_Thread_Join (&ctid[iter]);
    158         CF_Thread_DestroyCtx (&ctid[iter]);
     157        if (CF_Thread_Start (stid[iter]) < 0)
     158        {
     159            CF_DEBUG_PRINT (stderr, "failed to start %dth thread\n", iter);
     160            return -6;
     161        }
     162    }
    159163
    160         CF_Thread_Join (&stid[iter]);
    161         CF_Thread_DestroyCtx (&stid[iter]);
     164    for (iter = 0 ; iter < THREAD_POOL ; iter++)
     165    {
     166        if (CF_Thread_Start (ctid[iter]) < 0)
     167        {
     168            CF_DEBUG_PRINT (stderr, "failed to start %dth thread\n", iter);
     169            return -7;
     170        }
     171    }
     172
     173    for (iter = 0 ; iter < THREAD_POOL ; iter++)
     174    {
     175        CF_Thread_Join (ctid[iter]);
     176        CF_Thread_DestroyCtx (ctid[iter]);
     177
     178        CF_Thread_Join (stid[iter]);
     179        CF_Thread_DestroyCtx (stid[iter]);
    162180
    163181        CF_Log_Write (LOG_SOCKET, "SOCKET", "join server thread-%d\n", iter);
  • trunk/test/thread.c

    r121 r122  
    3232
    3333    for (i = 0 ; i < 10 ; i++) {
    34         if (CF_Thread_Create (&tid[i], worker, NULL) < 0) {
     34        if (CF_Thread_CreateCtx (&tid[i], worker, NULL) < 0) {
    3535            // error
    3636        }
     
    3838
    3939    for (i = 0 ; i < 10 ; i++) {
    40         if (CF_Thread_Join (&tid[i]) < 0) { // block
     40        if (CF_Thread_Start (tid[i]) < 0) {
    4141            // error
    4242        }
     
    4444
    4545    for (i = 0 ; i < 10 ; i++) {
    46         if (CF_Thread_DestroyCtx (&tid[i]) < 0) {
     46        if (CF_Thread_Join (tid[i]) < 0) { // block
    4747            // error
    4848        }
    4949    }
    5050
    51     if (CF_Mutex_DestoryCtx (&globalMutex) < 0) {
     51    for (i = 0 ; i < 10 ; i++) {
     52        if (CF_Thread_DestroyCtx (tid[i]) < 0) {
     53            // error
     54        }
     55    }
     56
     57    if (CF_Mutex_DestoryCtx (globalMutex) < 0) {
    5258        // error
    5359    }
Note: See TracChangeset for help on using the changeset viewer.