Skip to content
Snippets Groups Projects
Commit 637c0a83 authored by Kurt Zeilenga's avatar Kurt Zeilenga
Browse files

Use strtok_r() instead of strtok(). Remove strtok mutex!

parent ddb0752b
No related branches found
No related tags found
No related merge requests found
......@@ -114,6 +114,7 @@ str2charray( char *str, char *brkstr )
{
char **res;
char *s;
char *lasts;
int i;
/* protect the input string from strtok */
......@@ -129,15 +130,13 @@ str2charray( char *str, char *brkstr )
res = (char **) ch_malloc( (i + 1) * sizeof(char *) );
i = 0;
pthread_mutex_lock(&strtok_mutex);
for ( s = strtok( str, brkstr ); s != NULL; s = strtok( NULL,
brkstr ) ) {
for ( s = strtok_r( str, brkstr, &lasts );
s != NULL;
s = strtok_r( NULL, brkstr, &lasts ) )
{
res[i++] = ch_strdup( s );
}
pthread_mutex_unlock(&strtok_mutex);
res[i] = NULL;
free( str );
......
......@@ -45,7 +45,6 @@ pthread_mutex_t new_conn_mutex;
#ifdef SLAPD_CRYPT
pthread_mutex_t crypt_mutex;
#endif
pthread_mutex_t strtok_mutex;
int num_conns;
long ops_initiated;
......@@ -70,7 +69,6 @@ init( void )
pthread_mutex_init( &new_conn_mutex, pthread_mutexattr_default );
pthread_mutex_init( &currenttime_mutex, pthread_mutexattr_default );
pthread_mutex_init( &strtok_mutex, pthread_mutexattr_default );
pthread_mutex_init( &entry2str_mutex, pthread_mutexattr_default );
pthread_mutex_init( &replog_mutex, pthread_mutexattr_default );
pthread_mutex_init( &ops_mutex, pthread_mutexattr_default );
......
......@@ -251,7 +251,6 @@ extern pthread_mutex_t active_threads_mutex;
extern pthread_cond_t active_threads_cond;
extern pthread_mutex_t currenttime_mutex;
extern pthread_mutex_t strtok_mutex;
extern pthread_mutex_t entry2str_mutex;
extern pthread_mutex_t new_conn_mutex;
extern pthread_mutex_t num_sent_mutex;
......
......@@ -519,8 +519,10 @@ generate_new_centroids(
/* generate a word-based centroid */
} else {
for ( w = strtok( val[j], WORD_BREAKS ); w != NULL;
w = strtok( NULL, WORD_BREAKS ) ) {
char *lasts;
for ( w = strtok_r( val[j], WORD_BREAKS, &lasts );
w != NULL;
w = strtok_r( NULL, WORD_BREAKS, &lasts ) ) {
key.dptr = w;
key.dsize = strlen( key.dptr ) + 1;
(void) ldbm_store( ldbm[i], key, data, LDBM_INSERT );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment