瀏覽代碼

HPCC-15447 Move a few static variables out of functions

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
Gavin Halliday 9 年之前
父節點
當前提交
22a7937006
共有 2 個文件被更改,包括 30 次插入31 次删除
  1. 1 1
      system/jlib/jthread.cpp
  2. 29 30
      system/jlib/jutil.cpp

+ 1 - 1
system/jlib/jthread.cpp

@@ -1692,6 +1692,7 @@ static unsigned dowaitpid(HANDLE pid, int mode)
     return 0;
 }
 
+static CriticalSection runsect; // single thread process start to avoid forked handle open/closes interleaving
 class CLinuxPipeProcess: public CInterface, implements IPipeProcess
 {
 
@@ -1971,7 +1972,6 @@ public:
 
     bool run(const char *_title,const char *_prog,const char *_dir,bool _hasinput,bool _hasoutput, bool _haserror, size32_t stderrbufsize, bool _newProcessGroup)
     {
-        static CriticalSection runsect; // single thread process start to avoid forked handle open/closes interleaving
         CriticalBlock runblock(runsect);
         kill();
         CriticalBlock block(sect); 

+ 29 - 30
system/jlib/jutil.cpp

@@ -1299,21 +1299,20 @@ bool JBASE64_Decode(size32_t length, const char *incs, StringBuffer &out)
     return fullQuartetDecoded;
 }
 
+static const char enc32[33] =
+           "abcdefghijklmnopqrstuvwxyz"
+           "234567";
 static inline void encode5_32(const byte *in,StringBuffer &out)
 {
     // 5 bytes in 8 out
-    static const char enc[33] =  
-               "abcdefghijklmnopqrstuvwxyz"
-               "234567";
-
-    out.append(enc[(in[0] >> 3)]);
-    out.append(enc[((in[0] & 0x07) << 2) | (in[1] >> 6)]);
-    out.append(enc[(in[1] >> 1) & 0x1f]);
-    out.append(enc[((in[1] & 0x01) << 4) | (in[2] >> 4)]);
-    out.append(enc[((in[2] & 0x0f) << 1) | (in[3] >> 7)]);
-    out.append(enc[(in[3] >> 2) & 0x1f]);
-    out.append(enc[((in[3] & 0x03) << 3) | (in[4] >> 5)]);
-    out.append(enc[in[4] & 0x1f]);
+    out.append(enc32[(in[0] >> 3)]);
+    out.append(enc32[((in[0] & 0x07) << 2) | (in[1] >> 6)]);
+    out.append(enc32[(in[1] >> 1) & 0x1f]);
+    out.append(enc32[((in[1] & 0x01) << 4) | (in[2] >> 4)]);
+    out.append(enc32[((in[2] & 0x0f) << 1) | (in[3] >> 7)]);
+    out.append(enc32[(in[3] >> 2) & 0x1f]);
+    out.append(enc32[((in[3] & 0x03) << 3) | (in[4] >> 5)]);
+    out.append(enc32[in[4] & 0x1f]);
 }
 
 void JBASE32_Encode(const char *in,StringBuffer &out)
@@ -1996,28 +1995,29 @@ extern jlib_decl IAtom * deserializeAtom(MemoryBuffer & source)
 
 //==============================================================
 
+static const char enc64[65] =
+           "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+           "abcdefghijklmnopqrstuvwxyz"
+           "0123456789-_";
+
 static inline void encode3_64(byte *in,StringBuffer &out)
 {
     // 3 bytes in 4 out
-    static const char enc[65] =  
-               "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
-               "abcdefghijklmnopqrstuvwxyz"
-               "0123456789-_";
-    out.append(enc[in[0]>>2]);
-    out.append(enc[((in[0] << 4) & 0x30) | (in[1] >> 4)]);
-    out.append(enc[((in[1] << 2)  & 0x3c) | (in[2] >> 6)]);
-    out.append(enc[in[2] & 0x3f]);
+    out.append(enc64[in[0]>>2]);
+    out.append(enc64[((in[0] << 4) & 0x30) | (in[1] >> 4)]);
+    out.append(enc64[((in[1] << 2)  & 0x3c) | (in[2] >> 6)]);
+    out.append(enc64[in[2] & 0x3f]);
 }
 
 
 
 
+static NonReentrantSpinLock lock;
+static unsigned uuidbin[5] = {0,0,0,0,0};
 StringBuffer &genUUID(StringBuffer &out, bool nocase)
 { // returns a 24 char UUID for nocase=false or 32 char for nocase=true
-    static NonReentrantSpinLock lock;
     lock.enter();
     // could be quicker using statics
-    static unsigned uuidbin[5] = {0,0,0,0,0};
     if (uuidbin[0]==0) {
         queryHostIP().getNetAddress(sizeof(uuidbin[0]),uuidbin);
         uuidbin[1] = (unsigned)GetCurrentProcessId();
@@ -2319,17 +2319,16 @@ IPropertyTree *getHPCCEnvironment(const char *configFileName)
     return NULL;
 }
 
+static CriticalSection securitySettingsCrit;
+static bool useSSL = false;
+static StringAttr certificate;
+static StringAttr privateKey;
+static bool retrieved = false;
 jlib_decl bool querySecuritySettings(bool *          _useSSL,
                                      unsigned short *_port,
                                      const char * *  _certificate,
                                      const char * *  _privateKey)
 {
-    static CriticalSection securitySettingsCrit;
-    static bool useSSL = false;
-    static StringAttr certificate;
-    static StringAttr privateKey;
-    static bool retrieved = false;
-
     if (!retrieved)
     {
         CriticalBlock b(securitySettingsCrit);
@@ -2521,10 +2520,10 @@ bool replaceConfigurationDirectoryEntry(const char *path,const char *frommask,co
     return true;
 }
 
+static CriticalSection sect;
+static StringAttr processPath;
 const char * queryCurrentProcessPath()
 {
-    static CriticalSection sect;
-    static StringAttr processPath;
     CriticalBlock block(sect);
     if (processPath.isEmpty()) 
     {