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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/dir-nt-bird.c

    r3140 r3167  
    3838# include <glob.h>
    3939#endif
    40 
     40#include <assert.h>
    4141
    4242#include "nt_fullpath.h" /* for the time being - will be implemented here later on. */
     
    8080 * from the sources.  */
    8181static KBOOL g_fFsCacheIsUsingCustomRevision = K_FALSE;
     82/** The ID of the main thread.  We currently only let it access the cache. */
     83static DWORD g_idMainThread = 0;
    8284
    8385
    8486void hash_init_directories(void)
    8587{
     88    g_idMainThread = GetCurrentThreadId();
    8689    g_pFsCache = kFsCacheCreate(0);
    8790    if (g_pFsCache)
     
    110113    KFSLOOKUPERROR  enmError;
    111114    PKFSOBJ         pDirObj = kFsCacheLookupA(g_pFsCache, pszDir, &enmError);
     115    assert(GetCurrentThreadId() == g_idMainThread);
    112116    if (pDirObj)
    113117    {
     118
    114119        if (pDirObj->bObjType == KFSOBJ_TYPE_DIR)
    115120        {
     
    145150int file_exists_p(const char *pszPath)
    146151{
     152    int fRc;
     153    if (GetCurrentThreadId() == g_idMainThread)
     154    {
     155        KFSLOOKUPERROR  enmError;
     156        PKFSOBJ         pPathObj = kFsCacheLookupA(g_pFsCache, pszPath, &enmError);
     157        if (pPathObj)
     158        {
     159            fRc = pPathObj->bObjType != KFSOBJ_TYPE_MISSING;
     160            kFsCacheObjRelease(g_pFsCache, pPathObj);
     161        }
     162        else
     163            fRc = 0;
     164    }
     165    else
     166        fRc = GetFileAttributesA(pszPath) != INVALID_FILE_ATTRIBUTES;
     167    return fRc;
     168}
     169
     170
     171/**
     172 * Just a way for vpath.c to get a correctly cased path, I think.
     173 *
     174 * @returns Directory path in string cache.
     175 * @param   pszDir      The directory.
     176 */
     177const char *dir_name(const char *pszDir)
     178{
     179    char szTmp[MAX_PATH];
     180    assert(GetCurrentThreadId() == g_idMainThread);
     181    nt_fullpath(pszDir, szTmp, sizeof(szTmp));
     182    return strcache_add(szTmp);
     183}
     184
     185
     186/**
     187 * Makes future file_impossible_p calls return 1 for pszPath.
     188 */
     189void file_impossible(const char *pszPath)
     190{
     191    KFSLOOKUPERROR  enmError;
     192    PKFSOBJ         pPathObj = kFsCacheLookupA(g_pFsCache, pszPath, &enmError);
     193    assert(GetCurrentThreadId() == g_idMainThread);
     194    if (pPathObj)
     195    {
     196        kFsCacheObjAddUserData(g_pFsCache, pPathObj, KMK_DIR_NT_IMPOSSIBLE_KEY, sizeof(KFSUSERDATA));
     197        kFsCacheObjRelease(g_pFsCache, pPathObj);
     198    }
     199}
     200
     201/**
     202 * Makes future file_impossible_p calls return 1 for pszPath.
     203 */
     204int file_impossible_p(const char *pszPath)
     205{
    147206    int             fRc;
    148207    KFSLOOKUPERROR  enmError;
    149208    PKFSOBJ         pPathObj = kFsCacheLookupA(g_pFsCache, pszPath, &enmError);
     209    assert(GetCurrentThreadId() == g_idMainThread);
    150210    if (pPathObj)
    151211    {
    152         fRc = pPathObj->bObjType != KFSOBJ_TYPE_MISSING;
     212        fRc = kFsCacheObjGetUserData(g_pFsCache, pPathObj, KMK_DIR_NT_IMPOSSIBLE_KEY) != NULL;
    153213        kFsCacheObjRelease(g_pFsCache, pPathObj);
    154214    }
     
    160220
    161221/**
    162  * Just a way for vpath.c to get a correctly cased path, I think.
    163  *
    164  * @returns Directory path in string cache.
    165  * @param   pszDir      The directory.
    166  */
    167 const char *dir_name(const char *pszDir)
    168 {
    169     char szTmp[MAX_PATH];
    170     nt_fullpath(pszDir, szTmp, sizeof(szTmp));
    171     return strcache_add(szTmp);
    172 }
    173 
    174 
    175 /**
    176  * Makes future file_impossible_p calls return 1 for pszPath.
    177  */
    178 void file_impossible(const char *pszPath)
    179 {
    180     KFSLOOKUPERROR  enmError;
    181     PKFSOBJ         pPathObj = kFsCacheLookupA(g_pFsCache, pszPath, &enmError);
    182     if (pPathObj)
    183     {
    184         kFsCacheObjAddUserData(g_pFsCache, pPathObj, KMK_DIR_NT_IMPOSSIBLE_KEY, sizeof(KFSUSERDATA));
    185         kFsCacheObjRelease(g_pFsCache, pPathObj);
    186     }
    187 }
    188 
    189 /**
    190  * Makes future file_impossible_p calls return 1 for pszPath.
    191  */
    192 int file_impossible_p(const char *pszPath)
    193 {
    194     int             fRc;
    195     KFSLOOKUPERROR  enmError;
    196     PKFSOBJ         pPathObj = kFsCacheLookupA(g_pFsCache, pszPath, &enmError);
    197     if (pPathObj)
    198     {
    199         fRc = kFsCacheObjGetUserData(g_pFsCache, pPathObj, KMK_DIR_NT_IMPOSSIBLE_KEY) != NULL;
    200         kFsCacheObjRelease(g_pFsCache, pPathObj);
    201     }
    202     else
    203         fRc = 0;
    204     return fRc;
    205 }
    206 
    207 
    208 /**
    209222 * opendir for glob.
    210223 *
     
    216229    KFSLOOKUPERROR  enmError;
    217230    PKFSOBJ         pDirObj = kFsCacheLookupA(g_pFsCache, pszDir, &enmError);
     231    assert(GetCurrentThreadId() == g_idMainThread);
    218232    if (pDirObj)
    219233    {
     
    244258    KMKNTOPENDIR *pDir = (KMKNTOPENDIR *)pvDir;
    245259    KU32 const    cChildren = pDir->pDir->cChildren;
     260    assert(GetCurrentThreadId() == g_idMainThread);
    246261    while (pDir->idxNext < cChildren)
    247262    {
     
    307322{
    308323    KMKNTOPENDIR *pDir = (KMKNTOPENDIR *)pvDir;
     324    assert(GetCurrentThreadId() == g_idMainThread);
    309325    kFsCacheObjRelease(g_pFsCache, &pDir->pDir->Obj);
    310326    pDir->pDir = NULL;
     
    324340    KFSLOOKUPERROR  enmError;
    325341    PKFSOBJ         pPathObj = kFsCacheLookupA(g_pFsCache, pszPath, &enmError);
     342    assert(GetCurrentThreadId() == g_idMainThread);
    326343/** @todo follow symlinks vs. on symlink!   */
    327344    if (pPathObj)
     
    352369    KFSLOOKUPERROR  enmError;
    353370    PKFSOBJ         pPathObj = kFsCacheLookupA(g_pFsCache, pszPath, &enmError);
     371    assert(GetCurrentThreadId() == g_idMainThread);
    354372    if (pPathObj)
    355373    {
     
    384402    KFSLOOKUPERROR  enmError;
    385403    PKFSOBJ         pDirObj = kFsCacheLookupA(g_pFsCache, pszDir, &enmError);
     404    assert(GetCurrentThreadId() == g_idMainThread);
    386405    if (pDirObj)
    387406    {
     
    403422void dir_setup_glob(glob_t *pGlob)
    404423{
     424    assert(GetCurrentThreadId() == g_idMainThread);
    405425    pGlob->gl_opendir   = dir_glob_opendir;
    406426    pGlob->gl_readdir   = dir_glob_readdir;
     
    465485    KFSLOOKUPERROR  enmError;
    466486    PKFSOBJ         pPathObj = kFsCacheLookupA(g_pFsCache, pszPath, &enmError);
     487    assert(GetCurrentThreadId() == g_idMainThread);
    467488    if (pPathObj)
    468489    {
     
    558579    /* Currently a little expensive, so just hit the file system once the
    559580       jobs starts comming in. */
     581    assert(GetCurrentThreadId() == g_idMainThread);
    560582    if (g_cInvalidates == 0)
    561583    {
     
    589611void dir_cache_invalid_after_job(void)
    590612{
     613    assert(GetCurrentThreadId() == g_idMainThread);
    591614    g_cInvalidates++;
    592615    if (g_fFsCacheIsUsingCustomRevision)
     
    603626void dir_cache_invalid_all(void)
    604627{
     628    assert(GetCurrentThreadId() == g_idMainThread);
    605629    g_cInvalidates++;
    606630    kFsCacheInvalidateAll(g_pFsCache);
     
    614638void dir_cache_invalid_missing(void)
    615639{
     640    assert(GetCurrentThreadId() == g_idMainThread);
    616641    g_cInvalidates++;
    617642    kFsCacheInvalidateAll(g_pFsCache);
     
    625650void dir_cache_invalid_volatile(void)
    626651{
     652    assert(GetCurrentThreadId() == g_idMainThread);
    627653    g_cInvalidates++;
    628654    if (g_fFsCacheIsUsingCustomRevision)
     
    644670    KFSLOOKUPERROR enmError;
    645671    PKFSOBJ pObj = kFsCacheLookupA(g_pFsCache, pszDir, &enmError);
     672    assert(GetCurrentThreadId() == g_idMainThread);
    646673    if (pObj)
    647674    {
     
    670697int dir_cache_deleted_directory(const char *pszDir)
    671698{
     699    assert(GetCurrentThreadId() == g_idMainThread);
    672700    if (kFsCacheInvalidateDeletedDirectoryA(g_pFsCache, pszDir))
    673701        return 0;
     
    678706int kmk_builtin_dircache(int argc, char **argv, char **envp)
    679707{
     708    assert(GetCurrentThreadId() == g_idMainThread);
    680709    if (argc >= 2)
    681710    {
Note: See TracChangeset for help on using the changeset viewer.