Skip to content

Commit d2f670f

Browse files
Merge pull request #43 from aboutcode-org/add-more-cpp-tests
Add tests for more C++ source symbol extraction
2 parents 4a4707d + 02984c4 commit d2f670f

13 files changed

Lines changed: 1971 additions & 0 deletions
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#pragma once
2+
#include <mutex>
3+
#include <queue>
4+
5+
template <typename T>
6+
class FrameBuffer : public std::queue<T>
7+
{
8+
public:
9+
unsigned int frameCount;
10+
FrameBuffer() : frameCount(0) { mutex = new std::mutex(); };
11+
12+
void pushFrame(const T &FrameBuffering)
13+
{
14+
std::lock_guard<std::mutex> lock(*mutex);
15+
16+
std::queue<T>::push(FrameBuffering);
17+
frameCount += 1;
18+
}
19+
20+
T getFrame()
21+
{
22+
std::lock_guard<std::mutex> lock(*mutex);
23+
T lastestFrame = this->front();
24+
this->pop();
25+
frameCount -= 1;
26+
return lastestFrame;
27+
}
28+
29+
T peekFrame()
30+
{
31+
std::lock_guard<std::mutex> lock(*mutex);
32+
T lastestFrame = this->front();
33+
return lastestFrame;
34+
}
35+
36+
void clearBuffer()
37+
{
38+
std::lock_guard<std::mutex> lock(*mutex);
39+
while (!this->empty())
40+
this->pop();
41+
}
42+
43+
private:
44+
std::mutex *mutex;
45+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"files": [
3+
{
4+
"path": "ThreadBuffer.hpp",
5+
"type": "file",
6+
"source_symbols": [
7+
"FrameBuffer",
8+
"mutex",
9+
"FrameBuffering",
10+
"lock",
11+
"mutex",
12+
"push",
13+
"FrameBuffering",
14+
"frameCount",
15+
"lock",
16+
"mutex",
17+
"lastestFrame",
18+
"frameCount",
19+
"lastestFrame",
20+
"lock",
21+
"mutex",
22+
"lastestFrame",
23+
"lastestFrame",
24+
"lock",
25+
"mutex"
26+
],
27+
"source_strings": [],
28+
"scan_errors": []
29+
}
30+
]
31+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
PowerMail versatile mail receiver
3+
Copyright (C) 2002 PowerDNS.COM BV
4+
5+
This program is free software; you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with this program; if not, write to the Free Software
16+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+
*/
18+
#ifndef LOCK_HH
19+
#define LOCK_HH
20+
21+
#include <pthread.h>
22+
#include <iostream>
23+
#include <unistd.h>
24+
using namespace std;
25+
26+
27+
class RCMutex
28+
{
29+
public:
30+
class RCMutexImp
31+
{
32+
RCMutexImp() : count(1), d_mutex(new pthread_mutex_t)
33+
{
34+
35+
}
36+
~RCMutexImp()
37+
{
38+
delete d_mutex;
39+
}
40+
private:
41+
int count;
42+
pthread_mutex_t *d_mutex;
43+
44+
friend class RCMutex;
45+
};
46+
47+
RCMutex() : d_imp(new RCMutexImp)
48+
{
49+
}
50+
51+
RCMutex(const RCMutex &orig)
52+
{
53+
d_imp=orig.d_imp;
54+
d_imp->count++;
55+
}
56+
57+
RCMutex &operator=(const RCMutex& rhs)
58+
{
59+
if(rhs.d_imp!=d_imp) {
60+
if(!--d_imp->count)
61+
delete d_imp;
62+
63+
d_imp=rhs.d_imp;
64+
++d_imp->count;
65+
}
66+
return *this;
67+
}
68+
~RCMutex()
69+
{
70+
if(!--d_imp->count)
71+
delete d_imp;
72+
}
73+
74+
operator pthread_mutex_t*()
75+
{
76+
return d_imp->d_mutex;
77+
}
78+
79+
private:
80+
RCMutexImp *d_imp;
81+
};
82+
83+
class Lock
84+
{
85+
pthread_mutex_t *d_lock;
86+
public:
87+
88+
Lock(pthread_mutex_t *lock) : d_lock(lock)
89+
{
90+
pthread_mutex_lock(d_lock);
91+
92+
}
93+
~Lock()
94+
{
95+
pthread_mutex_unlock(d_lock);
96+
}
97+
98+
void un()
99+
{
100+
pthread_mutex_unlock(d_lock);
101+
}
102+
103+
void re()
104+
{
105+
pthread_mutex_lock(d_lock);
106+
}
107+
};
108+
#endif
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"files": [
3+
{
4+
"path": "lock.hh",
5+
"type": "file",
6+
"source_symbols": [
7+
"LOCK_HH",
8+
"LOCK_HH",
9+
"std",
10+
"RCMutexImp",
11+
"RCMutexImp",
12+
"d_mutex",
13+
"RCMutex",
14+
"RCMutex",
15+
"orig",
16+
"d_imp",
17+
"orig",
18+
"d_imp",
19+
"rhs",
20+
"rhs",
21+
"d_imp",
22+
"d_imp",
23+
"d_imp",
24+
"d_imp",
25+
"rhs",
26+
"d_imp",
27+
"RCMutex",
28+
"d_imp",
29+
"d_imp",
30+
"d_imp",
31+
"Lock",
32+
"lock",
33+
"lock",
34+
"pthread_mutex_lock",
35+
"d_lock",
36+
"Lock",
37+
"pthread_mutex_unlock",
38+
"d_lock",
39+
"pthread_mutex_unlock",
40+
"d_lock",
41+
"pthread_mutex_lock",
42+
"d_lock"
43+
],
44+
"source_strings": [],
45+
"scan_errors": []
46+
}
47+
]
48+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Copyright (c) 2012-2014 Konstantin Isakov <ikm@zbackup.org> and ZBackup contributors, see CONTRIBUTORS
2+
// Part of ZBackup. Licensed under GNU GPLv2 or later + OpenSSL, see LICENSE
3+
4+
#include "mt.hh"
5+
6+
#include <unistd.h>
7+
#include "check.hh"
8+
9+
Mutex::Mutex()
10+
{
11+
pthread_mutex_init( &mutex, 0 );
12+
}
13+
14+
void Mutex::lock()
15+
{
16+
pthread_mutex_lock( &mutex );
17+
}
18+
19+
void Mutex::unlock()
20+
{
21+
pthread_mutex_unlock( &mutex );
22+
}
23+
24+
Mutex::~Mutex()
25+
{
26+
pthread_mutex_destroy( &mutex );
27+
}
28+
29+
Condition::Condition()
30+
{
31+
pthread_cond_init( &cond, 0 );
32+
}
33+
34+
void Condition::signal()
35+
{
36+
pthread_cond_signal( &cond );
37+
}
38+
39+
void Condition::broadcast()
40+
{
41+
pthread_cond_broadcast( &cond );
42+
}
43+
44+
void Condition::wait( Mutex & m )
45+
{
46+
pthread_cond_wait( &cond, &m.mutex );
47+
}
48+
49+
Condition::~Condition()
50+
{
51+
pthread_cond_destroy( &cond );
52+
}
53+
54+
void * Thread::__thread_routine( void * param )
55+
{
56+
return ( (Thread *)param ) -> threadFunction();
57+
}
58+
59+
void Thread::start()
60+
{
61+
CHECK( pthread_create( &thread, 0, &__thread_routine, this ) == 0,
62+
"pthread_create() failed" );
63+
}
64+
65+
void Thread::detach()
66+
{
67+
CHECK( pthread_detach( thread ) == 0, "pthread_detach() failed" );
68+
}
69+
70+
void * Thread::join()
71+
{
72+
void * ret;
73+
pthread_join( thread, &ret );
74+
return ret;
75+
}
76+
77+
size_t getNumberOfCpus()
78+
{
79+
long result = sysconf( _SC_NPROCESSORS_ONLN );
80+
81+
// Handle -1 and also sanitize the 0 value which wouldn't make sense
82+
return result < 1 ? 1 : result;
83+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"files": [
3+
{
4+
"path": "mt.cc",
5+
"type": "file",
6+
"source_symbols": [
7+
"Mutex",
8+
"pthread_mutex_init",
9+
"mutex",
10+
"lock",
11+
"pthread_mutex_lock",
12+
"mutex",
13+
"unlock",
14+
"pthread_mutex_unlock",
15+
"mutex",
16+
"Mutex",
17+
"pthread_mutex_destroy",
18+
"mutex",
19+
"Condition",
20+
"pthread_cond_init",
21+
"cond",
22+
"signal",
23+
"pthread_cond_signal",
24+
"cond",
25+
"broadcast",
26+
"pthread_cond_broadcast",
27+
"cond",
28+
"wait",
29+
"m",
30+
"pthread_cond_wait",
31+
"cond",
32+
"m",
33+
"Condition",
34+
"pthread_cond_destroy",
35+
"cond",
36+
"__thread_routine",
37+
"param",
38+
"param",
39+
"start",
40+
"CHECK",
41+
"pthread_create",
42+
"thread",
43+
"__thread_routine",
44+
"detach",
45+
"CHECK",
46+
"pthread_detach",
47+
"thread",
48+
"join",
49+
"ret",
50+
"pthread_join",
51+
"thread",
52+
"ret",
53+
"ret",
54+
"getNumberOfCpus",
55+
"result",
56+
"sysconf",
57+
"_SC_NPROCESSORS_ONLN",
58+
"result",
59+
"result"
60+
],
61+
"source_strings": [
62+
"\"mt.hh\"",
63+
"\"check.hh\"",
64+
"\"pthread_create() failed\"",
65+
"\"pthread_detach() failed\""
66+
],
67+
"scan_errors": []
68+
}
69+
]
70+
}

0 commit comments

Comments
 (0)