]> mj.ucw.cz Git - libucw.git/blobdiff - lib/fb-temp.c
Fixed bug in joining.
[libucw.git] / lib / fb-temp.c
index ed7623ffc85edc5989678a5be0106c5124064881..4bcced6c4ecd56c5d3bac1064845807a09cd5917 100644 (file)
@@ -10,7 +10,9 @@
 #include "lib/lib.h"
 #include "lib/conf.h"
 #include "lib/fastbuf.h"
+#include "lib/threads.h"
 
+#include <stdio.h>
 #include <unistd.h>
 #include <sys/fcntl.h>
 
@@ -28,49 +30,18 @@ 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);
-
+  struct ucwlib_context *ctx = ucwlib_thread_context();
+  int cnt = ++ctx->temp_counter;
   int pid = getpid();
-#if 0
-  /* FIXME: This is Linux-specific and not declared anywhere :( */
-  int tid = gettid();
-#else
-  int tid = pid;
-#endif
-  if (pid == tid)
+  if (ctx->thread_id == pid)
     sprintf(buf, "%s%d-%d", temp_prefix, pid, cnt);
   else
-    sprintf(buf, "%s%d-%d-%d", temp_prefix, pid, tid, cnt);
+    sprintf(buf, "%s%d-%d-%d", temp_prefix, pid, ctx->thread_id, 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)
 {