Changeset 3167 for trunk/src/lib


Ignore:
Timestamp:
Mar 20, 2018, 10:47:25 PM (7 years ago)
Author:
bird
Message:

kDep*: no globals; dir-nt-bird.c: only main thread

Location:
trunk/src/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/kDep.c

    r3140 r3167  
    7373
    7474
    75 /*******************************************************************************
    76 *   Global Variables                                                           *
    77 *******************************************************************************/
    78 /** List of dependencies. */
    79 static PDEP g_pDeps = NULL;
     75/**
     76 * Initializes the dep instance.
     77 *
     78 * @param   pThis       The dep instance to init.
     79 */
     80void depInit(PDEPGLOBALS pThis)
     81{
     82    pThis->pDeps = NULL;
     83}
     84
     85
     86/**
     87 * Cleans up the dep instance (frees resources).
     88 *
     89 * @param   pThis       The dep instance to cleanup.
     90 */
     91void depCleanup(PDEPGLOBALS pThis)
     92{
     93    PDEP pDep = pThis->pDeps;
     94    pThis->pDeps = NULL;
     95    while (pDep)
     96    {
     97        PDEP pFree = pDep;
     98        pDep = pDep->pNext;
     99        free(pFree);
     100    }
     101}
    80102
    81103
     
    196218 * 'Optimizes' and corrects the dependencies.
    197219 */
    198 void depOptimize(int fFixCase, int fQuiet, const char *pszIgnoredExt)
     220void depOptimize(PDEPGLOBALS pThis, int fFixCase, int fQuiet, const char *pszIgnoredExt)
    199221{
    200222    /*
     
    202224     */
    203225    size_t  cchIgnoredExt = pszIgnoredExt ? strlen(pszIgnoredExt) : 0;
    204     PDEP    pDepOrg = g_pDeps;
    205     PDEP    pDep = g_pDeps;
    206     g_pDeps = NULL;
     226    PDEP    pDepOrg = pThis->pDeps;
     227    PDEP    pDep = pThis->pDeps;
     228    pThis->pDeps = NULL;
    207229    for (; pDep; pDep = pDep->pNext)
    208230    {
     
    287309         * Insert the corrected dependency.
    288310         */
    289         depAdd(pszFilename, strlen(pszFilename));
     311        depAdd(pThis, pszFilename, strlen(pszFilename));
    290312    }
    291313
     
    305327 * Prints the dependency chain.
    306328 *
    307  * @returns Pointer to the allocated dependency.
     329 * @param   pThis       The 'dep' instance.
    308330 * @param   pOutput     Output stream.
    309331 */
    310 void depPrint(FILE *pOutput)
     332void depPrint(PDEPGLOBALS pThis, FILE *pOutput)
    311333{
    312334    PDEP pDep;
    313     for (pDep = g_pDeps; pDep; pDep = pDep->pNext)
     335    for (pDep = pThis->pDeps; pDep; pDep = pDep->pNext)
    314336        fprintf(pOutput, " \\\n\t%s", pDep->szFilename);
    315337    fprintf(pOutput, "\n\n");
     
    319341/**
    320342 * Prints empty dependency stubs for all dependencies.
    321  */
    322 void depPrintStubs(FILE *pOutput)
     343 *
     344 * @param   pThis       The 'dep' instance.
     345 * @param   pOutput     Output stream.
     346 */
     347void depPrintStubs(PDEPGLOBALS pThis, FILE *pOutput)
    323348{
    324349    PDEP pDep;
    325     for (pDep = g_pDeps; pDep; pDep = pDep->pNext)
     350    for (pDep = pThis->pDeps; pDep; pDep = pDep->pNext)
    326351        fprintf(pOutput, "%s:\n\n", pDep->szFilename);
    327352}
     
    355380 *
    356381 * @returns Pointer to the allocated dependency.
     382 * @param   pThis       The 'dep' instance.
    357383 * @param   pszFilename     The filename. Does not need to be terminated.
    358384 * @param   cchFilename     The length of the filename.
    359385 */
    360 PDEP depAdd(const char *pszFilename, size_t cchFilename)
     386PDEP depAdd(PDEPGLOBALS pThis, const char *pszFilename, size_t cchFilename)
    361387{
    362388    unsigned    uHash = sdbm(pszFilename, cchFilename);
     
    368394     */
    369395    pDepPrev = NULL;
    370     for (pDep = g_pDeps; pDep; pDepPrev = pDep, pDep = pDep->pNext)
     396    for (pDep = pThis->pDeps; pDep; pDepPrev = pDep, pDep = pDep->pNext)
    371397        if (    pDep->uHash == uHash
    372398            &&  pDep->cchFilename == cchFilename
     
    397423    else
    398424    {
    399         pDep->pNext = g_pDeps;
    400         g_pDeps = pDep;
     425        pDep->pNext = pThis->pDeps;
     426        pThis->pDeps = pDep;
    401427    }
    402428    return pDep;
    403 }
    404 
    405 
    406 /**
    407  * Frees the current dependency chain.
    408  */
    409 void depCleanup(void)
    410 {
    411     PDEP pDep = g_pDeps;
    412     g_pDeps = NULL;
    413     while (pDep)
    414     {
    415         PDEP pFree = pDep;
    416         pDep = pDep->pNext;
    417         free(pFree);
    418     }
    419429}
    420430
  • trunk/src/lib/kDep.h

    r2955 r3167  
    4646} DEP, *PDEP;
    4747
     48typedef struct DEPGLOBALS
     49{
     50    /** List of dependencies. */
     51    PDEP pDeps;
    4852
    49 extern PDEP depAdd(const char *pszFilename, size_t cchFilename);
    50 extern void depOptimize(int fFixCase, int fQuiet, const char *pszIgnoredExt);
    51 extern void depPrint(FILE *pOutput);
    52 extern void depPrintStubs(FILE *pOutput);
    53 extern void depCleanup(void);
     53} DEPGLOBALS;
     54typedef DEPGLOBALS *PDEPGLOBALS;
     55
     56extern void depInit(PDEPGLOBALS pThis);
     57extern void depCleanup(PDEPGLOBALS pThis);
     58extern PDEP depAdd(PDEPGLOBALS pThis, const char *pszFilename, size_t cchFilename);
     59extern void depOptimize(PDEPGLOBALS pThis, int fFixCase, int fQuiet, const char *pszIgnoredExt);
     60extern void depPrint(PDEPGLOBALS pThis, FILE *pOutput);
     61extern void depPrintStubs(PDEPGLOBALS pThis, FILE *pOutput);
     62
    5463extern void *depReadFileIntoMemory(FILE *pInput, size_t *pcbFile, void **ppvOpaque);
    5564extern void depFreeFileMemory(void *pvFile, void *pvOpaque);
Note: See TracChangeset for help on using the changeset viewer.