renormalized files
This commit is contained in:
@ -1,50 +1,50 @@
|
||||
#ifndef FSFW_TASKS_SEMAPHOREFACTORY_H_
|
||||
#define FSFW_TASKS_SEMAPHOREFACTORY_H_
|
||||
|
||||
#include "../tasks/SemaphoreIF.h"
|
||||
|
||||
/**
|
||||
* Creates Semaphore.
|
||||
* This class is a "singleton" interface, i.e. it provides an
|
||||
* interface, but also is the base class for a singleton.
|
||||
*/
|
||||
class SemaphoreFactory {
|
||||
public:
|
||||
virtual ~SemaphoreFactory();
|
||||
/**
|
||||
* Returns the single instance of SemaphoreFactory.
|
||||
* The implementation of #instance is found in its subclasses.
|
||||
* Thus, we choose link-time variability of the instance.
|
||||
*/
|
||||
static SemaphoreFactory* instance();
|
||||
|
||||
/**
|
||||
* Create a binary semaphore.
|
||||
* Creator function for a binary semaphore which may only be acquired once
|
||||
* @param argument Can be used to pass implementation specific information.
|
||||
* @return Pointer to newly created semaphore class instance.
|
||||
*/
|
||||
SemaphoreIF* createBinarySemaphore(uint32_t arguments = 0);
|
||||
/**
|
||||
* Create a counting semaphore.
|
||||
* Creator functons for a counting semaphore which may be acquired multiple
|
||||
* times.
|
||||
* @param count Semaphore can be taken count times.
|
||||
* @param initCount Initial count value.
|
||||
* @param argument Can be used to pass implementation specific information.
|
||||
* @return
|
||||
*/
|
||||
SemaphoreIF* createCountingSemaphore(const uint8_t maxCount,
|
||||
uint8_t initCount, uint32_t arguments = 0);
|
||||
|
||||
void deleteSemaphore(SemaphoreIF* semaphore);
|
||||
|
||||
private:
|
||||
/**
|
||||
* External instantiation is not allowed.
|
||||
*/
|
||||
SemaphoreFactory();
|
||||
static SemaphoreFactory* factoryInstance;
|
||||
};
|
||||
|
||||
#endif /* FSFW_TASKS_SEMAPHOREFACTORY_H_ */
|
||||
#ifndef FSFW_TASKS_SEMAPHOREFACTORY_H_
|
||||
#define FSFW_TASKS_SEMAPHOREFACTORY_H_
|
||||
|
||||
#include "../tasks/SemaphoreIF.h"
|
||||
|
||||
/**
|
||||
* Creates Semaphore.
|
||||
* This class is a "singleton" interface, i.e. it provides an
|
||||
* interface, but also is the base class for a singleton.
|
||||
*/
|
||||
class SemaphoreFactory {
|
||||
public:
|
||||
virtual ~SemaphoreFactory();
|
||||
/**
|
||||
* Returns the single instance of SemaphoreFactory.
|
||||
* The implementation of #instance is found in its subclasses.
|
||||
* Thus, we choose link-time variability of the instance.
|
||||
*/
|
||||
static SemaphoreFactory* instance();
|
||||
|
||||
/**
|
||||
* Create a binary semaphore.
|
||||
* Creator function for a binary semaphore which may only be acquired once
|
||||
* @param argument Can be used to pass implementation specific information.
|
||||
* @return Pointer to newly created semaphore class instance.
|
||||
*/
|
||||
SemaphoreIF* createBinarySemaphore(uint32_t arguments = 0);
|
||||
/**
|
||||
* Create a counting semaphore.
|
||||
* Creator functons for a counting semaphore which may be acquired multiple
|
||||
* times.
|
||||
* @param count Semaphore can be taken count times.
|
||||
* @param initCount Initial count value.
|
||||
* @param argument Can be used to pass implementation specific information.
|
||||
* @return
|
||||
*/
|
||||
SemaphoreIF* createCountingSemaphore(const uint8_t maxCount,
|
||||
uint8_t initCount, uint32_t arguments = 0);
|
||||
|
||||
void deleteSemaphore(SemaphoreIF* semaphore);
|
||||
|
||||
private:
|
||||
/**
|
||||
* External instantiation is not allowed.
|
||||
*/
|
||||
SemaphoreFactory();
|
||||
static SemaphoreFactory* factoryInstance;
|
||||
};
|
||||
|
||||
#endif /* FSFW_TASKS_SEMAPHOREFACTORY_H_ */
|
||||
|
@ -1,68 +1,68 @@
|
||||
#ifndef FRAMEWORK_TASKS_SEMAPHOREIF_H_
|
||||
#define FRAMEWORK_TASKS_SEMAPHOREIF_H_
|
||||
#include "../returnvalues/FwClassIds.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include <cstdint>
|
||||
|
||||
/**
|
||||
* @brief Generic interface for semaphores, which can be used to achieve
|
||||
* task synchronization. This is a generic interface which can be
|
||||
* used for both binary semaphores and counting semaphores.
|
||||
* @details
|
||||
* A semaphore is a synchronization primitive.
|
||||
* See: https://en.wikipedia.org/wiki/Semaphore_(programming)
|
||||
* A semaphore can be used to achieve task synchonization and track the
|
||||
* availability of resources by using either the binary or the counting
|
||||
* semaphore types.
|
||||
*
|
||||
* If mutual exlcusion of a resource is desired, a mutex should be used,
|
||||
* which is a special form of a semaphore and has an own interface.
|
||||
*/
|
||||
class SemaphoreIF {
|
||||
public:
|
||||
/**
|
||||
* Different types of timeout for the mutex lock.
|
||||
*/
|
||||
enum TimeoutType {
|
||||
POLLING, //!< If mutex is not available, return immediately
|
||||
WAITING, //!< Wait a specified time for the mutex to become available
|
||||
BLOCKING //!< Block indefinitely until the mutex becomes available.
|
||||
};
|
||||
|
||||
virtual~ SemaphoreIF() {};
|
||||
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::SEMAPHORE_IF;
|
||||
//! Semaphore timeout
|
||||
static constexpr ReturnValue_t SEMAPHORE_TIMEOUT = MAKE_RETURN_CODE(1);
|
||||
//! The current semaphore can not be given, because it is not owned
|
||||
static constexpr ReturnValue_t SEMAPHORE_NOT_OWNED = MAKE_RETURN_CODE(2);
|
||||
static constexpr ReturnValue_t SEMAPHORE_INVALID = MAKE_RETURN_CODE(3);
|
||||
|
||||
/**
|
||||
* Generic call to acquire a semaphore.
|
||||
* If there are no more semaphores to be taken (for a counting semaphore,
|
||||
* a semaphore may be taken more than once), the taks will block
|
||||
* for a maximum of timeoutMs while trying to acquire the semaphore.
|
||||
* This can be used to achieve task synchrnization.
|
||||
* @param timeoutMs
|
||||
* @return - c RETURN_OK for successfull acquisition
|
||||
*/
|
||||
virtual ReturnValue_t acquire(TimeoutType timeoutType =
|
||||
TimeoutType::BLOCKING, uint32_t timeoutMs = 0) = 0;
|
||||
|
||||
/**
|
||||
* Corrensponding call to release a semaphore.
|
||||
* @return -@c RETURN_OK for successfull release
|
||||
*/
|
||||
virtual ReturnValue_t release() = 0;
|
||||
|
||||
/**
|
||||
* If the semaphore is a counting semaphore then the semaphores current
|
||||
* count value is returned. If the semaphore is a binary semaphore then 1
|
||||
* is returned if the semaphore is available, and 0 is returned if the
|
||||
* semaphore is not available.
|
||||
*/
|
||||
virtual uint8_t getSemaphoreCounter() const = 0;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_TASKS_SEMAPHOREIF_H_ */
|
||||
#ifndef FRAMEWORK_TASKS_SEMAPHOREIF_H_
|
||||
#define FRAMEWORK_TASKS_SEMAPHOREIF_H_
|
||||
#include "../returnvalues/FwClassIds.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include <cstdint>
|
||||
|
||||
/**
|
||||
* @brief Generic interface for semaphores, which can be used to achieve
|
||||
* task synchronization. This is a generic interface which can be
|
||||
* used for both binary semaphores and counting semaphores.
|
||||
* @details
|
||||
* A semaphore is a synchronization primitive.
|
||||
* See: https://en.wikipedia.org/wiki/Semaphore_(programming)
|
||||
* A semaphore can be used to achieve task synchonization and track the
|
||||
* availability of resources by using either the binary or the counting
|
||||
* semaphore types.
|
||||
*
|
||||
* If mutual exlcusion of a resource is desired, a mutex should be used,
|
||||
* which is a special form of a semaphore and has an own interface.
|
||||
*/
|
||||
class SemaphoreIF {
|
||||
public:
|
||||
/**
|
||||
* Different types of timeout for the mutex lock.
|
||||
*/
|
||||
enum TimeoutType {
|
||||
POLLING, //!< If mutex is not available, return immediately
|
||||
WAITING, //!< Wait a specified time for the mutex to become available
|
||||
BLOCKING //!< Block indefinitely until the mutex becomes available.
|
||||
};
|
||||
|
||||
virtual~ SemaphoreIF() {};
|
||||
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::SEMAPHORE_IF;
|
||||
//! Semaphore timeout
|
||||
static constexpr ReturnValue_t SEMAPHORE_TIMEOUT = MAKE_RETURN_CODE(1);
|
||||
//! The current semaphore can not be given, because it is not owned
|
||||
static constexpr ReturnValue_t SEMAPHORE_NOT_OWNED = MAKE_RETURN_CODE(2);
|
||||
static constexpr ReturnValue_t SEMAPHORE_INVALID = MAKE_RETURN_CODE(3);
|
||||
|
||||
/**
|
||||
* Generic call to acquire a semaphore.
|
||||
* If there are no more semaphores to be taken (for a counting semaphore,
|
||||
* a semaphore may be taken more than once), the taks will block
|
||||
* for a maximum of timeoutMs while trying to acquire the semaphore.
|
||||
* This can be used to achieve task synchrnization.
|
||||
* @param timeoutMs
|
||||
* @return - c RETURN_OK for successfull acquisition
|
||||
*/
|
||||
virtual ReturnValue_t acquire(TimeoutType timeoutType =
|
||||
TimeoutType::BLOCKING, uint32_t timeoutMs = 0) = 0;
|
||||
|
||||
/**
|
||||
* Corrensponding call to release a semaphore.
|
||||
* @return -@c RETURN_OK for successfull release
|
||||
*/
|
||||
virtual ReturnValue_t release() = 0;
|
||||
|
||||
/**
|
||||
* If the semaphore is a counting semaphore then the semaphores current
|
||||
* count value is returned. If the semaphore is a binary semaphore then 1
|
||||
* is returned if the semaphore is available, and 0 is returned if the
|
||||
* semaphore is not available.
|
||||
*/
|
||||
virtual uint8_t getSemaphoreCounter() const = 0;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_TASKS_SEMAPHOREIF_H_ */
|
||||
|
Reference in New Issue
Block a user