diff options
author | takeshi_hoshina <takeshi_hoshina@mail.toyota.co.jp> | 2020-10-27 11:16:21 +0900 |
---|---|---|
committer | takeshi_hoshina <takeshi_hoshina@mail.toyota.co.jp> | 2020-10-27 11:16:21 +0900 |
commit | 947c78887e791596d4a5ec2d1079f8b1a049628b (patch) | |
tree | 3981e88eb8764d7180722f8466f36b756dc005af /nsframework/common_library/client/include | |
parent | 706ad73eb02caf8532deaf5d38995bd258725cb8 (diff) |
basesystem 0.1sandbox/ToshikazuOhiwa/basesystem
Diffstat (limited to 'nsframework/common_library/client/include')
12 files changed, 2591 insertions, 0 deletions
diff --git a/nsframework/common_library/client/include/cl_cgroup.h b/nsframework/common_library/client/include/cl_cgroup.h new file mode 100644 index 00000000..10a71791 --- /dev/null +++ b/nsframework/common_library/client/include/cl_cgroup.h @@ -0,0 +1,35 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * 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. + */ + +#ifndef _cl_cgroup_h_ // NOLINT(build/header_guard) +#define _cl_cgroup_h_ // NOLINT(build/header_guard) + +typedef enum { + CL_CGROUP_MEMORY, + CL_CGROUP_CPU, +} cl_cgroup_t; + +int cl_cgroup_make(cl_cgroup_t cgroup, const char *cgroup_name); // NOLINT(readability/nolint) +int cl_cgroup_remove(cl_cgroup_t cgroup, const char *cgroup_name); // NOLINT(readability/nolint) +int cl_cgroup_exist(cl_cgroup_t cgroup, const char *cgroup_name); // NOLINT(readability/nolint) +int cl_cgroup_open(cl_cgroup_t cgroup, const char *cgroup_name, // NOLINT(readability/nolint) + const char *controler, int flags); +int cl_cgroup_set_string(cl_cgroup_t cgroup, const char *cgroup_name, // NOLINT(readability/nolint) + const char *controler, const char *str); +int cl_cgroup_set_num(cl_cgroup_t cgroup, const char *cgroup_name, // NOLINT(readability/nolint) + const char *controler, int64_t value); + +#endif // ifndef _cl_cgroup_h_ // NOLINT(build/header_guard) diff --git a/nsframework/common_library/client/include/cl_error.h b/nsframework/common_library/client/include/cl_error.h new file mode 100644 index 00000000..84bf64e0 --- /dev/null +++ b/nsframework/common_library/client/include/cl_error.h @@ -0,0 +1,44 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * 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. + */ + +#ifndef _cl_error_h_ // NOLINT(build/header_guard) +#define _cl_error_h_ // NOLINT(build/header_guard) + +#include <stdio.h> +#include <unistd.h> +#include <asm/unistd.h> + +static inline int gettid(void) { // NOLINT(readability/nolint) + return (int)syscall(__NR_gettid); // NOLINT(readability/casting) +} + +#define _num_to_str(num) #num +#define num_to_str(num) _num_to_str(num) +#define CL_PERROR(msg) \ + perror(__FILE__ ":" num_to_str(__LINE__)":"msg) + +#define CL_ERR_PRINT(fmt, args...) \ + fprintf(stderr, "[ERR]%d %s:%d:"fmt"\n", gettid(), __func__, __LINE__, ##args) + +#if defined(CL_DBG_ENABLE) +#define CL_DBG_PRINT(fmt, args...) \ + fprintf(stdout, "[DBG]%d %s:%d:"fmt"\n", gettid(), __func__, __LINE__, ##args) +#else +#define CL_DBG_PRINT(fmt, args...) +#endif + + +#endif // #ifndef _cl_error_h_ // NOLINT(build/header_guard) diff --git a/nsframework/common_library/client/include/cl_lock_internal.h b/nsframework/common_library/client/include/cl_lock_internal.h new file mode 100644 index 00000000..7a2f623c --- /dev/null +++ b/nsframework/common_library/client/include/cl_lock_internal.h @@ -0,0 +1,55 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * 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. + */ + +#ifndef _cl_lock_internal_h_ // NOLINT(build/header_guard) +#define _cl_lock_internal_h_ // NOLINT(build/header_guard) + +#include <native_service/cl_lockid.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file cl_lock_internal.h + */ + +/** @addtogroup BaseSystem + * @{ + */ +/** @addtogroup native_service + * @ingroup BaseSystem + * @{ + */ +/** @addtogroup common_library + * @ingroup native_service + * @{ + */ + +#define LOCKFILE_NAME "lockfile" // lock file name +#define SLOT_SIZE 4096 // slot size +#define LOCKFILE_SIZE SLOT_SIZE * LID_NUM // the lock file size + +#define LOCK_TIMEOUT 3 // timeout(sec) for CL_LockTimedGet + +/** @}*/ // end of common_library +/** @}*/ // end of NativeService +/** @}*/ // end of BaseSystem +#ifdef __cplusplus +} +#endif + +#endif // #ifndef _cl_lock_internal_h_ // NOLINT(build/header_guard) diff --git a/nsframework/common_library/client/include/cl_monitor_internal.h b/nsframework/common_library/client/include/cl_monitor_internal.h new file mode 100644 index 00000000..0a864a21 --- /dev/null +++ b/nsframework/common_library/client/include/cl_monitor_internal.h @@ -0,0 +1,30 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * 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. + */ + +#ifndef _cl_monitor_internal_h_ // NOLINT(build/header_guard) +#define _cl_monitor_internal_h_ // NOLINT(build/header_guard) + +#ifdef __cplusplus +extern "C" { +#endif + +int cl_monitor_cleanup(int pid); // NOLINT(readability/nolint) + +#ifdef __cplusplus +} +#endif + +#endif /* ifndef _cl_monitor_internal_h_ */ diff --git a/nsframework/common_library/client/include/cl_process_internal.h b/nsframework/common_library/client/include/cl_process_internal.h new file mode 100644 index 00000000..ce001de5 --- /dev/null +++ b/nsframework/common_library/client/include/cl_process_internal.h @@ -0,0 +1,53 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * 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. + */ + +#ifndef _cl_process_internal_h_ // NOLINT(build/header_guard) +#define _cl_process_internal_h_ // NOLINT(build/header_guard) + +typedef struct { + char name[20]; + uid_t uid; + gid_t gid; + int sched_policy; + int sched_priority; + int create_group; + int stack_size; + int cpu_assign; + int hold_fds[CL_PROCESSS_ATTR_HOLD_FDS_NUM]; + int disable_close_fds; + char cgroup_name[64]; +} CL_ProcessAttrInternal_t; + +typedef struct { + char name[20]; +} CL_ThreadAttrInternal_t; + +typedef struct { + int rt_runtime_us; + int cfs_quota_us; + int cpu_shares; + int memory_limit; + int usage_in_bytes; + int event_fd; +} CL_ProcessCreateCgroupAttrInternal_t; + +#define CL_PROCESS_NAME_ENV "CL_PROCESS_NAME" + +#define CL_PROCESS_EXIT_INTERNAL 0x80 + +#define CL_PROCESS_CGROUP_NAME_FORMAT "CGRP%05d" + +#endif // #ifndef _cl_process_internal_h_ // NOLINT(build/header_guard) diff --git a/nsframework/common_library/client/include/native_service/cl_lock.h b/nsframework/common_library/client/include/native_service/cl_lock.h new file mode 100644 index 00000000..d9745405 --- /dev/null +++ b/nsframework/common_library/client/include/native_service/cl_lock.h @@ -0,0 +1,259 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * 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. + */ +#ifndef _cl_lock_h_ // NOLINT(build/header_guard) +#define _cl_lock_h_ // NOLINT(build/header_guard) + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file cl_lock.h + * @brief \~english This file contains the base api of cl_clock. + */ + +/** @addtogroup BaseSystem + * @{ + */ +/** @addtogroup native_service + * @ingroup BaseSystem + * @{ + */ +/** @addtogroup common_library + * @ingroup native_service + * @{ + */ + +//////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_LockSystemInit +/// \~english @par Brief +/// Initialize the system lock. +/// \~english @retval 0 Success +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// - Prerequisites are nothing. +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - On system call shm_open error, -1 is returned. +/// - On system call ftrancate error, -1 is returned. +/// - On system call mmap error, -1 is returned. +/// - On system call pthread_mutexattr_setpshared error, -1 is returned. +/// \~english @par Detail +/// This function will generate the Lock file, and initialize all the pthread_mutex_t slots.\n +/// This function must to be called in the system once, which is recommended on the SystemManager start.\n +/// \~english @par +/// Lock file is formed with lots of slots. Every slot occupies 4KB. +/// The slot layout is: +/// 0 ~ 4Byte : field of PID +/// 4Byte ~ 28Byte : field of pthread_mutex_t +/// \~english @par Classification +/// Public +/// \~english @par Type +/// Sync only +/// \~english @see +/// none +//////////////////////////////////////////////////////////////////////////////////// +int32_t CL_LockSystemInit(void); // NOLINT(readability/nolint) + +//////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_LockProcessInit +/// \~english @par Brief +/// Initialize the process Lock file. +/// \~english @retval 0 Success +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// Should call CL_LockSystemInit() to generate Lock file. +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - On system call shm_open error, -1 is returned. +/// \~english @par Detail +/// Open the Lock file.\n +/// If process want to use the Lock, this function should be called.\n +/// It is recommended that this function should be called since start main function. +/// \~english @par Classification +/// Public +/// \~english @par Type +/// Sync only +/// \~english @see +/// none +//////////////////////////////////////////////////////////////////////////////////// +int32_t CL_LockProcessInit(void); // NOLINT(readability/nolint) + +//////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_LockMap +/// \~english @par Brief +/// Mapping the Lock information address. +/// \~english @param [in] lid +/// int32_t - LockID of the Lock used.(0~LID_NUM) \n +/// \~english @retval addr Lock address +/// \~english @retval MAP_FAILED Error (errno) +/// \~english @par Prerequisite +/// Should call CL_LockSystemInit(), CL_LockProcessInit() to open the Lock file. +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - If LockID(lid) < 0, errno is set as EINVAL, and MAP_FAILED is returned +/// - If LockID(lid) > LID_NUM, errno is set as EINVAL, and MAP_FAILED is returned +/// - If systemcall mmap is failure, errno is set euqal with the errno of mmap, and MAP_FAILED is returned +/// \~english @par Detail +/// Mapping the Lock information to the memory.\n +/// The related LockID should be assigned, when apply the share memory.\n +/// \~english @par Classification +/// Public +/// \~english @par Type +/// Sync only +/// \~english @see +/// CL_LockUnmap +//////////////////////////////////////////////////////////////////////////////////// +void *CL_LockMap(int32_t lid); // NOLINT(readability/nolint) + +//////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_LockUnmap +/// \~english @par Brief +/// Unmapping the Lock information. +/// \~english @param [in] addr +/// void* - Lock information address. +/// \~english @retval 0 Success +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// Should call CL_LockSystemInit(), CL_LockProcessInit() before this function is called +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - If systemcall munmap is failure, errno is set euqal with the errno of munmap, -1 is returned +/// \~english @par Detail +/// 0 would be returned, even if not get the Lock. +/// The addr is the Lock information address that acquired from CL_LockMap. +/// \~english @par Classification +/// Public +/// \~english @par Type +/// Sync only +/// \~english @see +/// CL_LockMap +//////////////////////////////////////////////////////////////////////////////////// +int32_t CL_LockUnmap(void *addr); // NOLINT(readability/nolint) + +//////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_LockGet +/// \~english @par Brief +/// Get the Lock. Block until get the Lock. +/// \~english @param [in] addr +/// void* - Lock information address. +/// \~english @retval 0 Success +/// \~english @retval EINVAL Invalid parameter +/// \~english @retval EDEADLK Mutex already locked +/// \~english @par Prerequisite +/// Should call CL_LockMap to get the Lock information address. +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - EINVAL as the parameter of Lock information address is NULL +/// - EINVAL as the parameter of Lock information address is MAP_FAILED +/// - EINVAL as the mutex does not be initialized in the systemcall pthread_mutex_lock failure. +/// - EDEADLK as the current thread already owns the mutex in the systemcall pthread_mutex_lock failure. +/// \~english @par Detail +/// Get the Lock until other threads release it. +/// It will be deadlock if the current thread already owns the mutex. +/// The addr is the Lock information address that should be acquired from CL_LockMap. +/// \~english @par Classification +/// Public +/// \~english @par Type +/// Sync only +/// \~english @see +/// CL_LockRelease +//////////////////////////////////////////////////////////////////////////////////// +int32_t CL_LockGet(void *addr); // NOLINT(readability/nolint) + +//////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_LockNowait +/// \~english @par Brief +/// Try to get Lock, shall immediately return. +/// \~english @param [in] addr +/// void* - Lock information address. +/// \~english @retval 0 Success +/// \~english @retval EINVAL Invalid parameter +/// \~english @retval EBUSY Busy +/// \~english @par Prerequisite +/// Should call CL_LockMap to get the Lock information address. +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - EINVAL as input parameter addr, the Lock information address is NULL +/// - EINVAL as input parameter addr, the Lock information address if MAP_FAILED +/// - EINVAL as the mutex does not be initialized in the systemcall pthread_mutex_trylock failure. +/// - EBUSY as the mutex could not be acquired as it was already locked in the +/// systemcall pthread_mutex_trylock failure. +/// \~english @par Detail +/// The addr is the Lock information address that should be acquired from CL_LockMap. +/// Get the Lock information from the pointed share memory. +/// Shall immediately return while not acquire the Lock. +/// \~english @par Classification +/// Public +/// \~english @par Type +/// Sync only +/// \~english @see +/// CL_LockRelease +//////////////////////////////////////////////////////////////////////////////////// +int32_t CL_LockNowait(void *addr); // NOLINT(readability/nolint) + +//////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_LockRelease +/// \~english @par Brief +/// Release the Lock. +/// \~english @param [in] addr +/// addr - Lock information address. +/// \~english @retval 0 Success +/// \~english @retval EINVAL Invalid parameter +/// \~english @retval EPERM The current thread does not own the mutex +/// \~english @par Prerequisite +/// - Should call CL_LockMap to get the Lock information address. +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - EINVAL as input parameter addr, the Lock information address is NULL +/// - EINVAL as input parameter addr, the Lock information address if MAP_FAILED +/// - EINVAL as the mutex does not be initialized in the systemcall pthread_mutex_unlock failure. +/// - EPERM as the current thread does not own the mutex in the systemcall pthread_mutex_unlock failure. +/// \~english @par Detail +/// 0 would be returned, even if not get the Lock. +/// The addr is the Lock information address that should be acquired from CL_LockMap. +/// Release the Lock related with the share memory. +/// \~english @par Classification +/// Public +/// \~english @par Type +/// Sync only +/// \~english @see +/// CL_LockGet, CL_LockNowait +//////////////////////////////////////////////////////////////////////////////////// +int CL_LockRelease(void *addr); // NOLINT(readability/nolint) + +#ifdef __cplusplus +} +#endif + + +/** @}*/ // end of common_library +/** @}*/ // end of NativeService +/** @}*/ // end of BaseSystem +#define LOCK_POS_MTX_RSV 40 +#define LOCK_HRDS_RSV 15 +#define LOCK_NSLOG_ACCES_IF_RSV 50 +#define LID_NUM 140 +#endif // #ifndef _cl_lock_h_ // NOLINT(build/header_guard) diff --git a/nsframework/common_library/client/include/native_service/cl_lockid.h b/nsframework/common_library/client/include/native_service/cl_lockid.h new file mode 100644 index 00000000..a790a4bb --- /dev/null +++ b/nsframework/common_library/client/include/native_service/cl_lockid.h @@ -0,0 +1,180 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * 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 cl_lockid.h + * @brief Definition of LockID(LID) + * + */ + +#ifndef _cl_lockid_h_ // NOLINT(build/header_guard) +#define _cl_lockid_h_ // NOLINT(build/header_guard) +#include <native_service/cl_lock.h> +#include <assert.h> + +/** + * @file cl_lockid.h + */ + +/** @addtogroup BaseSystem + * @{ + */ +/** @addtogroup native_service + * @ingroup BaseSystem + * @{ + */ +/** @addtogroup common_library + * @ingroup native_service + * @{ + */ + +/* + * Numbering rules + * Assign LID corresponding to the Lock name specified when requesting shared memories. + */ + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup ENUM_LOCK_ID +/// \~english @par Brief +/// ID for Exclusive Control\n +/// When AGL users add their own definitions, add "_**" to the definitions.\n +/// ("**" is an aribitrary character string indicating the organization that uses AGL.) +///////////////////////////////////////////////////////////////////////////////////// + +typedef enum { +// LID_TEST_1 = 0, +// LID_TEST_2, + LOCK_ANA_LOG_SEM = 0, /* Exclusive Control to store application log on kernel unmanaged RAM*/ + LOCK_POS_MTX_1, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_2, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_3, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_4, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_5, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_6, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_7, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_8, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_9, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_10, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_11, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_12, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_13, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_14, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_15, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_16, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_17, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_18, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_19, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_20, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_21, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_22, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_23, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_24, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_25, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_26, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_27, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_28, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_29, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_30, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_31, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_32, /* Exclusive Control between POSITIONING and others */ + LOCK_POS_MTX_MAX, /* Exclusive Control between POSITIONING and others MAX */ + LOCK_CLOCK_SEM_TZ = (LOCK_POS_MTX_1+LOCK_POS_MTX_RSV), /* Access control to shared memory for TimeZone */ + LOCK_SEC_DATA_PROTECT, /* Exclusive control to shared memory for the application that use the security chip. */ + LOCK_OS_SEM_ID__CWORD68_, /* Exclusive Control for SSL library. */ + LOCK_ROM_ACCESS_IF, /* Exclusive access control for system manager nv area */ + LOCK_BOOT_ACCESS_IF, /* Exclusive access control for system manager nor area */ + LOCK_RAM_ACCESS_IF, /* Exclusive access control for system manager drambackup area */ + LOCK_HRDS_1, /* Exclusive Control between DataService and others */ + LOCK_HRDS_2, /* Exclusive Control between DataService and others */ + LOCK_HRDS_3, /* Exclusive Control between DataService and others */ + LOCK_HRDS_4, /* Exclusive Control between DataService and others */ + LOCK_HRDS_5, /* Exclusive Control between DataService and others */ + LOCK_HRDS_6, /* Exclusive Control between DataService and others */ + LOCK_HRDS_7, /* Exclusive Control between DataService and others */ + LOCK_HRDS_8, /* Exclusive Control between DataService and others */ + LOCK_HRDS_MAX, /* Exclusive Control between DataService and others MAX */ + LOCK_LOGG_ACCESS_IF = (LOCK_HRDS_1+LOCK_HRDS_RSV), /* Exclusive access control for NsLoggerService nv area */ + LOCK__CWORD76__HMI, /* Exclusive Control between _CWORD76_Service and HMI's */ + LOCK__CWORD76___CWORD58_, /* Exclusive Control between _CWORD76_Service and _CWORD58_Service */ + LOCK_DIAGCODE_MEM, /* Exclusive Control to diag code memory area */ + LOCK_MOUNTER_MOUNT, /* Exclusive Control for Mount */ + LOCK_NOR_ERCNT, /* Exclusive access control for NOR erase count information */ + LOCK_RS_WNG_HIS_LIST_DATA, /* Exclusive Control between RemoteService and RS-HMI. */ + LOCK_RS_WNG_SCREEN_DATA, /* Exclusive Control between RemoteService and RS-HMI. */ + LOCK_RS_SCREEN_DATA, /* Exclusive Control between RemoteService and RS-HMI. */ + LOCK_NSLOG_ACCES_IF_1, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_2, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_3, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_4, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_5, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_6, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_7, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_8, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_9, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_10, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_11, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_12, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_13, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_14, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_15, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_16, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_17, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_18, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_19, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_20, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_21, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_22, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_23, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_24, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_25, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_26, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_27, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_28, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_29, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_30, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_31, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_32, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_33, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_34, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_35, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_36, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_37, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_38, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_39, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_40, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_41, /* Exclusive Control between writing to log file */ + + LOCK_NSLOG_ACCES_IF_42, /* Exclusive Control between writing to log file */ + + LOCK_NSLOG_ACCES_IF_43, /* Exclusive Control between writing to log file */ + LOCK_NSLOG_ACCES_IF_MAX, /* Exclusive Control between writing to log file MAX */ + LOCK_INFOSETTING_REV = (LOCK_NSLOG_ACCES_IF_1+LOCK_NSLOG_ACCES_IF_RSV), /* Exclusive control revision information for managing the settings */ + LOCK_SUBMENU_SELECT, /* Exclusive control between writing the selection information of the sub-menu*/ + LOCK_DIAG_SEM1, /* Exclusive Control between DiagService and others */ + LOCK_DIAG_SEM2, /* Exclusive Control between Collect thread and Upload thread */ + LID_NUM_MAX /* Number of LockID */ +} ENUM_LOCK_ID; + +static_assert(LOCK_POS_MTX_MAX <= (LOCK_POS_MTX_1+LOCK_POS_MTX_RSV), "LOCK_POS_MTX_RSV resource empty. Please change limit and build AGL."); +static_assert(LOCK_HRDS_MAX <= (LOCK_HRDS_1+LOCK_HRDS_RSV), "LOCK_HRDS_RSV resource empty. Please change limit and build AGL."); +static_assert(LOCK_NSLOG_ACCES_IF_MAX <= (LOCK_NSLOG_ACCES_IF_1+LOCK_NSLOG_ACCES_IF_RSV), "LOCK_NSLOG_ACCES_IF_RSV resource empty. Please change limit and build AGL."); +static_assert(LID_NUM_MAX <= LID_NUM, "LOCK_ID resource empty. Please change limit and build AGL."); + +/** @}*/ // end of common_library +/** @}*/ // end of NativeService +/** @}*/ // end of BaseSystem + +#endif // #ifndef _cl_lockid_h_ // NOLINT(build/header_guard) diff --git a/nsframework/common_library/client/include/native_service/cl_monitor.h b/nsframework/common_library/client/include/native_service/cl_monitor.h new file mode 100644 index 00000000..650492cf --- /dev/null +++ b/nsframework/common_library/client/include/native_service/cl_monitor.h @@ -0,0 +1,269 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * 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 + * @brief \~english This file contains the enum,struct and api of cl_monitor. + */ +#ifndef _cl_monitor_h_ // NOLINT(build/header_guard) +#define _cl_monitor_h_ // NOLINT(build/header_guard) + +#include <stdint.h> + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup Monitor +/// \~english @par Brief +/// Monitor init enum +///////////////////////////////////////////////////////////////////////////////////// +typedef enum { + CL_MONITOR_INIT_SYSTEM = 0, + CL_MONITOR_INIT_USER +} CL_MonitorInit_t; + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup Monitor +/// \~english @par Brief +/// the struct of Monitor Entry +///////////////////////////////////////////////////////////////////////////////////// +typedef struct { + uint16_t pid; + uint8_t type; + uint8_t state; + +// uint32_t timeout; + time_t timeout; + uint32_t id; + uint32_t user_data; +} CL_MonitorEntry_t; + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup Monitor +/// \~english @par Brief +/// Monitor type enum +///////////////////////////////////////////////////////////////////////////////////// +typedef enum { + CL_MONITOR_TYPE_GENERIC = 0, + CL_MONITOR_TYPE_RPC +} CL_MonitorType_t; + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup Monitor +/// \~english @par Brief +/// Monitor state enum +///////////////////////////////////////////////////////////////////////////////////// +typedef enum { + CL_MONITOR_STATE_SLEEP = 0, + CL_MONITOR_STATE_RUN +} CL_MonitorState_t; + + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup Monitor +/// \~english @par Brief +/// the struct of Monitor Search +///////////////////////////////////////////////////////////////////////////////////// +typedef struct { + CL_MonitorEntry_t *entry_list; + int entry_num; +} CL_MonitorSearch_t; + +#ifdef __cplusplus +extern "C" { +#endif +/** + * @file cl_monitor.h + */ + +/** @addtogroup BaseSystem + * @{ + */ +/** @addtogroup native_service + * @ingroup BaseSystem + * @{ + */ +/** @addtogroup common_library + * @ingroup native_service + * @{ + */ + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup Monitor +/// \~english @par Brief +/// Monitor initialize +/// \~english @param [in] init_type +/// CL_MonitorInit_t - the type of initialzation +/// \~english @retval 0 Success +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// None +/// \~english @par Change of internal state +/// None +/// \~english @par Conditions of processing failure +/// None +/// \~english @par Classification +/// Public +/// \~english @par Type +/// Sync +/// \~english @par Detail +/// None +/// \~english @see None +//////////////////////////////////////////////////////////////////////////////////// +int CL_MonitorInit(CL_MonitorInit_t init_type); // NOLINT(readability/nolint) + + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup Monitor +/// \~english @par Brief +/// Set Monitor Entry +/// \~english @param [in] type +/// CL_MonitorType_t - the type of monitor +/// \~english @param [in] state +/// CL_MonitorState_t - the state of monitor +/// \~english @param [in] timeout +/// uint32_t - the vlaue of timeout +/// \~english @param [in] user_data +/// uint32_t - the user data +/// \~english @retval 0 Success +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// None +/// \~english @par Change of internal state +/// None +/// \~english @par Conditions of processing failure +/// None +/// \~english @par Classification +/// Public +/// \~english @par Type +/// Sync +/// \~english @par Detail +/// None +/// \~english @see None +//////////////////////////////////////////////////////////////////////////////////// +int CL_MonitorSetEntry(CL_MonitorType_t type, uint32_t id, // NOLINT(readability/nolint) + CL_MonitorState_t state, uint32_t timeout, + uint32_t user_data); + + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup Monitor +/// \~english @par Brief +/// Get Monitor Entry +/// \~english @param [in] type +/// CL_MonitorType_t - the type of monitor +/// \~english @param [in] id +/// uint32_t - the monitor id +/// \~english @param [out] entry +/// CL_MonitorEntry_t* - the pointer to monitor entry +/// \~english @retval 0 Success +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// None +/// \~english @par Change of internal state +/// None +/// \~english @par Conditions of processing failure +/// None +/// \~english @par Classification +/// Public +/// \~english @par Type +/// Sync +/// \~english @par Detail +/// None +/// \~english @see None +//////////////////////////////////////////////////////////////////////////////////// +int CL_MonitorGetEntry(CL_MonitorType_t type, uint32_t id, CL_MonitorEntry_t *entry); // NOLINT(readability/nolint) + + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup Monitor +/// \~english @par Brief +/// Monitor searth intialize +/// \~english @param [in] serch +/// CL_MonitorSearch_t* - the pointor to monitory search +/// \~english @retval 0 Success +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// None +/// \~english @par Change of internal state +/// None +/// \~english @par Conditions of processing failure +/// None +/// \~english @par Classification +/// Public +/// \~english @par Type +/// Sync +/// \~english @par Detail +/// None +/// \~english @see None +//////////////////////////////////////////////////////////////////////////////////// +int CL_MonitorSearchInit(CL_MonitorSearch_t *serch); // NOLINT(readability/nolint) + + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup Monitor +/// \~english @par Brief +/// Monitor searth destroy +/// \~english @param [in] serch +/// CL_MonitorSearch_t* - the pointor to monitory search +/// \~english @retval 0 Success +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// None +/// \~english @par Change of internal state +/// None +/// \~english @par Conditions of processing failure +/// None +/// \~english @par Classification +/// Public +/// \~english @par Type +/// Sync +/// \~english @par Detail +/// None +/// \~english @see None +//////////////////////////////////////////////////////////////////////////////////// +int CL_MonitorSearchDestroy(CL_MonitorSearch_t *serch); // NOLINT(readability/nolint) + + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup Monitor +/// \~english @par Brief +/// Monitor searth timeout +/// \~english @param [in] serch +/// CL_MonitorSearch_t* - the pointor to monitory search +/// \~english @retval 0 Success +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// None +/// \~english @par Change of internal state +/// None +/// \~english @par Conditions of processing failure +/// None +/// \~english @par Classification +/// Public +/// \~english @par Type +/// Sync +/// \~english @par Detail +/// None +/// \~english @see None +//////////////////////////////////////////////////////////////////////////////////// +int CL_MonitorSearchTimeout(CL_MonitorSearch_t *search); // NOLINT(readability/nolint) + +/** @}*/ // end of common_library +/** @}*/ // end of NativeService +/** @}*/ // end of BaseSystem +#ifdef __cplusplus +} +#endif + +#endif /* ifndef _cl_monitor_h_ */ // NOLINT(build/header_guard) diff --git a/nsframework/common_library/client/include/native_service/cl_process.h b/nsframework/common_library/client/include/native_service/cl_process.h new file mode 100644 index 00000000..6a9adbfb --- /dev/null +++ b/nsframework/common_library/client/include/native_service/cl_process.h @@ -0,0 +1,1288 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * 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. + */ + +#ifndef _cl_process_h_ // NOLINT(build/header_guard) +#define _cl_process_h_ // NOLINT(build/header_guard) + +#include <sys/types.h> + +#define CL_PROCESSS_ATTR_HOLD_FDS_NUM 8 + +#define CL_INTFY_FILENAME_FORMAT "/tmp/intfy_%05d" + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_ProcessAttr_t +/// \~english @par Brief +/// Process attribute structure +///////////////////////////////////////////////////////////////////////////////////// +typedef struct { + char body[148]; ///< process attribute +} CL_ProcessAttr_t; + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_ProcessCleanupInfo_t +/// \~english @par Brief +/// Child-process attribute structure +///////////////////////////////////////////////////////////////////////////////////// +typedef struct { + pid_t pid; ///< child-process ID + int code; ///< signal code + int status; ///< end status or signal +} CL_ProcessCleanupInfo_t; + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_ProcessSchedPolicy_t +/// \~english @par Brief +/// Schedule policy +///////////////////////////////////////////////////////////////////////////////////// +typedef enum { + CL_PROCESS_SCHED_POLICY_OTHER = 0, ///< TSS + CL_PROCESS_SCHED_POLICY_RR, ///< Round robin + CL_PROCESS_SCHED_POLICY_FIFO, ///< FIFO +} CL_ProcessSchedPolicy_t; + +typedef struct { + char body[20]; +} CL_ThreadAttr_t; + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_ProcessCreateCgroupAttr_t +/// Cgroup attribute structure +///////////////////////////////////////////////////////////////////////////////////// +typedef struct { + char body[24]; ///< Cgroup attribute +} CL_ProcessCreateCgroupAttr_t; + +#ifdef __cplusplus +extern "C" { +#endif +/** + * @file cl_process.h + * @brief \~english This file contains the base api,enum and struct of cl_process. + */ + +/** @addtogroup BaseSystem + * @{ + */ +/** @addtogroup native_service + * @ingroup BaseSystem + * @{ + */ +/** @addtogroup common_library + * @ingroup native_service + * @{ + */ + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_ProcessInit +/// \~english @par Brief +/// Initialize the process +/// \~english @retval int file descriptor +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// - Prerequisites are nothing. +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - Failed to set up process prctl, -1 is returned. +/// - Failed to set the signal set to the empty set sigemptyset, -1 is returned. +/// - Failed to add a signal to the signal mask sigaddset, -1 is returned. +/// - Failed to set sigprocmask, -1 is returned. +/// - Failed to create a scripter in the file for signal acceptance signalfd, -1 is returned. +/// \~english @par Detail +/// This API must be called before createing a thread. +/// Therefore, it is recommended that this API be called from within the main() function immediately after the API started.\n +/// Initialize the process.\n +/// The retuen value fd is assumed to be poll/select and used for waiting for event.\n +/// An ready occurs when the child process terminates.\n +/// Call process name setting(\ref CL_ProcessCreateAttrSetName) uniformly +/// because it is applied only to the number of architecture after exec.\n +/// \~english @par Classification +/// Public +/// \~english @par Type +/// No match +/// \~english @see +/// none +//////////////////////////////////////////////////////////////////////////////////// +int CL_ProcessInit(void); // NOLINT(readability/nolint) + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_ProcessCreate +/// \~english @par Brief +/// Create the process +/// \~english @param [in] file +/// const char* - +/// \~english @param [in] argv[] +/// char* const - +/// \~english @param [in] envp[] +/// char* const +/// \~english @param [in] attr +/// const CL_ProcessAttr_t* - Process attribute pointer +/// \~english @par +/// CL_ProcessAttr_t struct +/// \~english @code +/// typedef struct { +/// char body[148]; +/// } CL_ProcessAttr_t; +/// @endcode +/// \~english @retval int Success(PID) +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// - Need to be running CL_ProcessInit. +/// - Initialize attr with CL_ProcessCreateAttrInit. +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - When the executable name (file) in the argument is NULL, set errno to EINVAL, -1 is returned. +/// - When the ARG parameter (argv[]) in the argument is NULL, set errno to EINVAL, -1 is returned. +/// - When the pointer of the process attribute specified (attr) in the argument is NULL, +/// set errno to EINVAL, -1 is returned. +/// - When memory (malloc) of the data storagee area of the environment variable parameter (envp[]) specified +/// by the arguments fails, set errno to EINVAL, -1 is returned. +/// - When memory (malloc) of the data control area of the environment variable parameter (envp[]) specified +/// by the arguments fails, set errno to EINVAL, -1 is returned. +/// - Process creation (fork) fail, -1 is returned. +/// - Process CPU affinity masking (sched_setaffinity) fail, -1 is returned. +/// - When the character string output processing (snprintf) for process creation fail, -1 is returned. +/// - When the character string output processing (snprintf) for PID setting of cgroup fail, -1 is returned. +/// - Failure to allocate the area fo sstoring the path name of cgroup (malloc), -1 is returned. +/// - Failure to open file descriptor (open) of cgroup, -1 is returned. +/// - Failure to write file descriptor (write) of cgroup, -1 is returned. +/// \~english @par Detail +/// - This API must be called before createing a thread. +/// \~english @par +/// Create the process.\n +/// The ARG parameter (argv[]) specified in the argment must satisfy the following conditions:\n +/// - Can not be omitted.\n +/// - The first argument must specify a pointer o the filename to be executed.\n +/// - An array of pointer to NULL terminated strings.\n +/// - Arrays must be terminated by NULL pointer.\n +/// \~english @par +/// Enviroment-variable parameters (envp[]) specified in arguments mus satisfy the following condiions:\n +/// - When NULL is specified, the parent process inherits the parent process's environment variables.\n +/// - An array of pointer to NULL terminated strings.\n +/// - Arrays must be terminated by NULL pointer.\n +/// \~english @par +/// Be aware of the following.\n +/// - Processing continues without interrupting event if setrlimit() fail.\n +/// - System call access() checks whether or not there is access privilege, +/// but returns PID regardless of the access privilege status. +/// (If the process does not have access privilege, 100 retries are executed at 100 microseconds.) +/// \~english @par +/// Since the process attribute of a process cannot be changed during processing, +/// if it is necessary to change the process attribute, +/// it is necessary to call the following API and change the process attribute before calling this API.\n +/// - CL_ProcessCreateAttrInit Initialize process attribute +/// - CL_ProcessCreateAttrSetCgroup Setting process attribute (Cgroup) +/// - CL_ProcessCreateAttrSetDisableCloseFds Setting process attribute (stop compulsion FD close) +/// - CL_ProcessCreateAttrSetGid Setting process attribute (group ID) +/// - CL_ProcessCreateAttrSetGroup Setting process attribute (process group) +/// - CL_ProcessCreateAttrSetHoldFds Setting process attribute (maintain FD) +/// - CL_ProcessCreateAttrSetName Setting process attribute (process name) +/// - CL_ProcessCreateAttrSetSchedule Setting process attribute (schedule policy and priority) +/// - CL_ProcessCreateAttrSetStackSize Setting process attribute (Stack Size) +/// - CL_ProcessCreateAttrSetUid Setting process attribute (user ID) +/// \~english @par Classification +/// Public +/// \~english @par Type +/// Open Close +/// \~english @see +/// CL_ProcessTerminate, CL_ProcessTerminateGroup +/// CL_ProcessCreateAttrInit, CL_ProcessCreateAttrSetCgroup, +/// CL_ProcessCreateAttrSetDisableCloseFds, CL_ProcessCreateAttrSetGid, +/// CL_ProcessCreateAttrSetGroup, CL_ProcessCreateAttrSetHoldFds, +/// CL_ProcessCreateAttrSetName, CL_ProcessCreateAttrSetSchedule, +/// CL_ProcessCreateAttrSetStackSize, CL_ProcessCreateAttrSetUid +//////////////////////////////////////////////////////////////////////////////////// +int CL_ProcessCreate(const char *file, char * const argv[], char * const envp[], // NOLINT(readability/nolint) + const CL_ProcessAttr_t *attr); + +//////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_ProcessCreateAttrInit +/// \~english @par Brief +/// Initialize process attribute +/// \~english @param [out] attr +/// const CL_ProcessAttr_t* - Process attribute pointer +/// \~english @par +/// CL_ProcessAttr_t struct +/// \~english @code +/// typedef struct { +/// char body[148]; +/// } CL_ProcessAttr_t; +/// @endcode +/// \~english @retval 0 Success +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// - Prerequisites are nothing. +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - When the pointer of the process attribute specified (attr) in the argument is NULL, +/// set errno to EINVAL, -1 is returned. +/// \~english @par Detail +/// Initilize the CL_ProcessAttr_t structure that stores process attribute.\n +/// \~english @par Classification +/// Public +/// \~english @par Type +/// Method(Async) / Fire and Forget / Broadcast / Sync / Set Get / Open Close / Request Notify / No match +/// \~english @see +/// none +//////////////////////////////////////////////////////////////////////////////////// +int CL_ProcessCreateAttrInit(CL_ProcessAttr_t *attr); // NOLINT(readability/nolint) + +//////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_ProcessCreateAttrSetName +/// \~english @par Brief +/// Set process name in process attribute +/// \~english @param [in,out] attr +/// const CL_ProcessAttr_t* - Process attribute pointer +/// \~english @param [in] name +/// const char* - process name (max length 16byte) +/// \~english @par +/// CL_ProcessAttr_t struct +/// \~english @code +/// typedef struct { +/// char body[148]; +/// } CL_ProcessAttr_t; +/// @endcode +/// \~english @retval 0 Success +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// - Initialize attr with CL_ProcessCreateAttrInit. +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - When the pointer of the process attribute specified (attr) in the argument is NULL, +/// set errno to EINVAL, -1 is returned. +/// - When the pointer (name) to the character string hat stores the process name specified +/// by the argument is NULL, set errno to EINVAL, -1 is returned. +/// \~english @par Detail +/// Set process name to process attribute.\n +/// The charactr string that stores the process name specified by the argument must satisfy the following conditions:\n +/// - Terminated by a NULL.\n +/// - The maximum lengthof character string is 16 byte including the termination character.\n +/// \~english @par Classification +/// Public +/// \~english @par Type +/// No match +/// \~english @see +/// none +//////////////////////////////////////////////////////////////////////////////////// +int CL_ProcessCreateAttrSetName(CL_ProcessAttr_t *attr, const char *name); // NOLINT(readability/nolint) + +//////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_ProcessCreateAttrSetUid +/// \~english @par Brief +/// Set process attribute to user ID +/// \~english @param [in,out] attr +/// const CL_ProcessAttr_t* - Process attribute pointer +/// \~english @param [in] uid +/// uid_t - user ID +/// \~english @par +/// CL_ProcessAttr_t struct +/// \~english @code +/// typedef struct { +/// char body[148]; +/// } CL_ProcessAttr_t; +/// @endcode +/// \~english @retval 0 Success +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// - Initialize attr with CL_ProcessCreateAttrInit. +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - When the pointer of the process attribute specified (attr) in the argument is NULL, +/// set errno to EINVAL, -1 is returned. +/// \~english @par Detail +/// Set process attribute to user ID.\n +/// When UINT_MAX is set for the user ID, +/// the user ID is set to 0 in the process attribute in the processing of CL_ProcessCreate().\n +/// When 0 is set for the user ID, +/// it is not reflected in the process attribute becose if is played by the process of CL_ProcessCreate().\n +/// \~english @par Classification +/// Public +/// \~english @par Type +/// No match +/// \~english @see +/// none +//////////////////////////////////////////////////////////////////////////////////// +int CL_ProcessCreateAttrSetUid(CL_ProcessAttr_t *attr, uid_t uid); // NOLINT(readability/nolint) + +//////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_ProcessCreateAttrSetGid +/// \~english @par Brief +/// Set process attribute to group ID +/// \~english @param [in,out] attr +/// const CL_ProcessAttr_t* - Process attribute pointer +/// \~english @param [in] gid +/// gid_t - Group ID +/// \~english @par +/// CL_ProcessAttr_t struct +/// \~english @code +/// typedef struct { +/// char body[148]; +/// } CL_ProcessAttr_t; +/// @endcode +/// \~english @retval 0 Success +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// - Initialize attr with CL_ProcessCreateAttrInit. +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - When the pointer of the process attribute specified (attr) in the argument is NULL, +/// set errno to EINVAL, -1 is returned. +/// \~english @par Detail +/// Set process attribute to group ID.\n +/// When 0 is set for the group ID, +/// it is not reflected in the process attribute becose if is played by the process of CL_ProcessCreate().\n +/// \~english @par Classification +/// Public +/// \~english @par Type +/// No match +/// \~english @see +/// none +//////////////////////////////////////////////////////////////////////////////////// +int CL_ProcessCreateAttrSetGid(CL_ProcessAttr_t *attr, gid_t gid); // NOLINT(readability/nolint) + +//////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_ProcessCreateAttrSetSchedule +/// \~english @par Brief +/// Set process attribute to schedule policy and priority +/// \~english @param [in,out] attr +/// const CL_ProcessAttr_t* - Process attribute pointer +/// \~english @param [in] policy +/// CL_ProcessSchedPolicy_t - schedule policy +/// \~english @param [in] priority +/// int - priority +/// \~english @par +/// CL_ProcessAttr_t struct +/// \~english @code +/// typedef struct { +/// char body[148]; +/// } CL_ProcessAttr_t; +/// @endcode +/// \~english @par +/// enum CL_ProcessSchedPolicy_t Variable +/// \~english @code +/// typedef enum { +/// CL_PROCESS_SCHED_POLICY_OTHER = 0, // TSS +/// CL_PROCESS_SCHED_POLICY_RR, // Round-robin +/// CL_PROCESS_SCHED_POLICY_FIFO, // FIFO +/// } CL_ProcessSchedPolicy_t; +/// @endcode +/// \~english @par +/// target to priority +/// - -20~19 : CL_PROCESS_SCHED_POLICY_OTHER +/// - 1~99 : CL_PROCESS_SCHED_POLICY_RR or CL_PROCESS_SCHED_POLICY_FIFO +/// \~english @retval 0 Success +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// - Initialize attr with CL_ProcessCreateAttrInit. +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - When the pointer of the process attribute specified (attr) in the argument is NULL, +/// set errno to EINVAL, -1 is returned. +/// - When the schedule policy (policy) specified in the parameter is CL_PROCESS_SCHED_POLICY_RR +/// and the priority (priority) is other than 1 to 99, set errno to EINVAL, -1 is returned. +/// - When the schedule policy (policy) specified in the parameter is CL_PROCESS_SCHED_POLICY_FIFO +/// and the priority (priority) is other than 1 to 99, set errno to EINVAL, -1 is returned. +/// - Incorrect parameters are specified for the schedule policy (policy) specified in the arguments, +/// set errno to EINVAL, -1 is returned. +/// \~english @par Detail +/// Set process attribute to schedule policy and priority.\n +/// Error occur if the real-time schedule policy is set and +/// the priority is passed value outside the range of 1-99.\n +/// In the case of TSS, an error does not occur even if it is outside the range of -20 to 19, +/// but ti is rounded to the nearest integer by a system call when a process is created.\n +/// If not set by this funtion, the schedule policy set the TSS and priority sets 0.\n +/// \~english @par Classification +/// Public +/// \~english @par Type +/// No match +/// \~english @see +/// none +//////////////////////////////////////////////////////////////////////////////////// +int CL_ProcessCreateAttrSetSchedule(CL_ProcessAttr_t *attr, // NOLINT(readability/nolint) + CL_ProcessSchedPolicy_t policy, + int priority); + +//////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_ProcessCreateAttrSetGroup +/// \~english @par Brief +/// Set process attribute to process group +/// \~english @param [in,out] attr +/// const CL_ProcessAttr_t* - Process attribute pointer +/// \~english @param [in] create +/// int - (0 or 1) +/// \~english @par +/// - 1 make +/// - 0 not make(default) +/// \~english @par +/// CL_ProcessAttr_t struct +/// \~english @code +/// typedef struct { +/// char body[148]; +/// } CL_ProcessAttr_t; +/// @endcode +/// \~english @retval 0 Success +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// - Initialize attr with CL_ProcessCreateAttrInit. +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - When the pointer of the process attribute specified (attr) in the argument is NULL, +/// set errno to EINVAL, -1 is returned. +/// - When a value oher than 0 or 1 is secified for the process group cration flag (create) +/// specified in the parameter, set errno to EINVAL, -1 is returned. +/// \~english @par Detail +/// Set process attribute to process group.\n +/// When a process group is created, all descendant process fork from child process also belong +/// to the same process group, and the entire process group can be forcibly terminated.\n +/// \~english @par Classification +/// Public +/// \~english @par Type +/// No match +/// \~english @see +/// none +//////////////////////////////////////////////////////////////////////////////////// +int CL_ProcessCreateAttrSetGroup(CL_ProcessAttr_t *attr, int create); // NOLINT(readability/nolint) + +int CL_ProcessCreateAttrSetCpuAssign(CL_ProcessAttr_t *attr, int cpu_assign); // NOLINT(readability/nolint) + +//////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_ProcessCreateAttrSetStackSize +/// \~english @par Brief +/// Set process attribute to stack size +/// \~english @param [in,out] attr +/// const CL_ProcessAttr_t* - Process attribute pointer +/// \~english @param [in] stack_size +/// int - stack size(byte) +/// \~english @par +/// CL_ProcessAttr_t struct +/// \~english @code +/// typedef struct { +/// char body[148]; +/// } CL_ProcessAttr_t; +/// @endcode +/// \~english @retval 0 Success +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// - Initialize attr with CL_ProcessCreateAttrInit. +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - When the pointer of the process attribute specified (attr) in the argument is NULL, +/// set errno to EINVAL, -1 is returned. +/// \~english @par Detail +/// Set process attribute to stack size.\n +/// The muximum configurable stack size is 1MB.\n +/// \~english @par Classification +/// Public +/// \~english @par Type +/// No match +/// \~english @see +/// none +//////////////////////////////////////////////////////////////////////////////////// +int CL_ProcessCreateAttrSetStackSize(CL_ProcessAttr_t *attr, int stack_size); // NOLINT(readability/nolint) + +//////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_ProcessCreateAttrSetHoldFds +/// \~english @par Brief +/// Set process attribute to FD to maintain +/// \~english @param [in,out] attr +/// const CL_ProcessAttr_t* - Process attribute pointer +/// \~english @param [in] hold_fds[] +/// int - +/// \~english @par +/// CL_ProcessAttr_t struct +/// \~english @code +/// typedef struct { +/// char body[148]; +/// } CL_ProcessAttr_t; +/// @endcode +/// \~english @retval 0 Success +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// - Initialize attr with CL_ProcessCreateAttrInit. +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - When the pointer of the process attribute specified (attr) in the argument is NULL, +/// set errno to EINVAL, -1 is returned. +/// - When the array (hode_openfd[]) storing the list of the FD to be maintained specified +/// by the arguments is NULL, set errno to EINVAL, -1 is returned. +/// \~english @par Detail +/// Set process attribute to FD to maintain.\n +/// When nothing is set, FD other than 0, 1, and 2 are automatically close.\n +/// For hold_openfds is stored in a CL_PROCESSS_ATTR_HOLD_FDS_NUM array, +/// it is recommended that int hold_openfds[CL_PROCESSS_ATTR_HOLD_FDS_NUM] be used.\n +/// \~english @par Classification +/// Public +/// \~english @par Type +/// No match +/// \~english @see +/// none +//////////////////////////////////////////////////////////////////////////////////// +int CL_ProcessCreateAttrSetHoldFds(CL_ProcessAttr_t *attr, int hold_fds[]); // NOLINT(readability/nolint) + +//////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_ProcessCreateAttrSetDisableCloseFds +/// \~english @par Brief +/// Set process attribute to suspend forced FD close +/// \~english @param [in,out] attr +/// const CL_ProcessAttr_t* - Process attribute pointer +/// \~english @par +/// CL_ProcessAttr_t struct +/// \~english @code +/// typedef struct { +/// char body[148]; +/// } CL_ProcessAttr_t; +/// @endcode +/// \~english @retval 0 Success +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// - Initialize attr with CL_ProcessCreateAttrInit. +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - When the pointer of the process attribute specified (attr) in the argument is NULL, +/// set errno to EINVAL, -1 is returned. +/// \~english @par Detail +/// Set process attribute to suspend forced FD close.\n +/// \~english @par Classification +/// Public +/// \~english @par Type +/// No match +/// \~english @see +/// none +//////////////////////////////////////////////////////////////////////////////////// +int CL_ProcessCreateAttrSetDisableCloseFds(CL_ProcessAttr_t *attr); // NOLINT(readability/nolint) + +//////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_ProcessCreateAttrSetCgroup +/// \~english @par Brief +/// Set process attribute to Cgroup +/// \~english @param [in,out] attr +/// const CL_ProcessAttr_t* - Process attribute pointer +/// \~english @param [in] cgroup_name +/// const char* - Cgroup name +/// \~english @par +/// CL_ProcessAttr_t struct +/// \~english @code +/// typedef struct { +/// char body[148]; +/// } CL_ProcessAttr_t; +/// @endcode +/// \~english @retval 0 Success +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// - Initialize attr with CL_ProcessCreateAttrInit. +/// - cgroup specified by CL_ProcessCreateCgroupCreate() has been created. +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - When the pointer of the process attribute specified (attr) in the argument is NULL, +/// set errno to EINVAL, -1 is returned. +/// - When the pointer (name) to the character string hat stores the process name specified +/// by the argument is NULL, set errno to EINVAL, -1 is returned. +/// - When the character string length of the character string (cgroup_name) storing the process name specified +/// by the argument is 64 byte or more, set errno to EINVAL, -1 is returned. +/// \~english @par Detail +/// Set process attribute to Cgroup.\n +/// Creat new Cgroup with CL_ProcessCreateCgroupCreate().\n +/// An error occurs if an Cgroup name that does not exist is specified.\n +/// \~english @par Classification +/// Public +/// \~english @par Type +/// No match +/// \~english @see +/// none +//////////////////////////////////////////////////////////////////////////////////// +int CL_ProcessCreateAttrSetCgroup(CL_ProcessAttr_t *attr, // NOLINT(readability/nolint) + const char *cgroup_name); + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_ProcessTerminate +/// \~english @par Brief +/// Kill the process +/// \~english @param [in] pid +/// pid_t - PID +/// \~english @retval int file descriptor +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// - CL_ProcessInit and CL_ProcessCreate must be running. +/// (Process ID to be forcibly terminated exists) +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - When the process ID to be forcibly terminated does not exist, -1 is returned. +/// \~english @par Detail +/// The PID of the process is he return value (PID) of CL_ProcessCreate(). +/// \~english @par Classification +/// Public +/// \~english @par Type +/// Open Close +/// \~english @see +/// CL_ProcessCreate +///////////////////////////////////////////////////////////////////////////////////// +int CL_ProcessTerminate(pid_t pid); // NOLINT(readability/nolint) + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_ProcessTerminateGroup +/// \~english @par Brief +/// Kill process group +/// \~english @param [in] pid +/// pid_t - process group ID +/// \~english @retval int file descriptor +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// - CL_ProcessInit and CL_ProcessCreate must be running. +/// (Process ID to be forcibly terminated exists) +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - When the process ID to be forcibly terminated does not exist, -1 is returned. +/// \~english @par Detail +/// The process group ID is he return value (PID) of CL_ProcessCreate(). +/// \~english @par Classification +/// Public +/// \~english @par Type +/// Open Close +/// \~english @see +/// CL_ProcessCreate +///////////////////////////////////////////////////////////////////////////////////// +int CL_ProcessTerminateGroup(pid_t pid); // NOLINT(readability/nolint) + +int CL_ProcessAbort(pid_t pid); // NOLINT(readability/nolint) + +int CL_ProcessAbortGroup(pid_t pid); // NOLINT(readability/nolint) + +int CL_ProcessEuthanizeGroup(pid_t pid); // NOLINT(readability/nolint) + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_ProcessCleanup +/// \~english @par Brief +/// Collect child process +/// \~english @param [in] sigchld_fd +/// int - CL_ProcessInit() function return to fd +/// \~english @param [out] cleanup_info +/// CL_ProcessCleanupInfo_t* - Pointer to chiled process info +/// \~english @par +/// CL_ProcessCleanupInfo_t struct +/// \~english @code +/// typedef struct { +/// pid_t pid; /* The process ID of the child. */ +/// int code; /* signal code */ +/// int status; /* the exit status of the child or the signal */ +/// } CL_ProcessCleanupInfo_t; +/// @endcode +/// \~english @retval 0 Success +/// \~english @retval 1 Success +/// (If WNOHANG was specified and no child(ren) specified by id has yet changed state) +/// \~english @retval -1 Error (setting to errno) +/// \~english @par Prerequisite +/// - Must be runnning CL_ProcessInit. +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - When the pointer (cleanup_info) to the child process information structure is NULL, +/// set errno to EINVAL, -1 is returned. +/// - When a systemu call (waitid) fails, -1 is returned. +/// - When there are no child process in state waitable, set errno to EINVAL, -1 is returned. +/// \~english @par Detail +/// This API must be called before createing a thread.\n +/// \~english @par +/// It must be called many times while the return valu is 1. +/// After the return value reaches 0, calling it again results in an error (ECHILD).\n +/// The code of CL_ProcessCleanupInfo_t cotains the following value:\n +/// - CLD_EXITED : Finished child process (exited) +/// - CLD_KILLED : Killed child process +/// - CLD_DUMPED : Ended abnormally child process +/// - CLD_TRAPPED : Trapped traced child process +/// - CLD_STOPPED : Stopped child process (stop) +/// - CLD_CONTINUED restarted the sopped child process (after Linux 2.6.9) +/// - The exit status is stored in status only when code is CLD_EXITED. Otherwise, signals are stored. +/// - Need to include signal.h to use CLD_*. +/// \~english @par Classification +/// Public +/// \~english @par Type +/// No match +/// \~english @see +/// none +//////////////////////////////////////////////////////////////////////////////////// +int CL_ProcessCleanup(int sigchld_fd, CL_ProcessCleanupInfo_t *cleanup_info); // NOLINT(readability/nolint) + +//////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_ThreadCreate +/// \~english @par Brief +/// Create thread +/// \~english @param [out] thread +/// pthread_t* - thread hadle +/// \~english @param [in] attr +/// pthread_attr_t* - Thread attibute pointer for pthread +/// \~english @param [in] cl_attr +/// CL_ThreadAttr_t* - Tred attribute pointer for expansion +/// \~english @param [in] start_routine +/// void*(*)(void*) - Pointer to the entry function of the thread +/// \~english @param [in] arg +/// void* - Argument to the entry function of the thread +/// \~english @par +/// CL_ThreadAttr_t structure +/// \~english @code +/// typedef struct { +/// char body[20]; +/// } CL_ThreadAttr_t; +/// @endcode +/// \~english @retval 0 Success +/// \~english @retval -1 Error (set errno) +/// \~english @retval EAGAIN failure to create thread +/// \~english @par Prerequisite +/// - Prerequisites are nothing. +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - When the thread handler (thread) specified in the argument is NULL, set errno to EINVAL, -1 is returned. +/// - When the pointer of the thread attribute specified in the argument is NULL, +/// set errno to EINVAL, -1 is returned. +/// - When the pointer (start_routine) of the entry function of the thread specified by the argument is NULL, +/// set errno to EINVAL, -1 is returned. +/// - Failure to initialize semaphore, set errno to sem_init, -1 is returned. +/// - Failure to create thread (pthread_create), EAGAIN is returned. +/// - Failure to rock semaphore (sem_wait), set errno to sem_init, -1 is returned. +/// \~english @par Detail +/// Create thread.\n +/// The extension thread attribute (cl_attr) is used o assign the thread name set +/// by CL_ThreadCreateAttrSetName(CL_ThreadAttr_t*, const char*).\n +/// \~english @par Classification +/// Public +/// \~english @see +/// none +//////////////////////////////////////////////////////////////////////////////////// +int CL_ThreadCreate(pthread_t *thread, pthread_attr_t *attr, // NOLINT(readability/nolint) + CL_ThreadAttr_t *cl_attr, void *(*start_routine)(void *), + void *arg); + +//////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_ThreadCreateAttrInit +/// \~english @par Brief +/// Initialize thread attribute +/// \~english @param [out] attr +/// CL_ThreadAttr_t* - thread attribute pointer +/// \~english @par +/// CL_ThreadAttr_t structure +/// \~english @code +/// typedef struct { +/// char body[20]; +/// } CL_ThreadAttr_t; +/// @endcode +/// \~english @retval 0 Success +/// \~english @retval -1 Error (set errno) +/// \~english @par Prerequisite +/// - Prerequisites are nothing. +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - When the pointer (attr) of the thread attributespecified by the argument is NULL, set errno to EINVAL, -1 is returned. +/// \~english @par Detail +/// Initialize structure CL_ThreadAttr_t that stores threade attribute.\n +/// \~english @par Classification +/// Public +/// \~english @see +/// none +//////////////////////////////////////////////////////////////////////////////////// +int CL_ThreadCreateAttrInit(CL_ThreadAttr_t *attr); // NOLINT(readability/nolint) + +//////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_ThreadCreateAttrSetName +/// \~english @par Brief +/// Set thread attribute to thread name +/// \~english @param [out] attr +/// CL_ThreadAttr_t* - thread attribute pointer +/// \~english @param [in] name +/// const char* - Pointer to the string storing the thread name (max length 16byte) +/// \~english @par +/// CL_ThreadAttr_t structure +/// \~english @code +/// typedef struct { +/// char body[20]; +/// } CL_ThreadAttr_t; +/// @endcode +/// \~english @retval 0 Success +/// \~english @retval -1 Error (set errno) +/// \~english @par Prerequisite +/// - Prerequisites are nothing. +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - When the pointer (attr) of thread attribute specified by the argument is NULL, set errno to EINVAL, -1 is returned. +/// - When the pointer (name) to the character string that stores the thread name specified +/// by the argument is NULL, set errno to EINVAL, -1 is returned. +/// \~english @par Detail +/// Set thread attribute to thread name\n +/// The characer string that stores the thread name specified by the argument must satisfy the following conditions:\n +/// - Terminated by a NULL.\n +/// - The maximum lengthof character string is 16 byte including the termination character.\n +/// \~english @par Classification +/// Public +/// \~english @see +/// none +//////////////////////////////////////////////////////////////////////////////////// +int CL_ThreadCreateAttrSetName(CL_ThreadAttr_t *attr, const char *name); // NOLINT(readability/nolint) + +//////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_ProcessCreateCgroupCreate +/// \~english @par Brief +/// Create Cgroup +/// \~english @param [in] cgroup_name +/// const char* - cgroup name +/// \~english @param [in] attr +/// const CL_ProcessCreateCgroupAttr_t* - Cgroup attribut +/// \~english @par +/// CL_ProcessCreateCgroupAttr_t struct +/// \~english @code +/// typedef struct { +/// char body[24]; +/// } CL_ProcessCreateCgroupAttr_t; +/// @endcode +/// \~english @retval 0 Success +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// - Initialize attr by CL_ProcessCreateCgroupAttrInit +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - When the Cgroup name (cgroup_name) specified by the argument is NULL, set errno to EINVAL, -1 is returned. +/// - When the pointer (attr) of the Cgroup attribute specified by the argumet is NULL, +/// set errno to EINVAL, -1 is returned. +/// - When the area for directory path name of the CPU subsystem of Cgroup could not be allocated, +/// set errno to EINVAL, -1 is returned. +/// - When the area for directory of the CPU subsystem of Cgroup could not be create, -1 is returned. +/// - When the area for file path name of the CPU subsystem of Cgroup could not be allocated, +/// set errno to EINVAL, -1 is returned. +/// - When file descriptor of the CPU subsystem of Cgroup could not be acquired, -1 is returned. +/// - When setting value to CPU subsystem of Cgroup could not be written, -1 is returned. +/// - When the area for directory path name of the memory subsystem of Cgroup could not be allocated, +/// set errno to EINVAL, -1 is returned. +/// - When the area for directory of the memory subsystem of Cgroup could not be create, -1 is returned. +/// - When the area for file path name of the memory subsystem of Cgroup could not be allocated, +/// set errno to EINVAL, -1 is returned. +/// - When file descriptor of the memory subsystem of Cgroup could not be acquired, -1 is returned. +/// - When setting value to memory subsystem of Cgroup could not be written, -1 is returned. +/// \~english @par Detail +/// Create Cgroup to which the process to be created belongs. +/// If it belongs to Cgroup that has already been created, it is not necessary to create it.\n +/// \~english @par +/// Since the Cgroup attribute cannot be changed during Cgroup, if it is necessary o chage the Cgroup attribute, +/// it is necessary to call the following API and change the Cgroup attribute calling this API.\n +/// - CL_ProcessCreateCgroupAttrInit :Initialize Cgroup attribute +/// - CL_ProcessCreateCgroupAttrSetCfsBandwidthControl :TSS process CPU time control by Bandwidth Control +/// - CL_ProcessCreateCgroupAttrSetCpuShares :TSS process CPU time control +/// - CL_ProcessCreateCgroupAttrSetMemoryLimit :Contol memory usage +/// - CL_ProcessCreateCgroupAttrSetMemoryUsageNotification :Memory usage notification setting +/// - CL_ProcessCreateCgroupAttrSetRtThrottling :FIFO/RR process CPU time control +/// \~english @par Classification +/// Public +/// \~english @par Type +/// Open Close +/// \~english @see +/// CL_ProcessCreateCgroupDelete, +/// CL_ProcessCreateCgroupAttrInit, CL_ProcessCreateCgroupAttrSetCfsBandwidthControl, +/// CL_ProcessCreateCgroupAttrSetCpuShares, CL_ProcessCreateCgroupAttrSetMemoryLimit, +/// CL_ProcessCreateCgroupAttrSetMemoryUsageNotification, CL_ProcessCreateCgroupAttrSetRtThrottling, +//////////////////////////////////////////////////////////////////////////////////// +int CL_ProcessCreateCgroupCreate(const char *cgroup_name, // NOLINT(readability/nolint) + CL_ProcessCreateCgroupAttr_t *attr); + +//////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_ProcessCreateCgroupAttrInit +/// \~english @par Brief +/// Initialize Cgroup attribute +/// \~english @param [out] attr +/// const CL_ProcessCreateCgroupAttr_t* - Cgroup attribute pointer +/// \~english @par +/// CL_ProcessCreateCgroupAttr_t struct +/// \~english @code +/// typedef struct { +/// char body[24]; +/// } CL_ProcessCreateCgroupAttr_t; +/// @endcode +/// \~english @retval 0 Success +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// - Prerequisites are nothing. +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - When the pointer of Cgroup attribute (attr) specified in the arguments is NULL, set errno to EINVAL, -1 is returned. +/// \~english @par Detail +/// Initialize Cgroup attibute with 0.\n +/// \~english @par Classification +/// Public +/// \~english @par Type +/// No match +/// \~english @see +/// none +//////////////////////////////////////////////////////////////////////////////////// +int CL_ProcessCreateCgroupAttrInit(CL_ProcessCreateCgroupAttr_t *attr); // NOLINT(readability/nolint) + +//////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_ProcessCreateCgroupAttrSetRtThrottling +/// \~english @par Brief +/// Set FIFO/RR process CPU time control +/// \~english @param [in,out] attr +/// const CL_ProcessCreateCgroupAttr_t* - Cgroup attribute +/// \~english @param [in] runtime_us +/// int - CPU allocation time(us) +/// \~english @par +/// CL_ProcessCreateCgroupAttr_t struct +/// \~english @code +/// typedef struct { +/// char body[24]; +/// } CL_ProcessCreateCgroupAttr_t; +/// @endcode +/// \~english @retval 0 Success +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// - Initialize attr with CL_ProcessCreateCgroupAttrInit. +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - When the pointer of Cgroup attribute (attr) specified in the arguments is NULL, +/// set errno to EINVAL, -1 is returned. +/// \~english @par Detail +/// Limiting the CPU time allocated to a process to +/// which a real-time class schedule policy (SCHED_FIFO/SCHED_RR) is applied.\n +/// Set the value of argument runtime_us to the cpu.rt_runtime_us (CPU allocation time) of created Cgroup.\n +/// cpu.rt_period_us(unit time:1000000us) is not changed.\n +/// If not set, Cgroup created will remain at default (CPU allocation time:950000us).\n +/// The configurable range of runtime_us depends on the use of Cgroup and the kernel version. +/// The user sets an appropriate value.\n +/// \~english @par Classification +/// Public +/// \~english @par Type +/// No match +/// \~english @see +/// none +//////////////////////////////////////////////////////////////////////////////////// +int CL_ProcessCreateCgroupAttrSetRtThrottling( // NOLINT(readability/nolint) + CL_ProcessCreateCgroupAttr_t *attr, int runtime_us); + +//////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_ProcessCreateCgroupAttrSetCpuShares +/// \~english @par Brief +/// Set TSS process CPU time control +/// \~english @param [in,out] attr +/// const CL_ProcessCreateCgroupAttr_t* - Cgroup attribute pointer +/// \~english @param [in] cpu_shares +/// int - An integer value that sepcified the relative distribution of CPU time +/// \~english @par +/// CL_ProcessCreateCgroupAttr_t struct +/// \~english @code +/// typedef struct { +/// char body[24]; +/// } CL_ProcessCreateCgroupAttr_t; +/// @endcode +/// \~english @retval 0 Success +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// - Initialize attr with CL_ProcessCreateCgroupAttrInit +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - When the pointer (attr) of the Cgroup attribute specified by the argument is NULL, +/// set errno to EINVAL, -1 is returned. +/// \~english @par Detail +/// Cotrols the CPU time allocated to a process to which +/// a class TSS schedule policy (SCHED_OTHER, etc.) is applied.\n +/// If cpu_shares is set with this function, a single Cgroup is created and cpu.shares is set with that value.\n +/// If not set, remain at default.\n +/// cpu_shares is set to the standard value 1024, and CPU time is allocated according +/// to the allocaion value specified between Cgroup.\n +/// Task Cgroup with cpu.shares set to 1024 has twice as much CPU time as +/// task Cgroup with cpu.shares set to 512.\n +/// Processes belonging to the same Cgroup are equally allocated CPU time allocated to Cgroup.\n +/// Note that the time distribution is distributed across al CPU cores on a multi-core system.\n +/// In a multicore system, if Cgroup limit is set to 100% of the CPU, +/// 100% of each CPU core wil be available.\n\n +/// Examle) If Cgroup A is set to use 25% of the CPU and Cgroup B is set to use 75% of the CPU,\n +/// and a process that uses CPU intensively is started on a 4-core system (1 process in A and 3 processes in B),\n +/// the CPU allocaion is distributed as follows.\n\n +/// \~english @par +/// | PID | cgroup | CPU | CPU allotment | +/// |:---:|:------:|:---:|:-------:| +/// | 100 | A | 0 | CPU0 100% | +/// | 101 | B | 1 | CPU1 100% | +/// | 102 | B | 2 | CPU2 100% | +/// | 103 | B | 3 | CPU3 100% | +/// \~english @par +/// \~english @par Classification +/// Public +/// \~english @par Type +/// No match +/// \~english @see +/// none +//////////////////////////////////////////////////////////////////////////////////// +int CL_ProcessCreateCgroupAttrSetCpuShares(CL_ProcessCreateCgroupAttr_t *attr, // NOLINT(readability/nolint) + int cpu_shares); + +/////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_ProcessCreateCgroupAttrSetCfsBandwidthControl +/// \~english @par Brief +/// Set TS process CU time control by Bandwidth Control +/// \~english @param [in,out] attr +/// const CL_ProcessCreateCgroupAttr_t* - Cgroup attribute pointer +/// \~english @param [in] cfs_quota_us +/// int - CPU allocation time +/// \~english @par +/// CL_ProcessCreateCgroupAttr_t struct +/// \~english @code +/// typedef struct { +/// char body[24]; +/// } CL_ProcessCreateCgroupAttr_t; +/// @endcode +/// \~english @retval 0 Success +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// - Initialize attr with CL_ProcessCreateCgroupAttrInit +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - When the pointer of the process attribute specified (attr) in the argument is NULL, +/// set errno to EINVAL, -1 is returned. +/// \~english @par Detail +/// Controls the amount of time allocated to processes o whitch TSS class schedule plicy (SCHED_OTHER, etc.) are +/// applied using bandwidth control of CFS(Completely Fair Scheduler) implemented from kernel 3.2.\n +/// Set the value of argument cfs_quota_us to the cpu.cfs_quota_us of created Cgroup.\n +/// cpu.cfs_period_us(unit time:1000000us) is not changed.\n +/// If not set, the created Cgroup will not have CPU allocatio control. (set cpu.cfs_guota_us to -1).\n +/// The time (%) allocated to Cgroup can be set correctly, +/// and it can be allocated correctly if the CPU is free.\n +/// It is scheduled to be allocated as much as possible even if it conflicts with other Cgroup's.\n +/// \~english @par Classification +/// Public +/// \~english @par Type +/// No match +/// \~english @see +/// none +//////////////////////////////////////////////////////////////////////////////////// +int CL_ProcessCreateCgroupAttrSetCfsBandwidthControl( // NOLINT(readability/nolint) + CL_ProcessCreateCgroupAttr_t *attr, int cfs_quota_us); + +///////////////////////////////////////////////////////////////// +/// \ingroup CL_ProcessCreateCgroupAttrSetMemoryLimit +/// \~english @par Brief +/// Control memory usage +/// \~english @param [in,out] attr +/// const CL_ProcessCreateCgroupAttr_t* - Cgroup attribute pointer +/// \~english @param [in] memory_limit +/// int - memory limit (byte) +/// \~english @par +/// CL_ProcessCreateCgroupAttr_t struct +/// \~english @code +/// typedef struct { +/// char body[24]; +/// } CL_ProcessCreateCgroupAttr_t; +/// @endcode +/// \~english @retval 0 Success +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// - Initialize attr with CL_ProcessCreateCgroupAttrInit +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - When the pointer of the process attribute specified (attr) in the argument is NULL, +/// set errno to EINVAL, -1 is returned. +/// \~english @par Detail +/// Control the CPU time allocated to a process.\n +/// Set the value of argument memory_limit to the memory.limit_in_bytes of created Cgroup.\n +/// If not set, there is no memory limit.When a request exceeding the memory limit is issued, +/// a SIGKILL is sent from the kernel and the process is discarded. +/// Note: When the memory limit is exceeded, control moves to 00M, +/// but its operation ca be changed (Documentation/cgroup/memory.txt).\n +/// Write memory.oom_control to 1 to stop the OOM-Killer. +/// When OOM-Killer is stopped, the task below Cgroup becomes hang/sleep.\n +/// The task moves when the limit of the memory Cgroup increaes or when usage decreases. When usage decreases,\n +/// - Task was killed\n +/// - Task was moved other group\n +/// - File has been deleted\n +/// \~english @par +/// You can also receive a eventf notification from OOM.\n +/// Memory usage is counted as follows\n +/// - RSS(All mapped anon pages)\n +/// - Page Cache\n +/// - First acess Shared Pages in Cgroup\n +/// \~english @par Classification +/// Public +/// \~english @par Type +/// No match +/// \~english @see +/// none +//////////////////////////////////////////////////////////////////////////////////// +int CL_ProcessCreateCgroupAttrSetMemoryLimit(CL_ProcessCreateCgroupAttr_t *attr, // NOLINT(readability/nolint) + int memory_limit); + +//////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_ProcessCreateCgroupAttrSetMemoryUsageNotification +/// \~english @par Brief +/// Set notificatio when memory usage exceeds the specified amount +/// \~english @param [in,out] attr +/// const CL_ProcessCreateCgroupAttr_t* - Cgroup attribute pointer +/// \~english @param [in] usage_in_bytes +/// int - usage in bytes(byte) +/// \~english @param [in] event_fd +/// int - File dexcriptor created by system call eventfd() +/// \~english @par +/// CL_ProcessCreateCgroupAttr_t struct +/// \~english @code +/// typedef struct { +/// char body[24]; +/// } CL_ProcessCreateCgroupAttr_t; +/// @endcode +/// \~english @retval 0 Success +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// - Initialize attr with CL_ProcessCreateCgroupAttrInit +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - When the pointer of the process attribute specified (attr) in the argument is NULL, +/// set errno to EINVAL, -1 is returned. +/// - When event_fd is negative for a file descriptor created by system call eventfd(), +/// set errno to EINVAL, -1 is returned. +/// \~english @par Detail +/// event_fd is notifued when memory usage exceeds argument usage_in_bytes.\n +/// See eventfd for details of event_fd.\n +/// \~english @par Classification +/// Public +/// \~english @par Type +/// No match +/// \~english @see +/// none +//////////////////////////////////////////////////////////////////////////////////// +int CL_ProcessCreateCgroupAttrSetMemoryUsageNotification( // NOLINT(readability/nolint) + CL_ProcessCreateCgroupAttr_t *attr, int usage_in_bytes, int event_fd); + +//////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_ProcessCreateCgroupDelete +/// \~english @par Brief +/// Delete Cgroup +/// \~english @param [in] cgroup_name +/// const char* - cgroup name +/// \~english @retval 0 Success +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// - Need to be runnning CL_ProcessCreateCgroupCreate. +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - When the Cgroup (cgroup_name) name specified inthe argument is NULL, set errno to EINVAL, -1 is returned. +/// - When the area for directory path name of the CPU subsystem of Cgroup and +/// memory subsystem of Cgroup could not be allocated, set errno to EINVAL, -1 is returned. +/// - When the area for the directory path name of the memory subsystem of Cgroup cannot be allocated and +/// the directory for the CPU subsystem of Cgroup does not exist, set errno to EINVAL, -1 is returned. +/// - When the directory for the CPU subsystem of Cgroup does not exist and +/// the area for the directory path name of the memory subsystem of Cgroup cannot be allocated, +/// set errno to EINVAL, -1 is returned. +/// - When the directory for the memory subsystem of Cgroup and +/// the directory for the CPU subsystem of Cgroup does not exist, set errno to EINVAL, -1 is returned. +/// - When the directory for the memory subsystem of Cgroup could not be deleted, -1 is returned. +/// - When the directory for the CPU subsystem of Cgroup could not be deleted, -1 is returned. +/// \~english @par Detail +/// Delete Cgroup. If there is a proess belonging to Cgroup, error code (EBUSY) is returned.\n +/// \~english @par +/// Success is also notified in the following cases:\n +/// - When the area for directory path name of memory subsyste Cgroup could not be allocated +/// but CPU subsystem of Cgroup was deleted successfully. +/// - When the directory for the memory subsystem of Cgroup does not exist, +/// but CPU subsystem of Cgroup was deleted successfully. +/// - When the area for directory path name of CPU subsyste Cgroup could not be allocated +/// but memory subsystem of Cgroup was deleted successfully. +/// - When the directory for the CPU subsystem of Cgroup does not exist, +/// but memory subsystem of Cgroup was deleted successfully. +/// \~english @par Classification +/// Public +/// \~english @par Type +/// Open Close +/// \~english @see +/// CL_ProcessCreateCgroupCreate +//////////////////////////////////////////////////////////////////////////////////// +int CL_ProcessCreateCgroupDelete(const char *cgroup_name); // NOLINT(readability/nolint) + +//////////////////////////////////////////////////////////////////////////////////// +/// \ingroup CL_ProcessCreateCgroupClassify +/// \~english @par Brief +/// Move process to the Cgroup +/// \~english @param [in,out] cgroup_name +/// const char* - Destination A name +/// \~english @param [in] pid +/// pid_t - process ID +/// \~english @retval 0 Success +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// - Need to be running CL_ProcessCreateCgroupCreate. +/// \~english @par Change of internal state +/// - Change of internal state according to the API does not occur. +/// \~english @par Conditions of processing failure +/// - When the Cgroup (cgroup_name) specified in the argument is NULL, set errno to EINVAL, -1 is returned. +/// - When the area for directory path name of memory subsystem of Cgroup and +/// CPU subsystem of Cgroup could not be allocated, set errno to EINVAL, -1 is returned. +/// - When the area for directory path name of memory subsystem of Cgroup could not be allocated, +/// and the directory for CPU subsystem of Cgroup does not exist, set errno to EINVAL, -1 is returned. +/// - When the directory for memory subsystem of Cgroup does not exist and +/// the directory for CU subsystem of Cgroup could not allocated , set errno to EINVAL, -1 is returned. +/// - When the directory for the memory subsystem of Cgroup and +/// the directory for the CPU subsystem of Cgroup does not exist, set errno to EINVAL, -1 is returned. +/// - When the area for directory path name of the memory subsystem of Cgroup could not allocated, +/// set errno to EINVAL, -1 is returned. +/// - When the file descripter for the memory subsystem of Cgroup could not be obtained, -1 is returned. +/// - When pid could not be written to the file for memory subsystem of Cgroup, -1 is returned. +/// - When the area for directory path name of the CPU subsystem of Cgroup could not be allocated, +/// set errno to EINVAL, -1 is returned. +/// - When the file decsripter for the CPU subsystem of Cgroup could not be allocated, -1 is returned. +/// - When pid could not be written to the file for CPU subsystem of Cgroup, -1 is returned. +/// \~english @par Detail +/// Move process to the Cgroup.\n +/// \~english @par +/// Success is also notified in the following cases:\n +/// - When the area for directory path name of memory subsyste Cgroup could not be allocated +/// but CPU subsystem of Cgroup was deleted successfully. +/// - When the directory for the memory subsystem of Cgroup does not exist, +/// but CPU subsystem of Cgroup was deleted successfully. +/// - When the area for directory path name of CPU subsyste Cgroup could not be allocated +/// but memory subsystem of Cgroup was deleted successfully. +/// - When the directory for the CPU subsystem of Cgroup does not exist, +/// but memory subsystem of Cgroup was deleted successfully. +/// \~english @par Classification +/// Public +/// \~english @par Type +/// No match +/// \~english @see +/// none +//////////////////////////////////////////////////////////////////////////////////// +int CL_ProcessCreateCgroupClassify(const char *cgroup_name, pid_t pid); // NOLINT(readability/nolint) + +/** @}*/ // end of common_library +/** @}*/ // end of NativeService +/** @}*/ // end of BaseSystem +#ifdef __cplusplus +} +#endif + +#endif // #ifndef _cl_process_h_ // NOLINT(build/header_guard) diff --git a/nsframework/common_library/client/include/native_service/cl_region.h b/nsframework/common_library/client/include/native_service/cl_region.h new file mode 100644 index 00000000..c9eec5f3 --- /dev/null +++ b/nsframework/common_library/client/include/native_service/cl_region.h @@ -0,0 +1,257 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * 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 cl_region.h + * @brief region manage + * + */ + +#ifndef _CL_REGION_H_ // NOLINT(build/header_guard) +#define _CL_REGION_H_ // NOLINT(build/header_guard) + +#include <stdint.h> +#include <stdbool.h> +#include <unistd.h> + +#define CL_REGION_DEFAULT_SIZE (4 * 1024) + +#define CL_ALIGNOF(type) __alignof(type) + +typedef void (*cl_region_cleanup_pt)(void *data); + +typedef struct cl_region_cleanup_s cl_region_cleanup_t; + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup Monitor +/// \~english @par Brief +/// region cleanup struct +///////////////////////////////////////////////////////////////////////////////////// +struct cl_region_cleanup_s { // NOLINT(readability/nolint) + cl_region_cleanup_pt handler; + void *data; + cl_region_cleanup_t *next; +}; + + +typedef struct cl_region_large_s cl_region_large_t; + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup Monitor +/// \~english @par Brief +/// region large struct +///////////////////////////////////////////////////////////////////////////////////// +struct cl_region_large_s { // NOLINT(readability/nolint) + cl_region_large_t *next; + void *alloc; + size_t size; +}; + + +typedef struct cl_region_s cl_region_t; + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup Monitor +/// \~english @par Brief +/// region data struct +///////////////////////////////////////////////////////////////////////////////////// +typedef struct { + uint8_t *last; + uint8_t *end; + cl_region_t *next; + int failed; +} cl_region_data_t; + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup Monitor +/// \~english @par Brief +/// region struct +///////////////////////////////////////////////////////////////////////////////////// +struct cl_region_s { // NOLINT(readability/nolint) + cl_region_data_t d; + size_t max; + cl_region_t *current; + cl_region_large_t *large; + cl_region_cleanup_t *cleanup; +}; + + +#ifdef __cplusplus +extern "C" { +#endif +/** + * @file cl_region.h + */ + +/** @addtogroup BaseSystem + * @{ + */ +/** @addtogroup native_service + * @ingroup BaseSystem + * @{ + */ +/** @addtogroup common_library + * @ingroup native_service + * @{ + */ + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup Region +/// \~english @par Brief +/// Region create +/// \~english @param [in] size +/// size_t - the size to create +/// \~english @retval 0 Success +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// None +/// \~english @par Change of internal state +/// None +/// \~english @par Conditions of processing failure +/// None +/// \~english @par Classification +/// Public +/// \~english @par Type +/// Sync +/// \~english @par Detail +/// None +/// \~english @see None +//////////////////////////////////////////////////////////////////////////////////// +cl_region_t *CL_RegionCreate(size_t size); // NOLINT(readability/nolint) + + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup Region +/// \~english @par Brief +/// Region destroy +/// \~english @param [in] region +/// cl_region_t * - the region to destroy +/// \~english @retval 0 Success +/// \~english @retval -1 Error +/// \~english @par Prerequisite +/// None +/// \~english @par Change of internal state +/// None +/// \~english @par Conditions of processing failure +/// None +/// \~english @par Classification +/// Public +/// \~english @par Type +/// Sync +/// \~english @par Detail +/// None +/// \~english @see None +//////////////////////////////////////////////////////////////////////////////////// +void CL_RegionDestroy(cl_region_t *region); // NOLINT(readability/nolint) + + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup Region +/// \~english @par Brief +/// Region allocation +/// \~english @param [in] region +/// cl_region_t * - the region to allocate +/// \~english @param [in] size +/// size_t * - the size to allocate +/// \~english @param [in] align_size +/// size_t * - the size to align +/// \~english @retval the pointer to region allocated +/// \~english @par Prerequisite +/// None +/// \~english @par Change of internal state +/// None +/// \~english @par Conditions of processing failure +/// None +/// \~english @par Classification +/// Public +/// \~english @par Type +/// Sync +/// \~english @par Detail +/// None +/// \~english @see None +//////////////////////////////////////////////////////////////////////////////////// +#define CL_RegionAlloc(region, type, length) \ + cl_region_alloc(region, sizeof(type) * length, CL_ALIGNOF(type)) +void *cl_region_alloc(cl_region_t *region, size_t size, size_t align_size); // NOLINT(readability/nolint) + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup Region +/// \~english @par Brief +/// Region free +/// \~english @param [in] region +/// cl_region_t * - the region to free +/// \~english @param [in] p +/// void * - the pointer to region +/// \~english @retval true Success +/// \~english @retval false Error +/// \~english @par Prerequisite +/// None +/// \~english @par Change of internal state +/// None +/// \~english @par Conditions of processing failure +/// None +/// \~english @par Classification +/// Public +/// \~english @par Type +/// Sync +/// \~english @par Detail +/// None +/// \~english @see None +//////////////////////////////////////////////////////////////////////////////////// +bool CL_RegionFree(cl_region_t *region, void *p); // NOLINT(readability/nolint) + + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup Region +/// \~english @par Brief +/// add region cleanup +/// \~english @param [in] region +/// cl_region_t * - the region to allocate +/// \~english @param [in] size +/// size_t * - the size to add +/// \~english @param [in] align_size +/// size_t * - the size to align +/// \~english @retval the pointer to region cleanup added +/// \~english @par Prerequisite +/// None +/// \~english @par Change of internal state +/// None +/// \~english @par Conditions of processing failure +/// None +/// \~english @par Classification +/// Public +/// \~english @par Type +/// Sync +/// \~english @par Detail +/// None +/// \~english @see None +//////////////////////////////////////////////////////////////////////////////////// +#define CL_RegionCleanupAdd(region, type, length) \ + cl_region_cleanup_add(region, sizeof(type) * length, CL_ALIGNOF(type)) +cl_region_cleanup_t *cl_region_cleanup_add(cl_region_t *region, size_t size, // NOLINT(readability/nolint) + size_t align_size); + +/** @}*/ // end of common_library +/** @}*/ // end of NativeService +/** @}*/ // end of BaseSystem +#ifdef __cplusplus +} +#endif + + +#endif /* _CL_REGION_H_ */ // NOLINT(build/header_guard) + +/* vim:set ts=8 sw=2 sts=2: */ diff --git a/nsframework/common_library/client/include/native_service/cl_sem.h b/nsframework/common_library/client/include/native_service/cl_sem.h new file mode 100644 index 00000000..9dbe54e4 --- /dev/null +++ b/nsframework/common_library/client/include/native_service/cl_sem.h @@ -0,0 +1,73 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * 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. + */ +#ifndef _cl_sem_h_ // NOLINT(build/header_guard) +#define _cl_sem_h_ // NOLINT(build/header_guard) + +#include <semaphore.h> + +#ifdef __cplusplus +#define EXT_C extern "C" +#else +#define EXT_C +#endif // __cplusplus + +/** + * @file cl_sem.h + * @brief \~english This file contains the api of sem wait. + */ + +/** @addtogroup BaseSystem + * @{ + */ +/** @addtogroup native_service + * @ingroup BaseSystem + * @{ + */ +/** @addtogroup common_library + * @ingroup native_service + * @{ + */ + +///////////////////////////////////////////////////////////////////////////////////// +/// \ingroup Sem +/// \~english @par Brief +/// Sem wait +/// \~english @param [in] semid +/// sem_t * - the pointer to the union sem_t +/// \~english @param [in] timeout +/// unsigned int - the count of timeout +/// \~english @retval 0 Success +/// \~english @retval not 0 Error +/// \~english @par Prerequisite +/// None +/// \~english @par Change of internal state +/// None +/// \~english @par Conditions of processing failure +/// None +/// \~english @par Classification +/// Public +/// \~english @par Type +/// Sync +/// \~english @par Detail +/// None +/// \~english @see None +//////////////////////////////////////////////////////////////////////////////////// +EXT_C int CL_SemWait(sem_t *semid, unsigned int timeout); // NOLINT(readability/nolint) + +/** @}*/ // end of common_library +/** @}*/ // end of NativeService +/** @}*/ // end of BaseSystem +#endif // #ifndef _cl_sem_h_ // NOLINT(build/header_guard) diff --git a/nsframework/common_library/client/include/native_service/common_library.h b/nsframework/common_library/client/include/native_service/common_library.h new file mode 100644 index 00000000..929d04d6 --- /dev/null +++ b/nsframework/common_library/client/include/native_service/common_library.h @@ -0,0 +1,48 @@ +// +// @copyright Copyright (c) 2017-2020 TOYOTA MOTOR CORPORATION. +// +// 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. +// +#ifndef NATIVESERVICE_COMMONLIBRARY_H_ // NOLINT(build/header_guard) +#define NATIVESERVICE_COMMONLIBRARY_H_ + +/** + * @file common_library.h + * @brief \~english include all common_library head files + */ + +/** @addtogroup BaseSystem + * @{ + */ +/** @addtogroup native_service + * @ingroup BaseSystem + * @{ + */ +/** @addtogroup common_library + * @ingroup native_service + * @{ + */ + +#include <native_service/cl_process.h> +#include <native_service/cl_sem.h> +#include <native_service/cl_monitor.h> +#include <native_service/cl_lock.h> +#include <native_service/cl_region.h> +#include <native_service/cl_lockid.h> + + +/** @}*/ // end of common_library +/** @}*/ // end of NativeService +/** @}*/ // end of BaseSystem + +#endif // NATIVESERVICE_COMMONLIBRARY_H_ |