Changeset 134 for trunk/src/sh_tiger0.c


Ignore:
Timestamp:
Oct 26, 2007, 12:20:10 AM (12 years ago)
Author:
rainer
Message:

More thread-safety changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sh_tiger0.c

    r133 r134  
    100100 */
    101101
    102 static sh_byte buffer[PRIV_MAX + 72];
     102/* static sh_byte buffer[PRIV_MAX + 72]; */
    103103
    104104#if defined(TIGER_64_BIT)
     
    121121  UINT64    bcount = 0;
    122122
    123   static int lockflag = SL_FALSE;
     123  char * buffer = SH_ALLOC(PRIV_MAX + 72);
    124124
    125125  unsigned long pages_read;
     
    176176                           MSG_E_ACCESS, (long) euid, tmp);
    177177          SH_FREE(tmp);
     178          SH_FREE(buffer);
    178179          SL_RETURN( NULL, _("sh_tiger_hash_val"));
    179180        }
    180181
    181       SH_MUTEX_LOCK(mutex_skey); 
    182182#if defined(HAVE_MLOCK) && !defined(HAVE_BROKEN_MLOCK)
    183     if ((lockflag == SL_FALSE) && (skey->mlock_failed == SL_FALSE))
     183    if (skey->mlock_failed == SL_FALSE)
    184184      {
    185         lockflag = SL_TRUE;
    186185        if ( (-1) == sh_unix_mlock(FIL__, __LINE__,
    187186                                   (char *)buffer,
    188187                                   (PRIV_MAX)*sizeof(sh_byte)))
    189           skey->mlock_failed = SL_TRUE;
     188          {
     189            SH_MUTEX_LOCK_UNSAFE(mutex_skey); 
     190            skey->mlock_failed = SL_TRUE;
     191            SH_MUTEX_UNLOCK_UNSAFE(mutex_skey);
     192          }
    190193      }
    191194#else
    192     if (lockflag == SL_FALSE && skey->mlock_failed == SL_FALSE)
     195    if (skey->mlock_failed == SL_FALSE)
    193196      {
    194         lockflag = SL_TRUE;
     197        SH_MUTEX_LOCK_UNSAFE(mutex_skey); 
    195198        skey->mlock_failed = SL_TRUE;
     199        SH_MUTEX_UNLOCK_UNSAFE(mutex_skey);
    196200      }
    197201#endif
    198     SH_MUTEX_UNLOCK(mutex_skey);
    199202
    200203#ifdef TIGER_DBG
     
    216219          {
    217220            if (sig_termfast == 1) {
     221              sh_unix_munlock((char *)buffer, (PRIV_MAX)*sizeof(sh_byte));
     222              SH_FREE(buffer);
    218223              SL_RETURN( NULL, _("sh_tiger_hash_val"));
    219224            }
     
    234239            memset (buffer, 0, PRIV_MAX);
    235240
     241            sh_unix_munlock((char *)buffer, (PRIV_MAX)*sizeof(sh_byte));
     242            SH_FREE(buffer);
    236243            SL_RETURN( NULL, _("sh_tiger_hash_val"));
    237244          }
     
    278285            memset (bbuf,   0, 64);
    279286            memset (buffer, 0, PRIV_MAX);
    280 
     287            sh_unix_munlock((char *)buffer, (PRIV_MAX)*sizeof(sh_byte));
     288            SH_FREE(buffer);
    281289            SL_RETURN( NULL, _("sh_tiger_hash_val"));
    282290          }
     
    364372    if (what == TIGER_FILE)
    365373      (void) sl_close (fd);
    366 
     374    sh_unix_munlock((char *)buffer, (PRIV_MAX)*sizeof(sh_byte));
     375    SH_FREE(buffer);
    367376    SL_RETURN( res, _("sh_tiger_hash_val"));
    368377  }
     
    370379  if (what == TIGER_DATA && filename != NULL)
    371380    {
    372       tiger(TIGER_CAST filename, (sh_word32) Length, res);
     381      tiger(TIGER_CAST filename, (sh_word32) Length, res);
     382      sh_unix_munlock((char *)buffer, (PRIV_MAX)*sizeof(sh_byte));
     383      SH_FREE(buffer);
    373384      SL_RETURN(res, _("sh_tiger_hash_val"));
    374385    }
     386  sh_unix_munlock((char *)buffer, (PRIV_MAX)*sizeof(sh_byte));
     387  SH_FREE(buffer);
    375388  SL_RETURN( NULL, _("sh_tiger_hash_val"));
    376389}
Note: See TracChangeset for help on using the changeset viewer.