Add format script which invokes clang-format on the C++ source code (#41)

On Windows machines, clang-format.exe must be in the PATH environment variable.
This commit is contained in:
Tyler Veness
2016-05-20 17:30:37 -07:00
committed by Peter Johnson
parent 68690643d2
commit e14e45da76
383 changed files with 13787 additions and 13198 deletions

View File

@@ -1,13 +1,14 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved. */
/* Copyright (c) FIRST 2008. All Rights Reserved.
*/
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
/*----------------------------------------------------------------------------*/
#pragma once
#include <stdint.h>
#include "../Errors.hpp"
#include "HAL/cpp/priority_mutex.h"
#include <stdint.h>
#include <vector>
@@ -24,23 +25,22 @@ namespace hal {
* resources; it just tracks which indices were marked in use by
* Allocate and not yet freed by Free.
*/
class Resource
{
public:
Resource(const Resource&) = delete;
Resource& operator=(const Resource&) = delete;
explicit Resource(uint32_t size);
virtual ~Resource() = default;
static void CreateResourceObject(Resource **r, uint32_t elements);
uint32_t Allocate(const char *resourceDesc);
uint32_t Allocate(uint32_t index, const char *resourceDesc);
void Free(uint32_t index);
class Resource {
public:
Resource(const Resource&) = delete;
Resource& operator=(const Resource&) = delete;
explicit Resource(uint32_t size);
virtual ~Resource() = default;
static void CreateResourceObject(Resource** r, uint32_t elements);
uint32_t Allocate(const char* resourceDesc);
uint32_t Allocate(uint32_t index, const char* resourceDesc);
void Free(uint32_t index);
private:
std::vector<bool> m_isAllocated;
priority_recursive_mutex m_allocateLock;
private:
std::vector<bool> m_isAllocated;
priority_recursive_mutex m_allocateLock;
static priority_recursive_mutex m_createLock;
static priority_recursive_mutex m_createLock;
};
} // namespace hal

View File

@@ -1,7 +1,7 @@
#pragma once
#include <cstdint>
#include <condition_variable>
#include <cstdint>
#include "HAL/cpp/priority_mutex.h"

View File

@@ -30,7 +30,8 @@ class priority_condition_variable {
~priority_condition_variable() = default;
priority_condition_variable(const priority_condition_variable&) = delete;
priority_condition_variable& operator=(const priority_condition_variable&) = delete;
priority_condition_variable& operator=(const priority_condition_variable&) =
delete;
void notify_one() noexcept {
std::lock_guard<std::mutex> lock(*m_mutex);
@@ -42,7 +43,7 @@ class priority_condition_variable {
m_cond.notify_all();
}
template<typename Lock>
template <typename Lock>
void wait(Lock& _lock) {
std::shared_ptr<std::mutex> _mutex = m_mutex;
std::unique_lock<std::mutex> my_lock(*_mutex);
@@ -54,14 +55,16 @@ class priority_condition_variable {
m_cond.wait(my_lock2);
}
template<typename Lock, typename Predicate>
template <typename Lock, typename Predicate>
void wait(Lock& lock, Predicate p) {
while (!p()) { wait(lock); }
while (!p()) {
wait(lock);
}
}
template<typename Lock, typename Clock, typename Duration>
std::cv_status wait_until(Lock& _lock,
const std::chrono::time_point<Clock, Duration>& atime) {
template <typename Lock, typename Clock, typename Duration>
std::cv_status wait_until(
Lock& _lock, const std::chrono::time_point<Clock, Duration>& atime) {
std::shared_ptr<std::mutex> _mutex = m_mutex;
std::unique_lock<std::mutex> my_lock(*_mutex);
Unlock<Lock> unlock(_lock);
@@ -72,9 +75,11 @@ class priority_condition_variable {
return m_cond.wait_until(my_lock2, atime);
}
template<typename Lock, typename Clock, typename Duration, typename Predicate>
template <typename Lock, typename Clock, typename Duration,
typename Predicate>
bool wait_until(Lock& lock,
const std::chrono::time_point<Clock, Duration>& atime, Predicate p) {
const std::chrono::time_point<Clock, Duration>& atime,
Predicate p) {
while (!p()) {
if (wait_until(lock, atime) == std::cv_status::timeout) {
return p();
@@ -83,35 +88,36 @@ class priority_condition_variable {
return true;
}
template<typename Lock, typename Rep, typename Period>
std::cv_status wait_for(Lock& lock, const std::chrono::duration<Rep, Period>& rtime) {
template <typename Lock, typename Rep, typename Period>
std::cv_status wait_for(Lock& lock,
const std::chrono::duration<Rep, Period>& rtime) {
return wait_until(lock, clock_t::now() + rtime);
}
template<typename Lock, typename Rep, typename Period, typename Predicate>
template <typename Lock, typename Rep, typename Period, typename Predicate>
bool wait_for(Lock& lock, const std::chrono::duration<Rep, Period>& rtime,
Predicate p) {
Predicate p) {
return wait_until(lock, clock_t::now() + rtime, std::move(p));
}
native_handle_type native_handle() {
return m_cond.native_handle();
}
native_handle_type native_handle() { return m_cond.native_handle(); }
private:
std::condition_variable m_cond;
std::shared_ptr<std::mutex> m_mutex;
// scoped unlock - unlocks in ctor, re-locks in dtor
template<typename Lock>
template <typename Lock>
struct Unlock {
explicit Unlock(Lock& lk) : m_lock(lk) { lk.unlock(); }
~Unlock() /*noexcept(false)*/ {
if (std::uncaught_exception()) {
try { m_lock.lock(); } catch(...) {}
}
else {
try {
m_lock.lock();
} catch (...) {
}
} else {
m_lock.lock();
}
}

View File

@@ -15,17 +15,17 @@
// simulator, we do not care about priority inversion.
typedef std::mutex priority_mutex;
typedef std::recursive_mutex priority_recursive_mutex;
#else // Covers rest of file.
#else // Covers rest of file.
#include <pthread.h>
class priority_recursive_mutex {
public:
typedef pthread_mutex_t *native_handle_type;
typedef pthread_mutex_t* native_handle_type;
constexpr priority_recursive_mutex() noexcept = default;
priority_recursive_mutex(const priority_recursive_mutex &) = delete;
priority_recursive_mutex &operator=(const priority_recursive_mutex &) = delete;
priority_recursive_mutex(const priority_recursive_mutex&) = delete;
priority_recursive_mutex& operator=(const priority_recursive_mutex&) = delete;
// Lock the mutex, blocking until it's available.
void lock();
@@ -36,11 +36,11 @@ class priority_recursive_mutex {
// Tries to lock the mutex.
bool try_lock() noexcept;
pthread_mutex_t *native_handle();
pthread_mutex_t* native_handle();
private:
// Do the equivalent of setting PTHREAD_PRIO_INHERIT and
// PTHREAD_MUTEX_RECURSIVE_NP.
// Do the equivalent of setting PTHREAD_PRIO_INHERIT and
// PTHREAD_MUTEX_RECURSIVE_NP.
#if __WORDSIZE == 64
pthread_mutex_t m_mutex = {
{0, 0, 0, 0, 0x20 | PTHREAD_MUTEX_RECURSIVE_NP, 0, 0, {0, 0}}};
@@ -52,11 +52,11 @@ class priority_recursive_mutex {
class priority_mutex {
public:
typedef pthread_mutex_t *native_handle_type;
typedef pthread_mutex_t* native_handle_type;
constexpr priority_mutex() noexcept = default;
priority_mutex(const priority_mutex &) = delete;
priority_mutex &operator=(const priority_mutex &) = delete;
priority_mutex(const priority_mutex&) = delete;
priority_mutex& operator=(const priority_mutex&) = delete;
// Lock the mutex, blocking until it's available.
void lock();
@@ -67,16 +67,14 @@ class priority_mutex {
// Tries to lock the mutex.
bool try_lock() noexcept;
pthread_mutex_t *native_handle();
pthread_mutex_t* native_handle();
private:
// Do the equivalent of setting PTHREAD_PRIO_INHERIT.
// Do the equivalent of setting PTHREAD_PRIO_INHERIT.
#if __WORDSIZE == 64
pthread_mutex_t m_mutex = {
{0, 0, 0, 0, 0x20, 0, 0, {0, 0}}};
pthread_mutex_t m_mutex = {{0, 0, 0, 0, 0x20, 0, 0, {0, 0}}};
#else
pthread_mutex_t m_mutex = {
{0, 0, 0, 0x20, 0, {0}}};
pthread_mutex_t m_mutex = {{0, 0, 0, 0x20, 0, {0}}};
#endif
};