Hi Brian,

I have a suggestion for this code.  I am wondering why you have used a
#define on _HAVE_GLIBCXX_TLS?  You have already included
boost::thread, so why not use Boost thread-local storage and remove
the need for #define's using the following code:

// in /drizzled/table_identifier.cc
#include <boost/thread/thread.hpp>
#include <boost/thread/tss.hpp>

using namespace boost;

namespace drizzled
{
thread_specific_ptr<uint32_t> tmp_table_counter;

// then, in the build_tmptable_filename() function, you can do:

uint32_t *counter_value= tmp_table_counter.get();
if (counter_value == NULL)
{
  tmp_table_counter.reset(new int(0));
  *counter_value= tmp_table_counter.get();
}
else
{
  ++(*counter_value);
}
post_tmpdir_str << pthread_self() << *counter_value;

}

-jay

On Tue, Jun 8, 2010 at 1:48 AM,  <[email protected]> wrote:
> ------------------------------------------------------------
> revno: 1602
> committer: Brian Aker <br...@gaz>
> branch nick: rollup
> timestamp: Mon 2010-06-07 17:40:06 -0700
> message:
>  Update for current_session removal.
> modified:
>  drizzled/table_identifier.cc
>
>
> --
> lp:drizzle
> https://code.launchpad.net/~drizzle-developers/drizzle/development
>
> You are subscribed to branch lp:drizzle.
> To unsubscribe from this branch go to 
> https://code.launchpad.net/~drizzle-developers/drizzle/development/+edit-subscription
>
> === modified file 'drizzled/table_identifier.cc'
> --- drizzled/table_identifier.cc        2010-06-07 16:59:18 +0000
> +++ drizzled/table_identifier.cc        2010-06-08 00:40:06 +0000
> @@ -24,7 +24,6 @@
>
>  #include "drizzled/table_identifier.h"
>  #include "drizzled/session.h"
> -#include "drizzled/current_session.h"
>  #include "drizzled/internal/my_sys.h"
>  #include "drizzled/data_home.h"
>
> @@ -34,6 +33,8 @@
>  #include <sstream>
>  #include <cstdio>
>
> +#include <boost/thread.hpp>
> +
>  using namespace std;
>
>  namespace drizzled
> @@ -114,18 +115,39 @@
>     path length on success, 0 on failure
>  */
>
> +#ifdef _GLIBCXX_HAVE_TLS
> +__thread uint32_t counter= 0;
> +
> +static uint32_t get_counter()
> +{
> +  return ++counter;
> +}
> +
> +#else
> +boost::mutex counter_mutex;
> +static uint32_t counter= 1;
> +
> +static uint32_t get_counter()
> +{
> +  boost::mutex::scoped_lock lock(counter_mutex);
> +  uint32_t x;
> +  x= ++counter;
> +
> +  return x;
> +}
> +
> +#endif
> +
>  static size_t build_tmptable_filename(std::string &buffer)
>  {
>   size_t tmpdir_length;
>   ostringstream post_tmpdir_str;
>
> -  Session *session= current_session;
> -
>   buffer.append(drizzle_tmpdir);
>   tmpdir_length= buffer.length();
>
>   post_tmpdir_str << "/" << TMP_FILE_PREFIX << current_pid;
> -  post_tmpdir_str << session->thread_id << session->tmp_table++;
> +  post_tmpdir_str << pthread_self() << get_counter();
>
>   buffer.append(post_tmpdir_str.str());
>
>
>
>

_______________________________________________
Mailing list: https://launchpad.net/~drizzle-discuss
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~drizzle-discuss
More help   : https://help.launchpad.net/ListHelp

Reply via email to