Ignore:
Timestamp:
05/11/17 16:12:23 (7 years ago)
Author:
yushan
Message:

log OK with threads

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/branch_yushan/src/log.hpp

    r1081 r1128  
    55#include <iostream> 
    66#include <string> 
     7#include <stdio.h> 
     8#include <omp.h> 
    79 
    810namespace xios 
     
    1416    public : 
    1517    CLog(const string& name_, std::streambuf* sBuff = cout.rdbuf()) 
    16       : ostream(sBuff), level(0), name(name_), strBuf_(sBuff) {} 
    17     CLog& operator()(int l) 
     18      : ostream(cout.rdbuf()), level(0), name(name_), strBuf_(sBuff)  
    1819    { 
    19       if (l<=level) 
    20       { 
    21         rdbuf(strBuf_); 
    22         *this<<"-> "<<name<<" : " ; 
    23       } 
    24       else rdbuf(NULL) ; 
    25       return *this; 
     20      omp_init_lock( &mutex ); 
     21      for(int i=0; i<10; i++) 
     22        strBuf_array[i] = sBuff; 
    2623    } 
     24 
     25    ~CLog() 
     26    { 
     27      omp_destroy_lock( &mutex ); 
     28    } 
     29 
     30 
     31    CLog& operator()(int l); 
    2732    void setLevel(int l) {level=l; } 
    2833    int  getLevel() {return level ;} 
     
    4651     * \param [in] pointer to new streambuf 
    4752    */ 
    48     void changeStreamBuff(std::streambuf* sBuff) { strBuf_ = sBuff; rdbuf(sBuff); } 
     53    void changeStreamBuff(std::streambuf* sBuff)  
     54    {  
     55      strBuf_ = sBuff;  
     56      strBuf_array[omp_get_thread_num()] = sBuff; 
     57      rdbuf(sBuff); 
     58    } 
    4959 
    5060    int level ; 
    5161    string name ; 
    5262    std::streambuf* strBuf_; 
     63    std::streambuf* strBuf_array[10]; 
     64    omp_lock_t mutex; 
    5365  }; 
    5466 
     
    5668  extern CLog report; 
    5769  extern CLog error; 
     70 
     71 
     72  extern std::filebuf* info_FB[10]; 
     73 
     74 
    5875} 
    5976#endif 
Note: See TracChangeset for help on using the changeset viewer.