Revision 1238 branches/threaded2merge/src/linad99/thread_stuff.cpp

thread_stuff.cpp (revision 1238)
1 1
#include <admodel.h>
2 2
#include <cstddef>
3
#include <cstring>
4
#include <thread>
3 5
#include "adthread.h"
4 6
#if !defined(OPT_LIB)
5 7
#  if !defined(CHK_ID_STRING)
......
941 943
  pthread_cond_signal(&condition);
942 944
  pthread_mutex_unlock(&mutex);
943 945
}
946
void adthread_buffer::push(const int value)
947
{
948
  const size_t v = value;
949
  push(v);
950
}
951
void adthread_buffer::pop(int& value)
952
{
953
  size_t v = 0;
954
  pop(v);
955
  value = v;
956
}
957
void adthread_buffer::push(const size_t value)
958
{
959
  const size_t size = sizeof(size_t);
960
  const char* v = (const char*)&value;
961
  buffer.append(v, size);
962
}
963
void adthread_buffer::pop(size_t& value)
964
{
965
  const size_t size = sizeof(size_t);
966
  const char* source = buffer.c_str();
967
  char* destination = (char*)&value;
968
  memcpy(destination, &source[buffer.size() - size], size);
969
  buffer.erase(buffer.size() - size, size);
970
}
971
void adthread_buffer::push(const double value)
972
{
973
  const size_t size = sizeof(double);
974
  const char* v = (const char*)&value;
975
  buffer.append(v, size);
976
}
977
void adthread_buffer::pop(double& value)
978
{
979
  const size_t size = sizeof(double);
980
  const char* source = buffer.c_str();
981
  char* destination = (char*)&value;
982
  memcpy(destination, &source[buffer.size() - size], size);
983
  buffer.erase(buffer.size() - size, size);
984
}
985
void adthread_buffer::push(const char* value)
986
{
987
  const size_t size = strlen(value);
988
  buffer.append(value, size);
989
  push(size);
990
}
991
void adthread_buffer::pop(char* value)
992
{
993
  size_t size = 0;
994
  pop(size);
995
  const char* source = buffer.c_str();
996
  memcpy(value, &source[buffer.size() - size], size);
997
  buffer.erase(buffer.size() - size, size);
998
}
999
adthread::adthread()
1000
{
1001
}
1002
adthread::adthread(const adthread& other)
1003
{
1004
}
1005
adthread::~adthread()
1006
{
1007
}
1008
void adthread::create()
1009
{
1010
  std::thread t(&routine);
1011
}
1012
void adthread::routine()
1013
{
1014
  cout << __func__ << ':' << __LINE__ << endl;
1015
}

Also available in: Unified diff