#include "string-private.h"
#include "debug-private.h"
+#include "thread-private.h"
#include "array.h"
-#include <stdlib.h>
#include <stddef.h>
#include <limits.h>
-#ifdef HAVE_PTHREAD_H
-# include <pthread.h>
-#endif /* HAVE_PTHREAD_H */
/*
* Local globals...
*/
-#ifdef HAVE_PTHREAD_H
-static pthread_mutex_t sp_mutex = PTHREAD_MUTEX_INITIALIZER;
+static _cups_mutex_t sp_mutex = _CUPS_MUTEX_INITIALIZER;
/* Mutex to control access to pool */
-#endif /* HAVE_PTHREAD_H */
static cups_array_t *stringpool = NULL;
/* Global string pool */
* Get the string pool...
*/
-#ifdef HAVE_PTHREAD_H
- pthread_mutex_lock(&sp_mutex);
-#endif /* HAVE_PTHREAD_H */
+ _cupsMutexLock(&sp_mutex);
if (!stringpool)
stringpool = cupsArrayNew((cups_array_func_t)compare_sp_items, NULL);
if (!stringpool)
{
-#ifdef HAVE_PTHREAD_H
- pthread_mutex_unlock(&sp_mutex);
-#endif /* HAVE_PTHREAD_H */
+ _cupsMutexUnlock(&sp_mutex);
return (NULL);
}
abort();
#endif /* DEBUG_GUARDS */
-#ifdef HAVE_PTHREAD_H
- pthread_mutex_unlock(&sp_mutex);
-#endif /* HAVE_PTHREAD_H */
+ _cupsMutexUnlock(&sp_mutex);
return (item->str);
}
item = (_cups_sp_item_t *)calloc(1, sizeof(_cups_sp_item_t) + strlen(s));
if (!item)
{
-#ifdef HAVE_PTHREAD_H
- pthread_mutex_unlock(&sp_mutex);
-#endif /* HAVE_PTHREAD_H */
+ _cupsMutexUnlock(&sp_mutex);
return (NULL);
}
cupsArrayAdd(stringpool, item);
-#ifdef HAVE_PTHREAD_H
- pthread_mutex_unlock(&sp_mutex);
-#endif /* HAVE_PTHREAD_H */
+ _cupsMutexUnlock(&sp_mutex);
return (item->str);
}
DEBUG_printf(("4_cupsStrFlush: %d strings in array",
cupsArrayCount(stringpool)));
-#ifdef HAVE_PTHREAD_H
- pthread_mutex_lock(&sp_mutex);
-#endif /* HAVE_PTHREAD_H */
+ _cupsMutexLock(&sp_mutex);
for (item = (_cups_sp_item_t *)cupsArrayFirst(stringpool);
item;
cupsArrayDelete(stringpool);
stringpool = NULL;
-#ifdef HAVE_PTHREAD_H
- pthread_mutex_unlock(&sp_mutex);
-#endif /* HAVE_PTHREAD_H */
+ _cupsMutexUnlock(&sp_mutex);
}
* See if the string is already in the pool...
*/
-#ifdef HAVE_PTHREAD_H
- pthread_mutex_lock(&sp_mutex);
-#endif /* HAVE_PTHREAD_H */
+ _cupsMutexLock(&sp_mutex);
key = (_cups_sp_item_t *)(s - offsetof(_cups_sp_item_t, str));
}
}
-#ifdef HAVE_PTHREAD_H
- pthread_mutex_unlock(&sp_mutex);
-#endif /* HAVE_PTHREAD_H */
+ _cupsMutexUnlock(&sp_mutex);
}
}
#endif /* DEBUG_GUARDS */
-#ifdef HAVE_PTHREAD_H
- pthread_mutex_lock(&sp_mutex);
-#endif /* HAVE_PTHREAD_H */
+ _cupsMutexLock(&sp_mutex);
item->ref_count ++;
-#ifdef HAVE_PTHREAD_H
- pthread_mutex_unlock(&sp_mutex);
-#endif /* HAVE_PTHREAD_H */
+ _cupsMutexUnlock(&sp_mutex);
}
return ((char *)s);
* Loop through strings in pool, counting everything up...
*/
-#ifdef HAVE_PTHREAD_H
- pthread_mutex_lock(&sp_mutex);
-#endif /* HAVE_PTHREAD_H */
+ _cupsMutexLock(&sp_mutex);
for (count = 0, abytes = 0, tbytes = 0,
item = (_cups_sp_item_t *)cupsArrayFirst(stringpool);
tbytes += item->ref_count * len;
}
-#ifdef HAVE_PTHREAD_H
- pthread_mutex_unlock(&sp_mutex);
-#endif /* HAVE_PTHREAD_H */
+ _cupsMutexUnlock(&sp_mutex);
/*
* Return values...