00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __EID_SEQUENCES__
00021 #define __EID_SEQUENCES__
00022 #include "config.h"
00023 #include <cstdlib>
00024 #include <iostream>
00025 #include <sstream>
00026 #include <ctime>
00027 #include <memory>
00028 #include <cstring>
00029 #include <string>
00030 #include <ctime>
00031 #include <list>
00032 #include <queue>
00033
00034 #include <pthread.h>
00035 #include <errno.h>
00036
00037 #include "eid_connection.h"
00038
00039 #ifdef __WIN__
00040 typedef unsigned __int64 ulonglong;
00041 typedef __int64 longlong;
00042 #else
00043 typedef unsigned long long ulonglong;
00044 typedef long long longlong;
00045 #endif
00046
00047 #include <map>
00048
00049 namespace eid {
00050 class SequencePack {
00051 public:
00052 SequencePack();
00053 SequencePack(const char* _seqName, int _bufferMin, int _bufferPack);
00054
00055 ConnectionPack *clientPack;
00056 pthread_mutex_t clientMutex;
00057
00058 std::queue<longlong> buffor;
00059 pthread_mutex_t bufforMutex;
00060 int bufforMin;
00061 int bufforPack;
00062
00063 std::string seqName;
00064 int id;
00065 pthread_t thread;
00066
00067 pthread_mutex_t updateBufforMutex;
00068 pthread_cond_t updateBufforCondition;
00069 int updateBufforPredicate;
00070
00071 longlong getNext(int &error);
00072 private:
00073
00074 struct UpdateBufforArgs {
00075 int *error;
00076 SequencePack* owner;
00077 };
00078
00079 static void *updateBuffor(void *args);
00080
00081 longlong buffor_get_next();
00082
00083 void buffor_lock();
00084 void buffor_unlock();
00085 };
00086
00087 longlong getNext(const char *seq, int &error);
00088
00089
00090
00091
00092
00093 template<class T, class E>
00094 T to_num(std::basic_string<E> str) {
00095 std::stringstream ss(str);
00096 T res;
00097 ss >> res;
00098 return res;
00099 };
00100 }
00101 #endif