tcpflow  1.6.1
About: tcpflow is a TCP/IP packet demultiplexer that captures data transmitted as part of TCP connections (flows), and stores the data in a way that is convenient for protocol analysis and debugging.
  Fossies Dox: tcpflow-1.6.1.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

cppmutex.h
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 
3 /**
4  * Cppmutex is an easy-to-use mutex class.
5  * Create a cppmutex instance for a mutex.
6  * Create a cppmutex::lock(M) object to get a lock; delete the object to free it.
7  *
8  * BE SURE THAT HAVE_PTHREAD IS DEFINED BEFORE INCLUDING THIS FILE
9  */
10 
11 
12 #ifndef CPPMUTEX_H
13 #define CPPMUTEX_H
14 
15 #include <stdlib.h>
16 #include <iostream>
17 #include <errno.h>
18 #include <string.h>
19 
20 #include <pthread.h>
21 #include <exception>
22 
23 class cppmutex {
24  // default copy construction and assignment are meaningless and not implemented
25  cppmutex(const cppmutex &c);
27 
28 public:
29  pthread_mutex_t M;
30 public:
31  cppmutex():M(){
32  if(pthread_mutex_init(&M,NULL)){
33  std::cerr << "pthread_mutex_init failed: " << strerror(errno) << "\n";
34  exit(1);
35  }
36  }
37  virtual ~cppmutex(){
38  pthread_mutex_destroy(&M);
39  }
40  class lock { // get
41  private:
43  lock(const lock &l); // copy of locks is meaningless
44  lock &operator=(const lock &l);
45  public:
47  pthread_mutex_lock(&myMutex.M);
48  }
49  ~lock(){
50  pthread_mutex_unlock(&myMutex.M);
51  }
52  };
53 };
54 
55 #endif
lock(const lock &l)
cppmutex & myMutex
Definition: cppmutex.h:42
lock(cppmutex &m)
Definition: cppmutex.h:46
lock & operator=(const lock &l)
cppmutex(const cppmutex &c)
cppmutex & operator=(const cppmutex &cp)
pthread_mutex_t M
Definition: cppmutex.h:29
virtual ~cppmutex()
Definition: cppmutex.h:37
cppmutex()
Definition: cppmutex.h:31
int c
Definition: tcpdemux.cpp:366