]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/string.c
Merge changes from CUPS 1.5svn-r9105.
[thirdparty/cups.git] / cups / string.c
index 9e60076a2c85331ad1db86e9b7117dfbe5f85c33..96f6728a84dec6cdf967948653711838f9c2d763 100644 (file)
 
 #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 */
 
@@ -88,18 +83,14 @@ _cupsStrAlloc(const char *s)                /* I - String */
   * 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);
   }
@@ -127,9 +118,7 @@ _cupsStrAlloc(const char *s)                /* I - String */
       abort();
 #endif /* DEBUG_GUARDS */
 
-#ifdef HAVE_PTHREAD_H
-    pthread_mutex_unlock(&sp_mutex);
-#endif /* HAVE_PTHREAD_H */
+    _cupsMutexUnlock(&sp_mutex);
 
     return (item->str);
   }
@@ -141,9 +130,7 @@ _cupsStrAlloc(const char *s)                /* I - String */
   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);
   }
@@ -165,9 +152,7 @@ _cupsStrAlloc(const char *s)                /* I - String */
 
   cupsArrayAdd(stringpool, item);
 
-#ifdef HAVE_PTHREAD_H
-  pthread_mutex_unlock(&sp_mutex);
-#endif /* HAVE_PTHREAD_H */
+  _cupsMutexUnlock(&sp_mutex);
 
   return (item->str);
 }
@@ -186,9 +171,7 @@ _cupsStrFlush(void)
   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;
@@ -198,9 +181,7 @@ _cupsStrFlush(void)
   cupsArrayDelete(stringpool);
   stringpool = NULL;
 
-#ifdef HAVE_PTHREAD_H
-  pthread_mutex_unlock(&sp_mutex);
-#endif /* HAVE_PTHREAD_H */
+  _cupsMutexUnlock(&sp_mutex);
 }
 
 
@@ -317,9 +298,7 @@ _cupsStrFree(const char *s)         /* I - String to free */
   * 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));
 
@@ -353,9 +332,7 @@ _cupsStrFree(const char *s)         /* I - String to free */
     }
   }
 
-#ifdef HAVE_PTHREAD_H
-  pthread_mutex_unlock(&sp_mutex);
-#endif /* HAVE_PTHREAD_H */
+  _cupsMutexUnlock(&sp_mutex);
 }
 
 
@@ -386,15 +363,11 @@ _cupsStrRetain(const char *s)             /* I - String to retain */
     }
 #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);
@@ -558,9 +531,7 @@ _cupsStrStatistics(size_t *alloc_bytes,     /* O - Allocated bytes */
   * 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);
@@ -577,9 +548,7 @@ _cupsStrStatistics(size_t *alloc_bytes,     /* O - Allocated bytes */
     tbytes += item->ref_count * len;
   }
 
-#ifdef HAVE_PTHREAD_H
-  pthread_mutex_unlock(&sp_mutex);
-#endif /* HAVE_PTHREAD_H */
+  _cupsMutexUnlock(&sp_mutex);
 
  /*
   * Return values...