InfiniSQL  v0.1.2-alpha
Massive Scale Transaction Processing
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Mbox Class Reference

create mailbox More...

#include <Mbox.h>

Collaboration diagram for Mbox:

Public Member Functions

 Mbox ()
 
virtual ~Mbox ()
 
class Messagereceive (int timeout)
 consume a Message More...
 

Static Public Member Functions

static __int128 getInt128FromPointer (class Message *ptr, uint64_t count)
 create 128bit integer from Message object More...
 
static class MessagegetPtr (__int128 i128)
 return Message pointer from 128bit integer More...
 
static uint64_t getCount (__int128 i128)
 return count component from 128bit integer More...
 

Private Attributes

pthread_mutex_t mutexLast
 
class MessagefirstMsg
 
class MessagecurrentMsg
 
class MessagelastMsg
 
class MessagemyLastMsg
 
__int128 head
 
__int128 tail
 
__int128 current
 
__int128 mytail
 
uint64_t counter
 

Friends

class MboxProducer
 

Detailed Description

create mailbox

this is a queue, lockfree multi-producer single consumer adapted from: http://www.cs.rochester.edu/research/synchronization/pseudocode/queues.html

Definition at line 46 of file Mbox.h.

Constructor & Destructor Documentation

Mbox::Mbox ( )

lockfree producer adapted from: http://www.cs.rochester.edu/research/synchronization/pseudocode/queues.html

Definition at line 37 of file Mbox.cc.

References current, currentMsg, firstMsg, getInt128FromPointer(), head, lastMsg, Message::messageStruct, mutexLast, myLastMsg, mytail, Message::nextmsg, PAYLOADNONE, Message::message_s::payloadtype, and tail.

37  : counter(8888)
38 {
39  firstMsg = new class Message();
41  firstMsg->nextmsg = getInt128FromPointer(NULL, 5000);
43  lastMsg = firstMsg;
45 
47  tail = head;
48  current = head;
49  mytail = head;
50 
51  pthread_mutexattr_t attr;
52  attr.__align = PTHREAD_MUTEX_ADAPTIVE_NP;
53  pthread_mutex_init(&mutexLast, &attr);
54 }

Here is the call graph for this function:

Mbox::~Mbox ( )
virtual

Definition at line 56 of file Mbox.cc.

References firstMsg.

57 {
58  delete firstMsg;
59 }

Member Function Documentation

uint64_t Mbox::getCount ( __int128  i128)
static

return count component from 128bit integer

Parameters
i128input 128bit integer
Returns
count

Definition at line 120 of file Mbox.cc.

Referenced by receive(), and TransactionAgent::TransactionAgent().

121 {
122  return *((uint64_t *)&i128+1);
123 }

Here is the caller graph for this function:

__int128 Mbox::getInt128FromPointer ( class Message ptr,
uint64_t  count 
)
static

create 128bit integer from Message object

Parameters
ptrMessage variant
countcount component
Returns

Definition at line 106 of file Mbox.cc.

Referenced by Mbox(), and MboxProducer::sendMsg().

107 {
108  __int128 i128;
109  memcpy(&i128, &ptr, sizeof(ptr));
110  memcpy((uint64_t *)&i128+1, &count, sizeof(count));
111 
112  return i128;
113 }

Here is the caller graph for this function:

class Message * Mbox::getPtr ( __int128  i128)
static

return Message pointer from 128bit integer

Parameters
i128input 128bit integer
Returns
Message

Definition at line 115 of file Mbox.cc.

Referenced by receive(), MboxProducer::sendMsg(), and TransactionAgent::TransactionAgent().

116 {
117  return (class Message *)i128;
118 }

Here is the caller graph for this function:

class Message * Mbox::receive ( int  timeout)

consume a Message

Parameters
timeouttimeout in microseconds
Returns
Message object

Definition at line 66 of file Mbox.cc.

References current, getCount(), getPtr(), and Message::nextmsg.

Referenced by ObGateway::ObGateway().

67 {
68  __int128 mynext;
69 
70  while (1)
71  {
72  mynext = __atomic_load_n(&(getPtr(current)->nextmsg), __ATOMIC_SEQ_CST);
73 
74  if (getPtr(mynext)==NULL)
75  {
76  switch (timeout)
77  {
78  case -1:
79  break;
80 
81  case 0:
82  return NULL;
83  break;
84 
85  default:
86  struct timespec ts = {0, timeout * 1000};
87  nanosleep(&ts, NULL);
88  return NULL;
89  }
90  }
91  else
92  {
93  if (getPtr(current)==getPtr(mynext))
94  {
95  printf("%s %i WTF found it i guess count current %lu next %lu\n",
96  __FILE__, __LINE__, getCount(current), getCount(mynext));
97  }
98 
99  delete getPtr(current);
100  current = mynext;
101  return getPtr(current);
102  }
103  }
104 }

Here is the call graph for this function:

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class MboxProducer
friend

Definition at line 87 of file Mbox.h.

Member Data Documentation

uint64_t Mbox::counter
private

Definition at line 102 of file Mbox.h.

Referenced by MboxProducer::sendMsg().

__int128 Mbox::current
private

Definition at line 99 of file Mbox.h.

Referenced by Mbox(), and receive().

class Message* Mbox::currentMsg
private

Definition at line 93 of file Mbox.h.

Referenced by Mbox().

class Message* Mbox::firstMsg
private

Definition at line 92 of file Mbox.h.

Referenced by Mbox(), and ~Mbox().

__int128 Mbox::head
private

Definition at line 97 of file Mbox.h.

Referenced by Mbox().

class Message* Mbox::lastMsg
private

Definition at line 94 of file Mbox.h.

Referenced by Mbox().

pthread_mutex_t Mbox::mutexLast
private

Definition at line 90 of file Mbox.h.

Referenced by Mbox().

class Message* Mbox::myLastMsg
private

Definition at line 95 of file Mbox.h.

Referenced by Mbox().

__int128 Mbox::mytail
private

Definition at line 100 of file Mbox.h.

Referenced by Mbox().

__int128 Mbox::tail
private

Definition at line 98 of file Mbox.h.

Referenced by Mbox(), and MboxProducer::sendMsg().


The documentation for this class was generated from the following files: