提交 27ccc688dd753e7debd900fdac82a153796fd863

作者 LJH 李佳桓
1 个父辈 7f0d7746

add

正在显示 1 个修改的文件 包含 81 行增加0 行删除
  1 +/*
  2 + * Copyright 2007 Stephen Liu
  3 + * For license terms, see the file COPYING along with this library.
  4 + */
  5 +
  6 +#ifndef __sputils_hpp__
  7 +#define __sputils_hpp__
  8 +
  9 +#include "spthread.hpp"
  10 +
  11 +class SP_ArrayList {
  12 +public:
  13 + static const int LAST_INDEX;
  14 +
  15 + SP_ArrayList( int initCount = 2 );
  16 + virtual ~SP_ArrayList();
  17 +
  18 + int getCount() const;
  19 + int append( void * value );
  20 + const void * getItem( int index ) const;
  21 + void * takeItem( int index );
  22 +
  23 + void clean();
  24 +
  25 +private:
  26 + SP_ArrayList( SP_ArrayList & );
  27 + SP_ArrayList & operator=( SP_ArrayList & );
  28 +
  29 + int mMaxCount;
  30 + int mCount;
  31 + void ** mFirst;
  32 +};
  33 +
  34 +class SP_CircleQueue {
  35 +public:
  36 + SP_CircleQueue();
  37 + virtual ~SP_CircleQueue();
  38 +
  39 + void push( void * item );
  40 + void * pop();
  41 + void * top();
  42 + int getLength();
  43 +
  44 +private:
  45 + void ** mEntries;
  46 + unsigned int mHead;
  47 + unsigned int mTail;
  48 + unsigned int mCount;
  49 + unsigned int mMaxCount;
  50 +};
  51 +
  52 +class SP_BlockingQueue {
  53 +public:
  54 + SP_BlockingQueue();
  55 + virtual ~SP_BlockingQueue();
  56 +
  57 + // non-blocking
  58 + void push( void * item );
  59 +
  60 + // blocking until can pop
  61 + void * pop();
  62 +
  63 + // non-blocking, if empty then return NULL
  64 + void * top();
  65 +
  66 + // non-blocking
  67 + int getLength();
  68 +
  69 +private:
  70 + SP_CircleQueue * mQueue;
  71 + sp_thread_mutex_t mMutex;
  72 + sp_thread_cond_t mCond;
  73 +};
  74 +
  75 +int sp_strtok( const char * src, int index, char * dest, int len,
  76 + char delimiter = ' ', const char ** next = 0 );
  77 +
  78 +char * sp_strlcpy( char * dest, const char * src, int n );
  79 +
  80 +#endif
  81 +
... ...
注册登录 后发表评论