Added a base synchronized class.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15210 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
parent
ed2bc04969
commit
61a0f9743e
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file oop_object.h
|
* @file oop_base_object.h
|
||||||
* @brief Base object.
|
* @brief Base object.
|
||||||
* @details This header defines a base class that is the root class of
|
* @details This header defines a base class that is the root class of
|
||||||
* the ChibiOS Object Model.
|
* the ChibiOS Object Model.
|
||||||
|
@ -60,8 +60,8 @@
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef OOP_OBJECT_H
|
#ifndef OOP_BASE_OBJECT_H
|
||||||
#define OOP_OBJECT_H
|
#define OOP_BASE_OBJECT_H
|
||||||
|
|
||||||
#include "ccportab.h"
|
#include "ccportab.h"
|
||||||
#include "osal.h"
|
#include "osal.h"
|
||||||
|
@ -166,6 +166,6 @@ static inline void __base_object_dispose_impl(void *ip) {
|
||||||
(c)(((size_t)(ip)) - (ip)->vmt->instance_offset)
|
(c)(((size_t)(ip)) - (ip)->vmt->instance_offset)
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
#endif /* OOP_OBJECT_H */
|
#endif /* OOP_BASE_OBJECT_H */
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
|
@ -29,7 +29,7 @@
|
||||||
#ifndef OOP_REFERENCED_OBJECT_H
|
#ifndef OOP_REFERENCED_OBJECT_H
|
||||||
#define OOP_REFERENCED_OBJECT_H
|
#define OOP_REFERENCED_OBJECT_H
|
||||||
|
|
||||||
#include "oop_object.h"
|
#include "oop_base_object.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Type of a referenced object class.
|
* @brief Type of a referenced object class.
|
||||||
|
@ -105,9 +105,9 @@ static inline void __referenced_object_dispose_impl(void *ip) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Reference creation implementation.
|
* @brief New reference creation implementation.
|
||||||
*
|
*
|
||||||
* @param[in] ip An existing reference to the object.
|
* @param[in] ip A reference to the object.
|
||||||
* @return A new reference to the object.
|
* @return A new reference to the object.
|
||||||
*/
|
*/
|
||||||
CC_FORCE_INLINE
|
CC_FORCE_INLINE
|
||||||
|
@ -121,6 +121,9 @@ static inline void *__referenced_object_addref_impl(void *ip) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief References get implementation.
|
* @brief References get implementation.
|
||||||
|
*
|
||||||
|
* @param[in] ip A reference to the object.
|
||||||
|
* @return Remaining references.
|
||||||
*/
|
*/
|
||||||
CC_FORCE_INLINE
|
CC_FORCE_INLINE
|
||||||
static inline unsigned __referenced_object_getref_impl(void *ip) {
|
static inline unsigned __referenced_object_getref_impl(void *ip) {
|
||||||
|
@ -133,7 +136,6 @@ static inline unsigned __referenced_object_getref_impl(void *ip) {
|
||||||
* @brief Reference release implementation.
|
* @brief Reference release implementation.
|
||||||
*
|
*
|
||||||
* @param[in] ip A reference to the object.
|
* @param[in] ip A reference to the object.
|
||||||
* @return Remaining references.
|
|
||||||
*/
|
*/
|
||||||
CC_FORCE_INLINE
|
CC_FORCE_INLINE
|
||||||
static inline void __referenced_object_release_impl(void *ip) {
|
static inline void __referenced_object_release_impl(void *ip) {
|
||||||
|
@ -147,6 +149,29 @@ static inline void __referenced_object_release_impl(void *ip) {
|
||||||
}
|
}
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief New reference creation.
|
||||||
|
*
|
||||||
|
* @param[in] rop A reference to the object.
|
||||||
|
* @return A new reference to the object.
|
||||||
|
*/
|
||||||
|
CC_FORCE_INLINE
|
||||||
|
static inline referenced_object_c *roAddRef(referenced_object_c *rop) {
|
||||||
|
|
||||||
|
return (referenced_object_c *)__referenced_object_addref_impl(rop);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reference release.
|
||||||
|
*
|
||||||
|
* @param[in] rop A reference to the object.
|
||||||
|
*/
|
||||||
|
CC_FORCE_INLINE
|
||||||
|
static inline void roRelease(referenced_object_c *rop) {
|
||||||
|
|
||||||
|
return __referenced_object_release_impl(rop);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* OOP_REFERENCED_OBJECT_H */
|
#endif /* OOP_REFERENCED_OBJECT_H */
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -0,0 +1,161 @@
|
||||||
|
/*
|
||||||
|
ChibiOS - Copyright (C) 2006..2021 Giovanni Di Sirio
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file oop_synchronized_object.h
|
||||||
|
* @brief Base class for objects supporting synchronization.
|
||||||
|
* @details This header defines a base class for classes requiring a
|
||||||
|
* synchronization mechanism,
|
||||||
|
*
|
||||||
|
* @addtogroup OOP_SYNCHRONIZED_OBJECT
|
||||||
|
* @details Base class for objects that require a synchronization mechanism.
|
||||||
|
* This class extends @p synchronized_object_c class.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef OOP_SYNCHRONIZED_OBJECT_H
|
||||||
|
#define OOP_SYNCHRONIZED_OBJECT_H
|
||||||
|
|
||||||
|
#include "osal.h"
|
||||||
|
#include "oop_synchronized_object.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Type of a synchronized object class.
|
||||||
|
*/
|
||||||
|
typedef struct synchronized_object synchronized_object_c;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief @p synchronized_object_c specific methods.
|
||||||
|
* @note This object defines no methods.
|
||||||
|
*/
|
||||||
|
#define __synchronized_object_methods \
|
||||||
|
__referenced_object_methods
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief @p synchronized_object_c specific data.
|
||||||
|
*/
|
||||||
|
#define __synchronized_object_data \
|
||||||
|
__referenced_object_data \
|
||||||
|
mutex_t mutex;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief @p synchronized_object_c virtual methods table.
|
||||||
|
*/
|
||||||
|
struct __synchronized_object_vmt { \
|
||||||
|
__synchronized_object_methods \
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Structure representing a synchronized object class.
|
||||||
|
*/
|
||||||
|
typedef struct synchronized_object {
|
||||||
|
/**
|
||||||
|
* @brief Virtual Methods Table.
|
||||||
|
*/
|
||||||
|
const struct __synchronized_object_vmt *vmt;
|
||||||
|
__synchronized_object_data
|
||||||
|
} synchronized_object_c;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name Methods implementations
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @brief Object creation implementation.
|
||||||
|
*
|
||||||
|
* @param[in] ip Pointer to a @p synchronized_object_c structure to be
|
||||||
|
* initialized.
|
||||||
|
* @return A new reference to the object.
|
||||||
|
*/
|
||||||
|
CC_FORCE_INLINE
|
||||||
|
static inline void *__synchronized_object_objinit_impl(void *ip, const void *vmt) {
|
||||||
|
synchronized_object_c *objp = (synchronized_object_c *)ip;
|
||||||
|
|
||||||
|
__referenced_object_objinit_impl(ip, vmt);
|
||||||
|
osalMutexObjectInit(&objp->mutex);
|
||||||
|
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Object finalization implementation.
|
||||||
|
*
|
||||||
|
* @param[in] ip Pointer to a @p synchronized_object_c structure to be
|
||||||
|
* disposed.
|
||||||
|
*/
|
||||||
|
CC_FORCE_INLINE
|
||||||
|
static inline void __synchronized_object_dispose_impl(void *ip) {
|
||||||
|
|
||||||
|
__referenced_object_dispose_impl(ip);
|
||||||
|
/* Nothing.*/
|
||||||
|
/* TODO add RT objects disposing when available.*/
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Object lock implementation.
|
||||||
|
*
|
||||||
|
* @param[in] ip Pointer to a @p synchronized_object_c structure to be
|
||||||
|
* locked.
|
||||||
|
*/
|
||||||
|
CC_FORCE_INLINE
|
||||||
|
static inline void __synchronized_object_lock_impl(void *ip) {
|
||||||
|
synchronized_object_c *objp = (synchronized_object_c *)ip;
|
||||||
|
|
||||||
|
osalMutexLock(&objp->mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Object unlock implementation.
|
||||||
|
*
|
||||||
|
* @param[in] ip Pointer to a @p synchronized_object_c structure to be
|
||||||
|
* unlocked.
|
||||||
|
*/
|
||||||
|
CC_FORCE_INLINE
|
||||||
|
static inline void __synchronized_object_unlock_impl(void *ip) {
|
||||||
|
synchronized_object_c *objp = (synchronized_object_c *)ip;
|
||||||
|
|
||||||
|
osalMutexUnlock(&objp->mutex);
|
||||||
|
}
|
||||||
|
/** @} */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Object lock.
|
||||||
|
*
|
||||||
|
* @param[in] ip Pointer to a @p synchronized_object_c structure to be
|
||||||
|
* locked.
|
||||||
|
*/
|
||||||
|
CC_FORCE_INLINE
|
||||||
|
static inline void soLock(synchronized_object_c *sop) {
|
||||||
|
|
||||||
|
__synchronized_object_lock_impl(sop);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Object unlock.
|
||||||
|
*
|
||||||
|
* @param[in] ip Pointer to a @p synchronized_object_c structure to be
|
||||||
|
* unlocked.
|
||||||
|
*/
|
||||||
|
CC_FORCE_INLINE
|
||||||
|
static inline void soUnlock(synchronized_object_c *sop) {
|
||||||
|
|
||||||
|
__synchronized_object_unlock_impl(sop);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* OOP_SYNCHRONIZED_OBJECT_H */
|
||||||
|
|
||||||
|
/** @} */
|
Loading…
Reference in New Issue