Changeset 51 in libcf for trunk/src/cf_log.c


Ignore:
Timestamp:
04/02/13 10:23:52 (11 years ago)
Author:
cheese
Message:

#1 change the debugging utiltity to support single context with mutex

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/cf_log.c

    r50 r51  
    3030#define LOCK_LOG_CTX(__ctx)             CF_Mutex_Lock (&__ctx->mutex)
    3131#define UNLOCK_LOG_CTX(__ctx)           CF_Mutex_Unlock (&__ctx->mutex)
    32 #define CHECK_INITIALIZED()             (gLogEnvironment.ctxPool == NULL||  \
    33                                          gLogEnvironment.ctxSize <= 0   )
    34 #define CHECK_INVALID_MAPID(__mapid)    (gLogEnvironment.ctxSize <= __mapid)
    35 #define CHECK_MAPPED_ID(__mapid)        (gLogEnvironment.ctxPool[__mapid] != NULL)  \
    36 
     32#define CHECK_INITIALIZED()             (gLogArray.ctxPool == NULL||    \
     33                                         gLogArray.ctxSize <= 0 )
     34#define CHECK_INVALID_MAPID(__mapid)    (gLogArray.ctxSize <= __mapid)
     35#define CHECK_MAPPED_ID(__mapid)        (gLogArray.ctxPool[__mapid] != NULL)
    3736
    3837#define LOG_BUFFER_DEFAULT_SIZE         128 * 1024
    3938
    40 #define LOG_DATETIME_LENGTH         sizeof ("0000-00-00 00:00:00.000") - 1
     39#define LOG_DATETIME_LENGTH             sizeof ("0000-00-00 00:00:00.000") - 1
    4140
    4241/**
     
    6968} S_CF_LOG_CTX, CF_LOG_CTX;
    7069
    71 typedef struct __cf_log_environment__ {
     70typedef struct __cf_log_array__ {
    7271    CF_Log_Ctx  * ctxPool;
    7372    int         ctxSize;
    74 } S_CF_LOG_ENVIRONMENT, CF_LOG_ENVIRONMENT;
    75 
    76 static CF_LOG_ENVIRONMENT   gLogEnvironment;
     73} S_CF_LOG_ARRAY, CF_LOG_ARRAY;
     74
     75static CF_LOG_ARRAY gLogArray;
    7776
    7877#if defined(_WIN32) || defined(_WIN64)
     
    475474    }
    476475
    477     gLogEnvironment.ctxPool[mapid] = ctx;
     476    gLogArray.ctxPool[mapid] = ctx;
    478477
    479478    return CF_OK;
     
    501500        return CF_ERROR_LOG_NOT_MAPPED_ID;
    502501
    503     CF_Log_DestroyCtx (gLogEnvironment.ctxPool[mapid]);
    504 
    505     free (gLogEnvironment.ctxPool[mapid]);
    506     gLogEnvironment.ctxPool[mapid] = NULL;
     502    CF_Log_DestroyCtx (gLogArray.ctxPool[mapid]);
     503
     504    free (gLogArray.ctxPool[mapid]);
     505    gLogArray.ctxPool[mapid] = NULL;
    507506
    508507    return CF_OK;
     
    528527        return CF_ERROR_LOG_NOT_MAPPED_ID;
    529528
    530     *ctx = gLogEnvironment.ctxPool[mapid];
     529    *ctx = gLogArray.ctxPool[mapid];
    531530
    532531    return CF_OK;
     
    543542CF_Log_Initialize (const int logPool)
    544543{
    545     memset (&gLogEnvironment, 0x00, sizeof (CF_LOG_ENVIRONMENT));
     544    memset (&gLogArray, 0x00, sizeof (CF_LOG_ARRAY));
    546545
    547546    if (logPool > 0)
    548547    {
    549         gLogEnvironment.ctxPool =
     548        gLogArray.ctxPool =
    550549            (CF_Log_Ctx *) calloc ((size_t) logPool, sizeof (CF_Log_Ctx));
    551         if (gLogEnvironment.ctxPool == NULL)
     550        if (gLogArray.ctxPool == NULL)
    552551            return CF_ERROR_LOG_INITIALIZE;
    553         gLogEnvironment.ctxSize = logPool;
     552        gLogArray.ctxSize = logPool;
    554553    }
    555554
     
    567566    int mapid = 0;
    568567
    569     for (mapid = 0 ; mapid < gLogEnvironment.ctxSize ; mapid++)
     568    for (mapid = 0 ; mapid < gLogArray.ctxSize ; mapid++)
    570569    {
    571570        CF_Log_UnmapCtxID (mapid);
    572571    }
    573572
    574     if (gLogEnvironment.ctxPool != NULL)
    575         free (gLogEnvironment.ctxPool);
    576 
    577     memset (&gLogEnvironment, 0x00, sizeof (CF_LOG_ENVIRONMENT));
     573    if (gLogArray.ctxPool != NULL)
     574        free (gLogArray.ctxPool);
     575
     576    memset (&gLogArray, 0x00, sizeof (CF_LOG_ARRAY));
    578577
    579578    return CF_OK;
Note: See TracChangeset for help on using the changeset viewer.