Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 0 additions & 66 deletions .github/workflows/sonarqube.yml

This file was deleted.

9 changes: 4 additions & 5 deletions examples/examples_base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <iostream>
#include <map>
#include <thread>
#include <unistd.h>

#include "../include/base64.h"

Expand All @@ -17,8 +16,8 @@ namespace examples::base64 {

constexpr std::string_view str{"hello world"};

std::string b64 = small::tobase64(str);
auto vb64 = small::tobase64<std::vector<char>>(str.data(), str.size());
std::string b64 = small::tobase64(str);
auto vb64 = small::tobase64<std::vector<char>>(str.data(), str.size());

std::cout << "base64(\"" << str << "\") is " << b64 << "\n";
std::cout << "base64 as vector(\"" << str << "\") is ";
Expand All @@ -27,8 +26,8 @@ namespace examples::base64 {
}
std::cout << "\n";

std::string decoded = small::frombase64(vb64);
auto decodedvd64 = small::frombase64<std::vector<char>>(b64);
std::string decoded = small::frombase64(vb64);
auto decodedvd64 = small::frombase64<std::vector<char>>(b64);

std::cout << "decoded base64 is \"" << decoded << "\"\n";

Expand Down
1 change: 0 additions & 1 deletion examples/examples_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <iostream>
#include <map>
#include <thread>
#include <unistd.h>

#include "../include/buffer.h"

Expand Down
3 changes: 1 addition & 2 deletions examples/examples_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <cstdio>
#include <iostream>
#include <thread>
#include <unistd.h>

#include "../include/event.h"
#include "../include/util.h"
Expand Down Expand Up @@ -34,7 +33,7 @@ namespace examples::event {
};

// create thread
const int iterations = 3;
const int iterations = 3;
std::thread t[3];
for (size_t i = 0; i < sizeof(t) / sizeof(t[0]); ++i) {
t[i] = std::thread(fn_t, i, iterations, std::ref(e));
Expand Down
1 change: 0 additions & 1 deletion examples/examples_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <iostream>
#include <map>
#include <thread>
#include <unistd.h>

#include "../include/hash.h"

Expand Down
1 change: 0 additions & 1 deletion examples/examples_jobs_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <iostream>
#include <map>
#include <thread>
#include <unistd.h>

#include "../include/jobs_engine.h"

Expand Down
5 changes: 2 additions & 3 deletions examples/examples_lock_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <cstdio>
#include <iostream>
#include <thread>
#include <unistd.h>

#include "../include/lock_queue.h"

Expand Down Expand Up @@ -40,12 +39,12 @@ namespace examples::lock_queue {
ret = q.wait_pop_front(&e);
std::cout << "ret=" << static_cast<int>(ret) << ", pop " << e.first << "," << e.second << std::endl;

e = {};
e = {};
ret = q.wait_pop_front(&e);
std::cout << "ret=" << static_cast<int>(ret) << ", pop " << e.first << "," << e.second << std::endl;

// force exit signaled
e = {};
e = {};
ret = q.wait_pop_front(&e);
std::cout << "ret=" << static_cast<int>(ret) << "\n";

Expand Down
1 change: 0 additions & 1 deletion examples/examples_prio_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <cstdio>
#include <iostream>
#include <thread>
#include <unistd.h>

#include "../include/prio_queue.h"

Expand Down
1 change: 0 additions & 1 deletion examples/examples_spinlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <condition_variable>
#include <cstdio>
#include <iostream>
#include <unistd.h>

#include "../include/spinlock.h"

Expand Down
3 changes: 1 addition & 2 deletions examples/examples_time_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <cstdio>
#include <iostream>
#include <thread>
#include <unistd.h>

#include "../include/time_queue.h"

Expand Down Expand Up @@ -47,7 +46,7 @@ namespace examples::time_queue {
std::cout << "ret=" << static_cast<int>(ret) << " as timeout\n";

for (; ret != small::EnumLock::kExit;) {
ret = q.wait_pop(&e);
ret = q.wait_pop(&e);
auto elapsed = small::timeDiffMs(timeStart);
switch (ret) {
case small::EnumLock::kElement:
Expand Down
5 changes: 2 additions & 3 deletions examples/examples_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <map>
#include <string>
#include <thread>
#include <unistd.h>

#include "../include/util.h"

Expand All @@ -22,8 +21,8 @@ namespace examples::util {
m[std::string(b)] = 2;

constexpr const char *a = "a";
m[a] = 1;
m["A"] = 3; // this will have override the "a"
m[a] = 1;
m["A"] = 3; // this will have override the "a"

std::cout << "current map values ";
for (auto &[key, val] : m) {
Expand Down
1 change: 0 additions & 1 deletion examples/examples_worker_threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <iostream>
#include <map>
#include <thread>
#include <unistd.h>

#include "../include/worker_thread.h"

Expand Down
4 changes: 2 additions & 2 deletions include/base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace small {
template <typename T = std::string>
inline T tobase64(const char *src, const std::size_t src_length)
{
T base64;
T base64;
std::size_t base64_size = base64impl::get_base64_size(src_length);
base64.resize(base64_size);

Expand Down Expand Up @@ -64,7 +64,7 @@ namespace small {
template <typename T = std::string /*decoded may not be always string*/>
inline T frombase64(const char *base64, const std::size_t base64_length)
{
T decoded;
T decoded;
std::size_t decoded_size = base64impl::get_decodedbase64_size(base64_length);
decoded.resize(decoded_size);

Expand Down
26 changes: 13 additions & 13 deletions include/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ namespace small {
{
if (this != &o) {
clear_buffer();
m_config = o.m_config;
m_chunk_buffer_data = o.m_chunk_buffer_data;
m_chunk_buffer_length = o.m_chunk_buffer_length;
m_config = o.m_config;
m_chunk_buffer_data = o.m_chunk_buffer_data;
m_chunk_buffer_length = o.m_chunk_buffer_length;
m_chunk_buffer_alloc_size = o.m_chunk_buffer_alloc_size;
setup_buffer(m_chunk_buffer_data, m_chunk_buffer_length);
o.init();
Expand All @@ -189,9 +189,9 @@ namespace small {
} else if (m_chunk_buffer_data == get_empty_buffer() && o.m_chunk_buffer_data == o.get_empty_buffer()) { /*do nothing*/
} else if (m_chunk_buffer_data != get_empty_buffer() && o.m_chunk_buffer_data == o.get_empty_buffer()) {
o.m_chunk_buffer_data = m_chunk_buffer_data;
m_chunk_buffer_data = (char *)(get_empty_buffer());
m_chunk_buffer_data = (char *)(get_empty_buffer());
} else if (m_chunk_buffer_data == get_empty_buffer() && o.m_chunk_buffer_data != o.get_empty_buffer()) {
m_chunk_buffer_data = o.m_chunk_buffer_data;
m_chunk_buffer_data = o.m_chunk_buffer_data;
o.m_chunk_buffer_data = (char *)o.get_empty_buffer();
}
setup_buffer(m_chunk_buffer_data, m_chunk_buffer_length);
Expand All @@ -202,17 +202,17 @@ namespace small {
// init
inline void init()
{
m_config.chunk_size = std::max(m_config.chunk_size, std::size_t(1));
m_chunk_buffer_data = (char *)get_empty_buffer();
m_chunk_buffer_length = 0;
m_config.chunk_size = std::max(m_config.chunk_size, std::size_t(1));
m_chunk_buffer_data = (char *)get_empty_buffer();
m_chunk_buffer_length = 0;
m_chunk_buffer_alloc_size = 0;
setup_buffer(m_chunk_buffer_data, m_chunk_buffer_length);
}

// free_chunk_buffer
inline void free_chunk_buffer()
{
m_chunk_buffer_length = 0;
m_chunk_buffer_length = 0;
m_chunk_buffer_alloc_size = 0;
if (m_chunk_buffer_data && (m_chunk_buffer_data != get_empty_buffer())) {
buffer::free(m_chunk_buffer_data);
Expand All @@ -226,7 +226,7 @@ namespace small {
const auto chunk_size = m_config.chunk_size;
// we always append a '\0' to the end so we can use as string
std::size_t new_alloc_size = ((new_size + sizeof(char) /*for '\0'*/ + (chunk_size - 1)) / chunk_size) * chunk_size;
bool reallocate = false;
bool reallocate = false;
if (shrink) {
reallocate = (m_chunk_buffer_alloc_size == 0) || (new_alloc_size != m_chunk_buffer_alloc_size); // we need another size
} else {
Expand All @@ -235,7 +235,7 @@ namespace small {

// (re)allocate
if (reallocate) {
m_chunk_buffer_data = (m_chunk_buffer_alloc_size == 0) ? (char *)malloc(new_alloc_size) : (char *)realloc(m_chunk_buffer_data, new_alloc_size);
m_chunk_buffer_data = (m_chunk_buffer_alloc_size == 0) ? (char *)malloc(new_alloc_size) : (char *)realloc(m_chunk_buffer_data, new_alloc_size);
m_chunk_buffer_alloc_size = new_alloc_size;
}

Expand All @@ -252,7 +252,7 @@ namespace small {
// !! override functions
void clear_impl() override
{
m_chunk_buffer_length = 0;
m_chunk_buffer_length = 0;
m_chunk_buffer_data[0] = '\0';
setup_buffer(m_chunk_buffer_data, m_chunk_buffer_length);
}
Expand Down Expand Up @@ -298,7 +298,7 @@ namespace small {
// chunk size
config_buffer m_config{};
// buffer use char* instead of vector<char> because it is much faster
char *m_chunk_buffer_data{};
char *m_chunk_buffer_data{};
std::size_t m_chunk_buffer_length{};
std::size_t m_chunk_buffer_alloc_size{};
};
Expand Down
7 changes: 3 additions & 4 deletions include/critical_section.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "spinlock.h"

//
//
// small::critical_section lock;
// ...
// {
Expand All @@ -11,8 +11,7 @@
// // do your work
// ...
// }
//
namespace small
{
//
namespace small {
using critical_section = spinlock;
}
12 changes: 6 additions & 6 deletions include/impl/base_buffer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ namespace small {
{
protected:
// base_buffer (allocates in chunks)
base_buffer() = default;
base_buffer() = default;
base_buffer(const base_buffer &) = delete;
base_buffer(base_buffer &&) = delete;
virtual ~base_buffer() = default;
base_buffer(base_buffer &&) = delete;
virtual ~base_buffer() = default;

public:
// clang-format off
Expand Down Expand Up @@ -154,7 +154,7 @@ namespace small {
inline int compare(const char *s, std::size_t s_length) const
{
const std::size_t this_size = size();
int cmp = memcmp(data(), s, std::min(this_size, s_length));
int cmp = memcmp(data(), s, std::min(this_size, s_length));

if (cmp != 0) {
// different
Expand Down Expand Up @@ -297,7 +297,7 @@ namespace small {
// !! after every function call setup buffer data
inline void setup_buffer(char *buffer_data, std::size_t buffer_length)
{
m_buffer_data = buffer_data;
m_buffer_data = buffer_data;
m_buffer_length = buffer_length;
}

Expand Down Expand Up @@ -453,7 +453,7 @@ namespace small {
// base_buffer empty
char m_empty_buffer[1]{'\0'};
// base_buffer use char* instead of vector<char> because it is much faster
char *m_buffer_data{nullptr};
char *m_buffer_data{nullptr};
std::size_t m_buffer_length{0};
};

Expand Down
Loading
Loading