]> mj.ucw.cz Git - libucw.git/commitdiff
Converted the fb-temp module to use threads.h.
authorMartin Mares <mj@ucw.cz>
Sat, 9 Dec 2006 20:57:04 +0000 (21:57 +0100)
committerMartin Mares <mj@ucw.cz>
Sat, 9 Dec 2006 20:57:04 +0000 (21:57 +0100)
lib/fb-temp.c

index ed7623ffc85edc5989678a5be0106c5124064881..aa1689c4f4259fd1618c7d7bd4b67790cf5a4319 100644 (file)
@@ -10,6 +10,7 @@
 #include "lib/lib.h"
 #include "lib/conf.h"
 #include "lib/fastbuf.h"
+#include "lib/threads.h"
 
 #include <unistd.h>
 #include <sys/fcntl.h>
@@ -28,25 +29,10 @@ static void CONSTRUCTOR temp_global_init(void)
   cf_declare_section("Tempfiles", &temp_config, 0);
 }
 
-#ifdef CONFIG_UCW_THREADS
-#include <pthread.h>
-
-static pthread_key_t temp_counter_key;
-
-static void CONSTRUCTOR
-temp_key_init(void)
-{
-  if (pthread_key_create(&temp_counter_key, NULL) < 0)
-    die("Cannot create fbdir_queue_key: %m");
-}
-
 void
 temp_file_name(byte *buf)
 {
-  int cnt = (int) pthread_getspecific(temp_counter_key);
-  cnt++;
-  pthread_setspecific(temp_counter_key, (void *) cnt);
-
+  int cnt = ++ucwlib_thread_context()->temp_counter;
   int pid = getpid();
 #if 0
   /* FIXME: This is Linux-specific and not declared anywhere :( */
@@ -60,17 +46,6 @@ temp_file_name(byte *buf)
     sprintf(buf, "%s%d-%d-%d", temp_prefix, pid, tid, cnt);
 }
 
-#else
-
-void
-temp_file_name(byte *buf)
-{
-  static int cnt;
-  sprintf(buf, "%s%d-%d", temp_prefix, (int)getpid(), cnt++);
-}
-
-#endif
-
 struct fastbuf *
 bopen_tmp(uns buflen)
 {