Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3272 in orxonox.OLD for orxonox/branches


Ignore:
Timestamp:
Dec 24, 2004, 8:41:18 PM (20 years ago)
Author:
bensch
Message:

orxonox/branches/updater: using pthread as Threader.

Location:
orxonox/branches/updater
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/updater/configure

    r3271 r3272  
    69696969
    69706970
    6971 #checking for pthread libs
    6972 # AC_CHECK_LIB([pthread], [main], FOUND_pthread=yes)
    6973 # if test "$FOUND_pthread" = "yes" ; then
    6974 #    LIBS="$LIBS -lpthread"
    6975 # fi
     6971checking for pthread libs
     6972echo "$as_me:$LINENO: checking for main in -lpthread" >&5
     6973echo $ECHO_N "checking for main in -lpthread... $ECHO_C" >&6
     6974if test "${ac_cv_lib_pthread_main+set}" = set; then
     6975  echo $ECHO_N "(cached) $ECHO_C" >&6
     6976else
     6977  ac_check_lib_save_LIBS=$LIBS
     6978LIBS="-lpthread  $LIBS"
     6979cat >conftest.$ac_ext <<_ACEOF
     6980/* confdefs.h.  */
     6981_ACEOF
     6982cat confdefs.h >>conftest.$ac_ext
     6983cat >>conftest.$ac_ext <<_ACEOF
     6984/* end confdefs.h.  */
     6985
     6986
     6987int
     6988main ()
     6989{
     6990main ();
     6991  ;
     6992  return 0;
     6993}
     6994_ACEOF
     6995rm -f conftest.$ac_objext conftest$ac_exeext
     6996if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
     6997  (eval $ac_link) 2>conftest.er1
     6998  ac_status=$?
     6999  grep -v '^ *+' conftest.er1 >conftest.err
     7000  rm -f conftest.er1
     7001  cat conftest.err >&5
     7002  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     7003  (exit $ac_status); } &&
     7004         { ac_try='test -z "$ac_c_werror_flag"
     7005                         || test ! -s conftest.err'
     7006  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
     7007  (eval $ac_try) 2>&5
     7008  ac_status=$?
     7009  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     7010  (exit $ac_status); }; } &&
     7011         { ac_try='test -s conftest$ac_exeext'
     7012  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
     7013  (eval $ac_try) 2>&5
     7014  ac_status=$?
     7015  echo "$as_me:$LINENO: \$? = $ac_status" >&5
     7016  (exit $ac_status); }; }; then
     7017  ac_cv_lib_pthread_main=yes
     7018else
     7019  echo "$as_me: failed program was:" >&5
     7020sed 's/^/| /' conftest.$ac_ext >&5
     7021
     7022ac_cv_lib_pthread_main=no
     7023fi
     7024rm -f conftest.err conftest.$ac_objext \
     7025      conftest$ac_exeext conftest.$ac_ext
     7026LIBS=$ac_check_lib_save_LIBS
     7027fi
     7028echo "$as_me:$LINENO: result: $ac_cv_lib_pthread_main" >&5
     7029echo "${ECHO_T}$ac_cv_lib_pthread_main" >&6
     7030if test $ac_cv_lib_pthread_main = yes; then
     7031  FOUND_pthread=yes
     7032fi
     7033
     7034 if test "$FOUND_pthread" = "yes" ; then
     7035    LIBS="$LIBS -lpthread"
     7036 fi
    69767037
    69777038
  • orxonox/branches/updater/configure.ac

    r3271 r3272  
    403403
    404404
    405 #checking for pthread libs
    406 # AC_CHECK_LIB([pthread], [main], FOUND_pthread=yes)
    407 # if test "$FOUND_pthread" = "yes" ; then
    408 #    LIBS="$LIBS -lpthread"
    409 # fi
     405checking for pthread libs
     406AC_CHECK_LIB([pthread], [main], FOUND_pthread=yes)
     407 if test "$FOUND_pthread" = "yes" ; then
     408    LIBS="$LIBS -lpthread"
     409 fi
    410410
    411411
  • orxonox/branches/updater/src/gui/orxonox_gui_update.cc

    r3271 r3272  
    201201
    202202CURL* OrxonoxGuiUpdate::curlHandle = NULL;
    203 GThread* OrxonoxGuiUpdate::downloadThreadID = NULL;
     203pthread_t* OrxonoxGuiUpdate::downloadThreadID = new pthread_t;
     204bool OrxonoxGuiUpdate::isDownloading = false;
    204205
    205206void* OrxonoxGuiUpdate::download (void* fileInfo)
     
    209210  FileInfo* info = (FileInfo*)fileInfo;
    210211  CURLcode res;
    211   FILE* outfile;
    212212  curlHandle = curl_easy_init();
    213213  char* fileOnNet = new char [strlen(info->webRoot)+strlen(info->fileName)+1];
     
    217217  strcpy (fileOnDisk, info->localRoot);
    218218  strcat (fileOnDisk, info->fileName);
    219 
     219  pthread_t test;
    220220  if(curlHandle)
    221221    {
    222222     
    223       outfile = fopen(fileOnDisk, "w");
     223      info->fileHandle = fopen(fileOnDisk, "w");
    224224
    225225      curl_easy_setopt(curlHandle, CURLOPT_URL, fileOnNet);
    226       curl_easy_setopt(curlHandle, CURLOPT_WRITEDATA, outfile);
     226      curl_easy_setopt(curlHandle, CURLOPT_WRITEDATA, info->fileHandle);
    227227      curl_easy_setopt(curlHandle, CURLOPT_WRITEFUNCTION, curlWriteFunc);
    228228      curl_easy_setopt(curlHandle, CURLOPT_READFUNCTION, curlReadFunc);
     
    231231      curl_easy_setopt(curlHandle, CURLOPT_PROGRESSDATA, info->Bar);
    232232
    233       if (!downloadThreadID)
     233      if (!isDownloading)
    234234        {
    235235          //! \todo check if threads really were created.
    236           downloadThreadID = g_thread_create(&downloadThread, info, TRUE, NULL);
    237 
    238           g_thread_create(&downloadThreadFinished, outfile, TRUE, NULL);
     236          pthread_create(downloadThreadID, NULL, downloadThread, info);
     237          //      else
     238          //    PRINTF(1)("thread already in use\n");
     239          //      res = curl_easy_perform(curlHandle);
     240         
     241          //      fclose(outfile);
    239242        }
    240       else
    241         PRINTF(1)("thread already in use\n");
    242       //      res = curl_easy_perform(curlHandle);
    243      
    244       //      fclose(outfile);
    245243    }
    246   //  downloadThreadID = NULL;
    247244  return NULL;
    248245}
    249246void* OrxonoxGuiUpdate::downloadThread(void* fileInfo)
    250247{
    251   //  gdk_threads_enter();
     248  isDownloading = true;
     249
     250  FileInfo* info = (FileInfo*)fileInfo;
    252251  curl_easy_perform(curlHandle);
    253252  if (curlHandle)
    254253    curl_easy_cleanup(curlHandle);
    255   gdk_threads_leave();
    256   downloadThreadID = NULL;
    257   //  g_thread_exit (NULL);
    258 }
    259 
    260 void* OrxonoxGuiUpdate::downloadThreadFinished(void* outfile)
    261 {
    262   g_thread_join(downloadThreadID);
     254
     255  pthread_join(*downloadThreadID, NULL);
    263256  PRINTF(3)("Closing the downloaded file.\n");
    264   fclose((FILE*)outfile);
    265 }
     257  fclose(info->fileHandle);
     258
     259  isDownloading = false;
     260}
     261
    266262
    267263#ifdef HAVE_GTK2
  • orxonox/branches/updater/src/gui/orxonox_gui_update.h

    r3271 r3272  
    1414#include <curl/easy.h>
    1515#endif /* HAVE_CURL */
     16#include <pthread.h>
    1617using namespace std;
    1718
     
    5051    char* webRoot;        //!< The Root of the File on The Web
    5152    char* localRoot;      //!< The Root directory to put the files on the local disk.
     53    FILE* fileHandle;     //!< A fileHandler.
    5254
    5355    ProgressBar* Bar;     //!< The ProgressBar, that sould be updated.
     
    6264  static gint cancelDownload(GtkWidget* w, GdkEventKey* event, void* bar);
    6365#endif /* HAVE_GTK2 */ 
    64   static GThread* downloadThreadID;
     66  static pthread_t* downloadThreadID;
     67  static bool isDownloading;
     68
    6569  static void* download (void* fileInfo);
    6670  static void* downloadThread (void* fileInfo);
Note: See TracChangeset for help on using the changeset viewer.