Ignore:
Timestamp:
Oct 6, 2001, 1:46:35 AM (24 years ago)
Author:
aubourg
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ArchTOIPipe/Kernel/toisegment.h

    r1670 r1671  
    22#ifndef TOISEGMENT_H
    33#define TOISEGMENT_H
     4
     5#include <vector>
     6#include <set>
    47
    58#include "toi.h"
     
    2124 
    2225 protected:
     26  class BufferSegment;
     27  class BufferView;
     28  class MasterView;
     29
     30
    2331  class BufferSegment {
    2432  public:
     
    2634    ~BufferSegment();
    2735    static const int NEW = 0;
    28     static const int WRITE = 1;
    29     static const int COMMITTED = 2;
     36    static const int WRITE = 1;     // single-thread write access
     37    static const int COMMITTED = 2; // multiple read without lock are ok
    3038   
    3139    int getStatus() {return status;}
    32 
    33 
     40    void incRefCount();
     41    void decRefCount();
     42    int  getRefCount();
     43   
    3444    void putData(int sn, double data, uint_8 flag);
    3545    inline double getData(int sn);
    3646    inline uint_8 getFlag(int sn);
     47
     48    bool isPastEnd(int sn) {
     49      return sn >= sn+bufferSize;
     50    }
    3751   
    3852  private:
     
    5973  };
    6074 
    61   // Master view, gere le lock...
     75  // Master view, gere le lock, et l'ecriture
    6276  class MasterView {
    6377  public:
    64     MasterView();
     78    MasterView(int bufsz=256, int maxseg=20);
    6579    ~MasterView();
    6680
     81    void putData(int sn, double data, uint_8 flag);
     82    void addToWaitList(BufferView* bv);
     83
     84    BufferView* getView(); // thread-specific
     85
    6786  protected:
    68     int s0;
     87    friend class BufferView;
     88    void signalWaitingViews();
     89    void nextSegment();
     90    BufferView* createView();
     91    void updateView(BufferView*); // called on reader thread of the view
     92   
     93    BufferSegment*   currentSegment;
     94
     95    int maxSegments;
     96    int bufferSize;
     97    int sn0;                // First sn in first buffer
     98    vector<BufferSegment*> segments; // Committed
    6999   
    70100    pthread_mutex_t  mutex; // lock for master buffer list access
    71     pthread_cond_t   condv; // waiting for new buffer
     101    pthread_cond_t   condv; // waiting (read or write)
     102
     103    static const int NO_WAIT   = 0;
     104    static const int WAIT_READ = 1;
     105    static const int WAIT_WRITE= 2;
     106    int  waitStatus;
     107
     108    set<BufferView*>  waitingBuffers;
    72109  };
    73110
     
    76113  class BufferView {
    77114  public:
     115    BufferView();
     116    ~BufferView();
    78117   
    79     void sync();
     118    void sync();  // recupere les nouveaux segments, resync avec master
     119    void wait();  // Passe en attente d'un nouveau segment
    80120  protected:
    81     MasterView master;
     121    friend class MasterView;
     122    MasterView* master;
     123    vector<BufferSegment*> segments; // Committed
     124    pthread_mutex_t  mutex; // lock pour attente de segments
     125    pthread_cond_t   condv; // attente de segments
    82126  }; 
     127
     128 
     129 
    83130};
    84131
Note: See TracChangeset for help on using the changeset viewer.