2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 /*---------------------------------------------------------------------------------*
24 *---------------------------------------------------------------------------------*/
26 #ifndef PT_PB_MUTEX_STUB__CWORD71_
28 #include <vehicle_service/positioning_base_library.h>
29 #include "_pbInternalProc.h"
30 #include <native_service/cl_lock.h>
31 #include <native_service/cl_lockid.h>
32 #include "WPF_STD_private.h"
35 /*---------------------------------------------------------------------------------*
37 *---------------------------------------------------------------------------------*/
38 /* Mutex control table name (Shared Memory) */
39 #define MUTEX_CTRL_TBL_NAME __TEXT("POS_BASE_MUTEX_TABLE")
42 Max. available Lock ID
43 Note : Lock ID application is 1 (for BaseAPI initialization) + 1 (for Mutex function control) + 30 (for provision) = 32
45 #define MAX_CTRL_MUTEX_NUM (30)
47 #define FULL_CTRL_MUTEX_NUM (MAX_CTRL_MUTEX_NUM - 4) /** Mutex control data threshold (no free) */
48 #define WARN_CTRL_MUTEX_NUM (MAX_CTRL_MUTEX_NUM - 10) /** Mutex control data threshold (warning) */
51 ID needs to be aplicated
53 If you increase or decrease the IDs, define maximum number of managed LOCK IDs and
54 the default setting of "Lock ID Resource List" must also be changed.
56 #define MUTEX_LOCK_ID_0 LOCK_POS_MTX_2 /* Mutex management-information-exclusive control */
57 #define MUTEX_LOCK_ID_1 LOCK_POS_MTX_3
58 #define MUTEX_LOCK_ID_2 LOCK_POS_MTX_4
59 #define MUTEX_LOCK_ID_3 LOCK_POS_MTX_5
60 #define MUTEX_LOCK_ID_4 LOCK_POS_MTX_6
61 #define MUTEX_LOCK_ID_5 LOCK_POS_MTX_7
62 #define MUTEX_LOCK_ID_6 LOCK_POS_MTX_8
63 #define MUTEX_LOCK_ID_7 LOCK_POS_MTX_9
64 #define MUTEX_LOCK_ID_8 LOCK_POS_MTX_10
65 #define MUTEX_LOCK_ID_9 LOCK_POS_MTX_11
66 #define MUTEX_LOCK_ID_10 LOCK_POS_MTX_12
67 #define MUTEX_LOCK_ID_11 LOCK_POS_MTX_13
68 #define MUTEX_LOCK_ID_12 LOCK_POS_MTX_14
69 #define MUTEX_LOCK_ID_13 LOCK_POS_MTX_15
70 #define MUTEX_LOCK_ID_14 LOCK_POS_MTX_16
71 #define MUTEX_LOCK_ID_15 LOCK_POS_MTX_17
72 #define MUTEX_LOCK_ID_16 LOCK_POS_MTX_18
73 #define MUTEX_LOCK_ID_17 LOCK_POS_MTX_19
74 #define MUTEX_LOCK_ID_18 LOCK_POS_MTX_20
75 #define MUTEX_LOCK_ID_19 LOCK_POS_MTX_21
76 #define MUTEX_LOCK_ID_20 LOCK_POS_MTX_22
77 #define MUTEX_LOCK_ID_21 LOCK_POS_MTX_23
78 #define MUTEX_LOCK_ID_22 LOCK_POS_MTX_24
79 #define MUTEX_LOCK_ID_23 LOCK_POS_MTX_25
80 #define MUTEX_LOCK_ID_24 LOCK_POS_MTX_26
81 #define MUTEX_LOCK_ID_25 LOCK_POS_MTX_27
82 #define MUTEX_LOCK_ID_26 LOCK_POS_MTX_28
83 #define MUTEX_LOCK_ID_27 LOCK_POS_MTX_29
84 #define MUTEX_LOCK_ID_28 LOCK_POS_MTX_30
85 #define MUTEX_LOCK_ID_29 LOCK_POS_MTX_31
86 #define MUTEX_LOCK_ID_30 LOCK_POS_MTX_32
88 typedef int32 LOCK_ID;
90 /*---------------------------------------------------------------------------------*
92 *---------------------------------------------------------------------------------*/
94 @brief Mutex control information(Interprocess common-details)
97 LOCK_ID lock_id; /**< Lock ID */
98 TCHAR name[NAME_MAX]; /**< Mutex Name */
99 int32 ref_cnt; /**< Reference Counter */
100 uint32_t thread_id; /**< Thread IDs while Lock is being acquired (Initial value:0) Note: For debugging */
101 BOOL is_rel_fail; /**< Release failure information (Failed:TRUE) Note: For debugging */
102 BOOL is_forbid_access; /**< Deletion occurred during Lock acquisition (Deletion occurred:TRUE) Note: For debugging */
103 } MUTEX_CTRL_SHARED_DETAIL;
106 @brief Mutex control information (Interprocess common)
109 MUTEX_CTRL_SHARED_DETAIL detail[MAX_CTRL_MUTEX_NUM]; /**< Common Infomation */
110 uint32_t use_cnt; /**< Use Counter */
111 uint32_t rsv_cnt; /**< Reserve Counter */
112 } MUTEX_CTRL_SHARED_INFO;
115 @brief Mutex control information
118 HANDLE handle[MAX_CTRL_MUTEX_NUM]; /**< Mutex Handle */
119 int32 ref_cnt[MAX_CTRL_MUTEX_NUM]; /**< Reference Counter */
120 MUTEX_CTRL_SHARED_INFO* info; /**< Common Infomation */
123 /*---------------------------------------------------------------------------------*
125 *---------------------------------------------------------------------------------*/
127 Mutex control table pointer (Partial shared memory)
128 Note: Access to this instance shall be made through the operation module.
130 static MUTEX_CTRL_INFO g_mutex_ctrl_tbl; // NOLINT(readability/nolint) global class instance
132 static HANDLE g_h_mtx; /** Mutex control-information-locking Mutex handle */
133 static HANDLE g_h_shm; /** Shared memory handle */ // Coverity CID: 18788 compliant
136 /** Lock ID Resource List */
137 static const LOCK_ID kLockIdList[MAX_CTRL_MUTEX_NUM] = {
171 Mutex property information (Information for each process)
172 _pb_CreateMutex calls -> 1
173 DeleteMutex calls -> 0
174 Only "1" can be used in the process.
176 BOOL g_is_mutex_owner_tbl[MAX_CTRL_MUTEX_NUM];
178 /*---------------------------------------------------------------------------------*
179 * Local Function Prototype *
180 *---------------------------------------------------------------------------------*/
181 /* Mutex Control Table Manipulation Functions */
182 static void MutexSetLockIdOfCtrlTbl(u_int32 idx, LOCK_ID l_id); /* Set Lock ID */
183 static LOCK_ID MutexGetLockIdOfCtrlTbl(u_int32 idx); /* Get Lock ID */
184 static void MutexSetMutexNameOfCtrlTbl(u_int32 idx, LPCTSTR name); /* Set Mutex name */
185 static void MutexSetMutexHandleOfCtrlTbl(u_int32 idx, HANDLE handle); /* Set Mutex handle */
186 static HANDLE MutexGetMutexHandleOfCtrlTbl(u_int32 idx); /* Get Mutex Handle */
187 static void MutexSetTidOfCtrlTbl(uint32_t idx, uint32_t tid); /* Set thread ID while Lock is being acquired */
188 static uint32_t MutexGetTidOfCtrlTbl(uint32_t idx); /* Get thread ID while Lock is being acquired */
189 static void MutexSetIsRelFailOfCtrlTbl(uint32_t idx, BOOL flag); /* Set release failure information */
190 static void MutexSetIsForbidAccessOfCtrlTbl(uint32_t idx, BOOL flag); /* Set deletion occurrence while Lock is being acquired */
191 static u_int32 MutexGetIdxOfCtrlTbl(HANDLE h_mutex); /* Get index for access */
192 static void MutexIncRefCntOfCtrlTbl(u_int32 idx); /* Increment Mutex reference counter */
193 static void MutexDecRefCntOfCtrlTbl(u_int32 idx); /* Decrement Mutex reference counter */
194 static int32 MutexGetRefCntOfCtrlTbl(u_int32 idx); /* Get Mutex reference counter */
195 static int32 MutexGetRefCntLocalOfCtrlTbl(u_int32 idx); /* Get mutex reference counter (in-process) */
196 static u_int32 MutexSearchNameOfCtrlTbl(LPCTSTR name); /* Search mutex name */
197 static u_int32 MutexSearchEmptyOfCtrlTbl(void); /* Search unused area */
198 static void MutexIncUseCntOfCtrlInfo(void); /* Increment Mutex using counter */
199 static void MutexDecUseCntOfCtrlInfo(void); /* Decrement Mutex using counter */
200 static void MutexIncRsvCntOfCtrlInfo(void); /* Increment Mutex reserved counter */
201 static void MutexDecRsvCntOfCtrlInfo(void); /* Decrement Mutex reserved counter */
203 /* Mutex ownership-information manipulation functions */
204 static void MutexSetFlagOfOwnerTbl(u_int32 idx, BOOL flag); /* Set ownership-information */
205 static BOOL MutexGetFlagOfOwnerTbl(u_int32 idx); /* Get ownership-information */
207 /* Mutex manipulation functions for accessing Mutex control tables */
208 static void MutexCreateMutex(void); /* Create Mutex */
209 static void MutexLockMutex(void); /* Get Mutex */
210 static void MutexUnlockMutex(void); /* Release Mutex */
211 static void MutexDeleteMutex(void); /* Delete Mutex */
213 /*---------------------------------------------------------------------------------*
215 *---------------------------------------------------------------------------------*/
218 * Initialize the mutex function
220 * Call the in-process initialization API for locking between processes that provide CLS.<br>
221 * Create shared memory for a Mutex control table.<br>
222 * Create a mutex for accessing Mutex control info.<br>
223 * If an error occurs during internal processing of this API, subsequent normal operations cannot be performed, so call _pb_Exit().
227 RET_API MutexInit(void) {
228 RET_API ret_api = RET_NORMAL;
229 MUTEX_CTRL_SHARED_INFO **pp_tbl;
232 memset(g_mutex_ctrl_tbl.handle, 0, sizeof(g_mutex_ctrl_tbl.handle));
233 memset(g_mutex_ctrl_tbl.ref_cnt, 0, sizeof(g_mutex_ctrl_tbl.ref_cnt));
235 /* Set pointer to Mutex control table */
236 pp_tbl = &(g_mutex_ctrl_tbl.info);
238 MutexCreateMutex(); /* Create Mutex for accessing Mutex control info */
240 MutexLockMutex(); /* Get Mutex for accessing Mutex control info */
242 /* Open the Mutex control table shared memory */
243 g_h_shm = OpenSharedMemory((TCHAR*)(MUTEX_CTRL_TBL_NAME), // NOLINT(readability/casting)
244 sizeof(MUTEX_CTRL_SHARED_INFO));
246 /* If called for the first time within all processes, an error occurs and the following processing is performed. */
247 if (g_h_shm == NULL) { // LCOV_EXCL_BR_LINE 200: can not be other val
248 /* Create shared memory for Mutex control table */
249 // LCOV_EXCL_BR_LINE 200: can not return NULL
250 g_h_shm = CreateSharedMemory((TCHAR*)MUTEX_CTRL_TBL_NAME, // NOLINT(readability/casting)
251 sizeof(MUTEX_CTRL_SHARED_INFO));
252 if (g_h_shm == NULL) /* In case of an error */ { // LCOV_EXCL_BR_LINE 200: can not return NULL
253 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "_pb_CreateShareData ERROR [hShm:%p]", g_h_shm);
254 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
255 _pb_Exit(); // LCOV_EXCL_LINE 200: cannot return NULL
256 /* don't arrive here. */
260 MutexUnlockMutex(); /* Release of Mutex for accessing Mutex control info */
262 /* Set addresses of the acquired shared memory as a pointer of the Mutex control table. */
263 *pp_tbl = reinterpret_cast<MUTEX_CTRL_SHARED_INFO*>(GetSharedMemoryPtr(g_h_shm));
265 /* Initialize various information of control table */
266 for (idx = 0; idx < MAX_CTRL_MUTEX_NUM; idx++) {
267 /* Set Lock ID in Mutex control table(Overwrite from the second process onwards) */
268 MutexSetLockIdOfCtrlTbl(idx, kLockIdList[idx]);
270 MutexSetFlagOfOwnerTbl(idx, FALSE);
280 RET_API MutexTerm(void) { // LCOV_EXCL_START 8:dead code
281 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
282 RET_API ret_api = RET_NORMAL;
284 CloseSharedMemory(g_h_shm);
296 * Create a named mutex that can be locked between processes.
298 * @param[in] lp_mutex_attributes Security descriptor(Unused)
299 * @param[in] b_initial_owner Initial owner flag(Unused)
300 * @param[in] lp_name Mutex name
302 * @return Except NULL Handle of the created mutex (Management information pointer)<br>
305 HANDLE _pb_CreateMutex(LPSECURITY_ATTRIBUTES lp_mutex_attributes, // NOLINT(readability/nolint) WPF_SYSAPI.h API
306 BOOL b_initial_owner, LPCTSTR lp_name) {
307 int32 idx; /* For accessing Mutex control table */
308 HANDLE h_mutex = NULL; /* Mutex handle */
315 if (lp_name == NULL) {
316 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR!!");
318 len = _tcslen(lp_name);
319 if (len >= NAME_MAX) {
320 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR!! " \
321 "Length of mutex name is too long(>=%d). [len:%zu]", NAME_MAX, len);
323 MutexLockMutex(); /* Get Mutex for accessing Mutex control info */
325 /* Retrieve whether the specified mutex name exists in the Mutex control table */
326 idx = MutexSearchNameOfCtrlTbl(lp_name);
328 /* Already assigned */
329 if (idx != MAX_CTRL_MUTEX_NUM) {
330 /* Get mutex handle from Mutex control table */
331 h_mutex = MutexGetMutexHandleOfCtrlTbl(idx);
333 /* First-time creation within a process */
334 if (h_mutex == NULL) {
336 lock_id = MutexGetLockIdOfCtrlTbl(idx);
338 /* Lock information mapping (CLS) */
339 p_addr = CL_LockMap(lock_id); // LCOV_EXCL_BR_LINE 4: nsfw error
340 /* In case of an error */
341 if (p_addr == MAP_FAILED) { // LCOV_EXCL_BR_LINE 4: nsfw error
342 /* Output an error log and return an error value */
343 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, \
344 "CL_LockMap ERROR!! [p_addr:%p, errno:%d]", p_addr, errno);
346 /* Successful allocation */
347 /* Set Mutex handle in the mutex management table */
348 MutexSetMutexHandleOfCtrlTbl(idx, (HANDLE)p_addr);
350 h_mutex = (HANDLE)p_addr;
354 if (h_mutex != NULL) { // LCOV_EXCL_BR_LINE 200: h_mutex can not be NULL
355 /* Increment Mutex reference counter */
356 MutexIncRefCntOfCtrlTbl(idx);
358 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__,
359 "### MUTEX TABLE INFORMATION # (+) idx:%d HANDLE:%p, " \
360 "ref_cnt:%d, LOCK_ID:%d, NAME:%s, ref_cnt:%d, tid:%d, fail:%d, forbid:%d",
362 g_mutex_ctrl_tbl.handle[idx],
363 g_mutex_ctrl_tbl.ref_cnt[idx],
364 g_mutex_ctrl_tbl.info->detail[idx].lock_id,
365 g_mutex_ctrl_tbl.info->detail[idx].name,
366 g_mutex_ctrl_tbl.info->detail[idx].ref_cnt,
367 g_mutex_ctrl_tbl.info->detail[idx].thread_id,
368 g_mutex_ctrl_tbl.info->detail[idx].is_rel_fail,
369 g_mutex_ctrl_tbl.info->detail[idx].is_forbid_access);
372 /* For a new assignment */
373 /* Get the free space in the mutex management table. */
374 idx = MutexSearchEmptyOfCtrlTbl();
377 lock_id = MutexGetLockIdOfCtrlTbl(idx);
379 /* Lock information mapping (CLS) */
380 p_addr = CL_LockMap(lock_id);
382 /* In case of an error */
383 if (p_addr == MAP_FAILED) { // LCOV_EXCL_BR_LINE 4: nsfw error
384 /* Output an error log and return an error value. */
385 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "CL_LockMap ERROR!! " \
386 "[p_addr:%p, errno:%d] In _pb_CreateMutex", p_addr, errno);
388 /* Successful allocation */
389 /* Set Mutex Hanlde in the mutex management table */
390 MutexSetMutexHandleOfCtrlTbl(idx, (HANDLE)p_addr);
392 /* Set the mutex name in the mutex management table */
393 MutexSetMutexNameOfCtrlTbl(idx, lp_name);
395 /* Increment Mutex reference counter */
396 MutexIncRefCntOfCtrlTbl(idx);
398 /* Increment mutex using counter */
399 MutexIncUseCntOfCtrlInfo();
401 h_mutex = (HANDLE)p_addr;
403 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__,
404 "### MUTEX TABLE INFORMATION # (++) idx:%d HANDLE:%p, ref_cnt:%d, " \
405 "LOCK_ID:%d, NAME:%s, ref_cnt:%d, tid:%d, fail:%d, forbid:%d",
407 g_mutex_ctrl_tbl.handle[idx],
408 g_mutex_ctrl_tbl.ref_cnt[idx],
409 g_mutex_ctrl_tbl.info->detail[idx].lock_id,
410 g_mutex_ctrl_tbl.info->detail[idx].name,
411 g_mutex_ctrl_tbl.info->detail[idx].ref_cnt,
412 g_mutex_ctrl_tbl.info->detail[idx].thread_id,
413 g_mutex_ctrl_tbl.info->detail[idx].is_rel_fail,
414 g_mutex_ctrl_tbl.info->detail[idx].is_forbid_access);
418 if (h_mutex != NULL) { // LCOV_EXCL_BR_LINE 200: can not be NULL
419 /* Update Mutex ownership */
420 MutexSetFlagOfOwnerTbl(idx, TRUE);
423 /* Release the Mutex for accessing Mutex control info */
435 * Decrement the Mutex reference counter and delete it when it reaches zero.
437 * @param[in] h_mutex Mutex handle (CreateMutex return value)
439 * @return WAIT_OBJECT_0 Normal completion<br>
442 DWORD PbDeleteMutex(HANDLE h_mutex) {
443 DWORD lret = WAIT_OBJECT_0;
451 if (h_mutex == NULL) { // LCOV_EXCL_BR_LINE 6: h_mutex cannot be NULL
452 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argment ERROR");
453 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
454 lret = WAIT_FAILED; /* ABEND */ // LCOV_EXCL_LINE 6: h_mutex cannot be NULL
456 MutexLockMutex(); /* Get Mutex for accessing Mutex control info */
458 /* Retrieve the index of the management table containing the Mutex handles */
459 idx = MutexGetIdxOfCtrlTbl(h_mutex);
460 /* When the specified Mutex handle is not registered */
461 if (idx == MAX_CTRL_MUTEX_NUM) { // LCOV_EXCL_BR_LINE 200: idx can no be MAX_CTRL_MUTEX_NUM
462 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__, "Argment ERROR [h_mutex:%p]", h_mutex);
463 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
464 lret = WAIT_FAILED; /* ABEND */ // LCOV_EXCL_LINE 200: idx can no be MAX_CTRL_MUTEX_NUM
466 /* If it is registered */
467 /* Determinate its ownership */
468 is_owner = MutexGetFlagOfOwnerTbl(idx);
469 if (is_owner == TRUE) {
470 /* Get Mutex reference counter */
471 ref_cnt = MutexGetRefCntOfCtrlTbl(idx);
473 /* No clients are using the specified Mutex. */
474 if ((ref_cnt - 1) <= 0) {
475 /* Lock information unmapping (CLS) */
476 ret = CL_LockUnmap(reinterpret_cast<void*>(h_mutex)); // LCOV_EXCL_BR_LINE 4: nsfw error
477 /* When an error occurs */
478 if (ret == -1) { // LCOV_EXCL_BR_LINE 4: nsfw error
479 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "CL_LockUnmap ERROR");
480 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
481 lret = WAIT_FAILED; /* ABEND */ // LCOV_EXCL_LINE 4: nsfw error
484 /* Remove Mutex hanlde from Mutex control table */
485 MutexSetMutexHandleOfCtrlTbl(idx, NULL);
487 /* Delete the mutex name from the Mutex control table */
488 MutexSetMutexNameOfCtrlTbl(idx, "");
490 /* Update Mutex ownership */
491 MutexSetFlagOfOwnerTbl(idx, FALSE);
493 /* Decrement Mutex reference counter */
494 MutexDecRefCntOfCtrlTbl(idx);
496 /* Decrement mutex using counter */
497 MutexDecUseCntOfCtrlInfo();
499 tid = MutexGetTidOfCtrlTbl(idx);
500 if (tid != 0) { // LCOV_EXCL_BR_LINE 200: tid can not be 0
501 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
502 MutexSetIsForbidAccessOfCtrlTbl(idx, TRUE); // LCOV_EXCL_LINE 200: tid can not be 0
505 /* Initialize debug information */
506 MutexSetTidOfCtrlTbl(idx, 0);
507 MutexSetIsRelFailOfCtrlTbl(idx, FALSE);
509 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__,
510 "### MUTEX TABLE INFORMATION # (--) idx:%d HANDLE:%p, ref_cnt(local):%d, " \
511 "LOCK_ID:%d, NAME:%s, ref_cnt:%d, tid:%d, fail:%d, forbid:%d",
513 g_mutex_ctrl_tbl.handle[idx],
514 g_mutex_ctrl_tbl.ref_cnt[idx],
515 g_mutex_ctrl_tbl.info->detail[idx].lock_id,
516 g_mutex_ctrl_tbl.info->detail[idx].name,
517 g_mutex_ctrl_tbl.info->detail[idx].ref_cnt,
518 g_mutex_ctrl_tbl.info->detail[idx].thread_id,
519 g_mutex_ctrl_tbl.info->detail[idx].is_rel_fail,
520 g_mutex_ctrl_tbl.info->detail[idx].is_forbid_access);
524 /* Determine if any clients are referencing in the process */
525 ref_cnt = MutexGetRefCntLocalOfCtrlTbl(idx);
526 if ((ref_cnt - 1) <= 0) { // LCOV_EXCL_BR_LINE 200: ref_cnt can not bigger than 1
527 // LCOV_EXCL_START 200: ref_cnt can not bigger than 1
528 //AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
529 /* Lock information unmapping (CLS) */
530 ret = CL_LockUnmap(reinterpret_cast<void*>(h_mutex));
531 /* When an error occurs */
533 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "CL_LockUnmap ERROR");
534 lret = WAIT_FAILED; /* ABEND */
537 /* Remove Mutex Hanlde from the Mutex control table */
538 MutexSetMutexHandleOfCtrlTbl(idx, NULL);
540 /* Update Mutex ownership */
541 MutexSetFlagOfOwnerTbl(idx, FALSE);
546 if (lret == WAIT_OBJECT_0) {
547 /* Decrement Mutex refernce counter */
548 MutexDecRefCntOfCtrlTbl(idx);
550 FRAMEWORKUNIFIEDLOG(ZONE_20, __FUNCTION__,
551 "### MUTEX TABLE INFORMATION # (-) idx:%d HANDLE:%p, ref_cnt(local):%d, " \
552 "LOCK_ID:%d, NAME:%s, ref_cnt:%d, tid:%d, fail:%d, forbid:%d",
554 g_mutex_ctrl_tbl.handle[idx],
555 g_mutex_ctrl_tbl.ref_cnt[idx],
556 g_mutex_ctrl_tbl.info->detail[idx].lock_id,
557 g_mutex_ctrl_tbl.info->detail[idx].name,
558 g_mutex_ctrl_tbl.info->detail[idx].ref_cnt,
559 g_mutex_ctrl_tbl.info->detail[idx].thread_id,
560 g_mutex_ctrl_tbl.info->detail[idx].is_rel_fail,
561 g_mutex_ctrl_tbl.info->detail[idx].is_forbid_access);
565 } else { // LCOV_EXCL_BR_LINE 200: is_owner can not be FALSE
566 /* If it is not the owner */
567 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
568 lret = WAIT_FAILED; // LCOV_EXCL_LINE 200: is_owner can not be FALSE
572 MutexUnlockMutex(); /* Release of Mutex for accessing Mutex control info */
582 * Take ownership of the mutex and start locking.
584 * @param[in] h_mutex Mutex handle(CreateMutex return value)
585 * @param[in] timeout Timeout (Millisecond)
587 * @return WAIT_OBJECT_0 Succeeded to get ownership<br>
588 * WAIT_TIMEOUT Failed to get ownership (Timeout)<br>
589 * WAIT_FAILED Failed to get ownership (Error)
591 DWORD PbMutexLock(HANDLE h_mutex, DWORD timeout) {
592 DWORD lret = WAIT_OBJECT_0;
594 DWORD time_out_cnt = 0;
600 if (h_mutex == NULL) { // LCOV_EXCL_BR_LINE 6: h_mutex cannot be NULL
601 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argment ERROR");
602 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
603 lret = WAIT_FAILED; /* ABEND */ // LCOV_EXCL_LINE 6: h_mutex cannot be NULL
605 /* Retrieve the index of the management table containing the Mutex handles */
606 idx = MutexGetIdxOfCtrlTbl(h_mutex);
607 /* When the specified Mutex handle is not registered */
608 if (idx == MAX_CTRL_MUTEX_NUM) { // LCOV_EXCL_BR_LINE 6: idx cannot be MAX_CTRL_MUTEX_NUM
609 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argment ERROR [h_mutex:%p, idx:%d]", \
611 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
612 lret = WAIT_FAILED; /* ABEND */ // LCOV_EXCL_LINE 6: idx cannot be MAX_CTRL_MUTEX_NUM
614 /* If it is registered */
615 /* Determinate ownership */
616 is_owner = MutexGetFlagOfOwnerTbl(idx);
617 if (is_owner == TRUE) {
620 /* No timeout specified */
621 if (timeout == INFINITE) { // LCOV_EXCL_BR_LINE 6: timeout will not be other case
623 ret = CL_LockGet(reinterpret_cast<void*>(h_mutex)); // LCOV_EXCL_BR_LINE 4: nsfw error
624 if (ret != 0) /* In case of ABEND */ { // LCOV_EXCL_BR_LINE 4: nsfw error
625 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, \
626 "CL_LockGet ERROR [h_mutex:%p, ret:%d]", h_mutex, ret);
627 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
628 lret = WAIT_FAILED; /* ABEND */ // LCOV_EXCL_LINE 4: nsfw error
630 /* Set thread ID during lock */
631 MutexSetTidOfCtrlTbl(idx, tid);
634 // LCOV_EXCL_START 6: timeout will not be other case
635 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
636 /* Timeout specified */
639 ret = CL_LockNowait(reinterpret_cast<void*>(h_mutex));
640 if (ret != 0) /* In case of ABEND */ {
641 /* Invalid parameter */
643 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, \
644 "CL_LockGet ERROR [h_mutex:%p, ret:%d]", h_mutex, ret);
645 lret = WAIT_FAILED; /* ABEND */
650 if (time_out_cnt <= timeout) {
658 /* Successful acquisition */
659 /* Set thread ID during lock */
660 MutexSetTidOfCtrlTbl(idx, tid);
667 } else { // LCOV_EXCL_BR_LINE 200: is_owner can not be FALSE
668 /* If it is not the owner */
669 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
670 lret = WAIT_FAILED; // LCOV_EXCL_LINE 200: is_owner can not be FALSE
682 * Release the mutex ownership and terminate the lock.
684 * @param[in] h_mutex Mutex handle(CreateMutex return value)
686 * @return TURE Normal<br>
689 BOOL PbMutexUnlock(HANDLE h_mutex) {
697 if (h_mutex == NULL) { // LCOV_EXCL_BR_LINE 6: h_mutex can not be NULL
698 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argment ERROR");
700 /* Retrieve the index of the management table containing the Mutex handle */
701 idx = MutexGetIdxOfCtrlTbl(h_mutex);
702 /* When the specified Mutex handle is not registered */
703 if (idx == MAX_CTRL_MUTEX_NUM) { // LCOV_EXCL_BR_LINE 200: idx can not be MAX_CTRL_MUTEX_NUM
704 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, \
705 "MutexGetIdxOfCtrlTbl ERROR [h_mutex:%p, idx:%d]", h_mutex, idx);
707 /* If it is registered */
708 /* Determinate ownership */
709 is_owner = MutexGetFlagOfOwnerTbl(idx);
710 if (is_owner == TRUE) { // LCOV_EXCL_BR_LINE 4: nsfw error
711 /* Release thread ID setting during lock */
712 MutexSetTidOfCtrlTbl(idx, 0);
714 /* Release the Lock */
715 ret = CL_LockRelease(reinterpret_cast<void*>(h_mutex));
716 if (ret == 0) /* If successful */ { // LCOV_EXCL_BR_LINE 4: nsfw error
719 } else { // LCOV_EXCL_BR_LINE 4: nsfw error
720 // LCOV_EXCL_START 4: nsfw error
721 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
725 /* Retry to set the thread ID during lock */
726 MutexSetTidOfCtrlTbl(idx, tid);
728 /* Add the release failure information */
729 MutexSetIsRelFailOfCtrlTbl(idx, TRUE);
731 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, \
732 "CL_LockRelease ERROR [h_mutex:%p, ret:%d]", h_mutex, ret);
742 /*---------------------------------------------------------------------------------*
744 *---------------------------------------------------------------------------------*/
747 * Set the Lock ID (Mutex control table)
749 * If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
751 * @param[in] idx Control table accessor
752 * @param[in] l_id Lock ID
754 static void MutexSetLockIdOfCtrlTbl(u_int32 idx, LOCK_ID l_id) {
756 if (idx >= MAX_CTRL_MUTEX_NUM) { // LCOV_EXCL_BR_LINE 6: idx cannot greater
758 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argment ERROR [idx:%d, l_id:%d]", idx, l_id);
759 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
760 _pb_Exit(); // LCOV_EXCL_LINE 6: idx cannot greater
761 /* don't arrive here. */
763 g_mutex_ctrl_tbl.info->detail[idx].lock_id = l_id;
771 * Get the Lock ID (Mutex control table)
773 * If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
775 * @param[in] idx Control table accessor
777 static LOCK_ID MutexGetLockIdOfCtrlTbl(u_int32 idx) {
779 if (idx >= MAX_CTRL_MUTEX_NUM) { // LCOV_EXCL_BR_LINE 6: idx cannot greater
781 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argment ERROR [idx:%d]", idx);
782 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
783 _pb_Exit(); // LCOV_EXCL_LINE 6: idx cannot greater
784 /* don't arrive here. */
787 return g_mutex_ctrl_tbl.info->detail[idx].lock_id;
792 * Set the Mutex name (Mutex control table)
794 * If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
796 * @param[in] idx Control table accessor
797 * @param[in] name Mutex name
799 static void MutexSetMutexNameOfCtrlTbl(u_int32 idx, LPCTSTR name) {
801 if (idx >= MAX_CTRL_MUTEX_NUM) { // LCOV_EXCL_BR_LINE 6: idx cannot greater
803 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argment ERROR [idx:%d, name:%s]", idx, name);
804 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
805 _pb_Exit(); // LCOV_EXCL_LINE 6: idx cannot greater
806 /* don't arrive here. */
808 _tcscpy(g_mutex_ctrl_tbl.info->detail[idx].name, name);
816 * Set the Mutex handle (Mutex control table)
818 * If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
820 * @param[in] idx Control table accessor
821 * @param[in] handle Mutex handle
823 static void MutexSetMutexHandleOfCtrlTbl(u_int32 idx, HANDLE handle) {
825 if (idx >= MAX_CTRL_MUTEX_NUM) { // LCOV_EXCL_BR_LINE 6: idx cannot greater
827 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argment ERROR [idx:%d, handle:%p]", idx, handle);
828 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
829 _pb_Exit(); // LCOV_EXCL_LINE 6: idx cannot greater
830 /* don't arrive here. */
832 g_mutex_ctrl_tbl.handle[idx] = handle;
840 * Get the Mutex handle (Mutex control table)
842 * If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
844 * @param[in] idx Control table accessor
846 * @return Mutex handle
848 static HANDLE MutexGetMutexHandleOfCtrlTbl(u_int32 idx) {
849 HANDLE handle = NULL;
852 if (idx >= MAX_CTRL_MUTEX_NUM) { // LCOV_EXCL_BR_LINE 6: idx cannot greater
854 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argment ERROR [idx:%d]", idx);
855 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
856 _pb_Exit(); // LCOV_EXCL_LINE 6: idx cannot greater
857 /* don't arrive here. */
859 handle = g_mutex_ctrl_tbl.handle[idx];
867 * Set the thread ID during lock acquisition (Mutex control table)
869 * @param[in] idx Control table accessor
870 * @param[in] tid Thread ID
871 * @note If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
873 static void MutexSetTidOfCtrlTbl(uint32_t idx, uint32_t tid) {
875 if (idx >= MAX_CTRL_MUTEX_NUM) { // LCOV_EXCL_BR_LINE 6: idx cannot greater
877 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR [idx:%d]", idx);
878 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
879 _pb_Exit(); // LCOV_EXCL_LINE 6: idx cannot greater
880 /* don't arrive here. */
882 g_mutex_ctrl_tbl.info->detail[idx].thread_id = tid;
891 * Get the thread ID during lock acquisition (Mutex control table)
893 * @param[in] idx Control table accessor
897 * @note If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
899 static uint32_t MutexGetTidOfCtrlTbl(uint32_t idx) {
903 if (idx >= MAX_CTRL_MUTEX_NUM) { // LCOV_EXCL_BR_LINE 6: idx cannot greater
905 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR [idx:%d]", idx);
906 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
907 _pb_Exit(); // LCOV_EXCL_LINE 6: idx cannot greater
908 /* don't arrive here. */
910 tid = g_mutex_ctrl_tbl.info->detail[idx].thread_id;
919 * Set the release failure information (Mutex control table)
921 * @param[in] idx Control table accessor
922 * @param[in] flag Failed to release:TURE
923 * @note If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
925 static void MutexSetIsRelFailOfCtrlTbl(uint32_t idx, BOOL flag) {
927 if (idx >= MAX_CTRL_MUTEX_NUM) { // LCOV_EXCL_BR_LINE 6: idx cannot greater
929 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR [idx:%d]", idx);
930 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
931 _pb_Exit(); // LCOV_EXCL_LINE 6: idx cannot greater
932 /* don't arrive here. */
934 g_mutex_ctrl_tbl.info->detail[idx].is_rel_fail = flag;
942 * Set deletion-occurrence information during Lock acquisition (Mutex control table)
944 * @param[in] idx Control table accessor
945 * @param[in] flag When deletion occurs while Lock is being acquired:TRUE
946 * @note If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
948 static void MutexSetIsForbidAccessOfCtrlTbl(uint32_t idx, BOOL flag) { // LCOV_EXCL_START 8:dead code
949 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
951 if (idx >= MAX_CTRL_MUTEX_NUM) { // LCOV_EXCL_BR_LINE 6: idx cannot greater
953 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argument ERROR [idx:%d]", idx);
954 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
955 _pb_Exit(); // LCOV_EXCL_LINE 6: idx cannot greater
956 /* don't arrive here. */
958 g_mutex_ctrl_tbl.info->detail[idx].is_forbid_access = flag;
967 * Get index for access (Mutex control table)
969 * Return the index for accessing the area of the Mutex control table in which <br>
970 * the specified mutex handle is registered. If the specified handle is not <br>
971 * registered, the maximum number of mutex management (MAX_MUTEX_CTRL_NUM) is returned.
973 * @param[in] h_mutex Mutex handle
975 * @return Index for access (Specified handle is already registered)<br>
976 * Maximum mutex management value (Specified handle is not registered)
978 static u_int32 MutexGetIdxOfCtrlTbl(HANDLE h_mutex) {
982 for (idx = 0; idx < MAX_CTRL_MUTEX_NUM; idx++) {
983 /* Get handle from Mutex control table */
984 handle = MutexGetMutexHandleOfCtrlTbl(idx);
986 if (handle == h_mutex) {
996 * Increment the Mutex reference counter (Mutex control table)
998 * If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
1000 * @param[in] idx Control table accessor
1002 static void MutexIncRefCntOfCtrlTbl(u_int32 idx) {
1004 if (idx >= MAX_CTRL_MUTEX_NUM) { // LCOV_EXCL_BR_LINE 6: idx cannot greater
1006 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argment ERROR [idx:%d]", idx);
1007 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1008 _pb_Exit(); // LCOV_EXCL_LINE 6: idx cannot greater
1009 /* don't arrive here. */
1012 g_mutex_ctrl_tbl.info->detail[idx].ref_cnt++;
1013 g_mutex_ctrl_tbl.ref_cnt[idx]++;
1020 * Decrement the Mutex reference counter (Mutex control table)
1022 * If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
1024 * @param[in] idx Control table accessor
1026 static void MutexDecRefCntOfCtrlTbl(u_int32 idx) {
1028 if (idx >= MAX_CTRL_MUTEX_NUM) { // LCOV_EXCL_BR_LINE 6: idx cannot greater
1030 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argment ERROR [idx:%d]", idx);
1031 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1032 _pb_Exit(); // LCOV_EXCL_LINE 6: idx cannot greater
1033 /* don't arrive here. */
1036 g_mutex_ctrl_tbl.info->detail[idx].ref_cnt--;
1037 g_mutex_ctrl_tbl.ref_cnt[idx]--;
1044 * Get the Mutex Reference Counter (Mutex control table)
1046 * If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
1048 * @param[in] idx Control table accessor
1050 * @return Reference counter value
1052 static int32 MutexGetRefCntOfCtrlTbl(u_int32 idx) {
1056 if (idx >= MAX_CTRL_MUTEX_NUM) { // LCOV_EXCL_BR_LINE 6: idx cannot greater
1058 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argment ERROR [idx:%d]", idx);
1059 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1060 _pb_Exit(); // LCOV_EXCL_LINE 6: idx cannot greater
1061 /* don't arrive here. */
1063 ret = g_mutex_ctrl_tbl.info->detail[idx].ref_cnt;
1071 * Get mutex reference counter (in-process)(Mutex control table)
1073 * If an invalid value is specified for an argument, the system assumes that it is a design problem and calls _pb_Exit().
1075 * @param[in] idx Control table accessor
1077 * @return Reference counter value
1079 static int32 MutexGetRefCntLocalOfCtrlTbl(u_int32 idx) {
1081 if (idx >= MAX_CTRL_MUTEX_NUM) { // LCOV_EXCL_BR_LINE 6: idx cannot greater
1083 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argment ERROR [idx:%d]", idx);
1084 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1085 _pb_Exit(); // LCOV_EXCL_LINE 6: idx cannot greater
1086 /* don't arrive here. */
1089 return g_mutex_ctrl_tbl.ref_cnt[idx];
1094 * Search mutex name (Mutex control table)
1096 * Retrieve whether the specified mutex is already registered in the Mutex control table.<br>
1097 * If it is registered, the access index is returned.If it is not registered,<br>
1098 * return the maximum mutex management value(MAX_CTRL_MUTEX_NUM).
1100 * @param[in] name Mutex name
1102 * @return Index for access(If it is registered)<br>
1103 * Maximum mutex management value (Not registered)
1105 static u_int32 MutexSearchNameOfCtrlTbl(LPCTSTR name) {
1109 for (idx = 0; idx < MAX_CTRL_MUTEX_NUM; idx++) {
1110 ret = _tcscmp(g_mutex_ctrl_tbl.info->detail[idx].name, name);
1112 /* If there is a match */
1123 * Search unused area (Mutex control table)
1125 * Return the lowest-numbered index for accessing unused space in the Mutex control table.<br>
1126 * Return the maximum value((MAX_CTRL_MUTEX_NUM)) of message queue management <br>
1127 * when no unused area exists.
1129 * @return Index for access (Unused area exists)<br>
1130 * Maximum mutex management value (No unused area)
1132 static u_int32 MutexSearchEmptyOfCtrlTbl(void) {
1135 idx = MutexSearchNameOfCtrlTbl("");
1142 * Set the Mutex ownership flag (Ownership-information table)
1144 * @param[in] idx Control table accessor
1145 * @param[in] flag ownership-information
1147 static void MutexSetFlagOfOwnerTbl(u_int32 idx, BOOL flag) {
1149 if (idx >= MAX_CTRL_MUTEX_NUM) { // LCOV_EXCL_BR_LINE 6: idx cannot greater
1151 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argment ERROR [idx:%d, flag:%d]", idx, flag);
1152 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1153 _pb_Exit(); // LCOV_EXCL_LINE 6: idx cannot greater
1154 /* don't arrive here. */
1156 g_is_mutex_owner_tbl[idx] = flag;
1164 * Get the Mutex ownership flag (Ownership-information table)
1166 * @param[in] idx Control table accessor
1168 * @return TRUE Owned
1171 static BOOL MutexGetFlagOfOwnerTbl(u_int32 idx) {
1175 if (idx >= MAX_CTRL_MUTEX_NUM) { // LCOV_EXCL_BR_LINE 6: idx cannot greater
1177 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Argment ERROR [idx:%d]", idx);
1178 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1179 _pb_Exit(); // LCOV_EXCL_LINE 6: idx cannot greater
1180 /* don't arrive here. */
1182 bret = g_is_mutex_owner_tbl[idx];
1190 * Create Mutex for accessing the Mutex control table
1192 static void MutexCreateMutex(void) {
1193 g_h_mtx = (HANDLE)CL_LockMap(MUTEX_LOCK_ID_0); // LCOV_EXCL_BR_LINE 4: nsfw error
1194 if (g_h_mtx == NULL) { // LCOV_EXCL_BR_LINE 4: nsfw error
1195 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "CL_LockMap ERROR [g_h_mtx:%p]", g_h_mtx);
1196 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1197 _pb_Exit(); // LCOV_EXCL_LINE 4: nsfw error
1198 /* don't arrive here. */
1206 * Delete Mutex for accessing Mutex control table
1208 static void MutexDeleteMutex(void) { // LCOV_EXCL_START 8:dead code
1209 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1212 ret = CL_LockUnmap(g_h_mtx);
1214 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, \
1215 "CL_LockUnmap ERROR [g_h_mtx:%p, ret:%d]", g_h_mtx, ret);
1217 /* don't arrive here. */
1226 * Get Mutex for accessing Mutex control table
1228 static void MutexLockMutex(void) {
1231 ret = CL_LockGet(g_h_mtx); // LCOV_EXCL_BR_LINE 4: nsfw error
1232 if (ret != 0) { // LCOV_EXCL_BR_LINE 4: nsfw error
1233 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, \
1234 "CL_LockGet ERROR [g_h_mtx:%p, ret:%d]", g_h_mtx, ret);
1235 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1236 _pb_Exit(); // LCOV_EXCL_LINE 4: nsfw error
1237 /* don't arrive here. */
1245 * Release Mutex for accessing Mutex control table
1247 static void MutexUnlockMutex(void) {
1250 ret = CL_LockRelease(g_h_mtx); // LCOV_EXCL_BR_LINE 4: nsfw error
1251 if (ret != 0) { // LCOV_EXCL_BR_LINE 4: nsfw error
1252 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, \
1253 "CL_LockRelease ERROR [g_h_mtx:%p, ret:%d]", g_h_mtx, ret);
1254 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1255 _pb_Exit(); // LCOV_EXCL_LINE 4: nsfw error
1256 /* don't arrive here. */
1264 * Get dump information
1266 * @param[out] p_buf Dump info
1267 * @param[in/out] p_len Buffer size
1269 void _pb_GetDebugMutexMngTbl(void* p_buf, uint8_t* p_len) {
1270 static uint8_t buf[DEBUG_DUMP_MAX_SIZE];
1271 static uint8_t buf_tmp[512];
1272 static uint8_t buf_info[DEBUG_DUMP_MAX_SIZE];
1276 if ((p_buf != NULL) && (p_len != NULL)) {
1277 memset(&buf[0], 0x00, sizeof(buf));
1278 memset(&buf_info[0], 0x00, sizeof(buf_info));
1279 for (i = 0; i < MAX_CTRL_MUTEX_NUM; i++) {
1280 memset(&buf_tmp[0], 0x00, sizeof(buf_tmp));
1281 snprintf(reinterpret_cast<char *>(&buf_tmp[0]), sizeof(buf_tmp),
1282 "\n [%02d]id:%10d, nm:%40s, ref_cnt:%10d, tid:%03d, fail:%01d, " \
1283 "forbid:%01d, handle:%10p, ref_cnt(local):%10d",
1285 g_mutex_ctrl_tbl.info->detail[i].lock_id,
1286 g_mutex_ctrl_tbl.info->detail[i].name,
1287 g_mutex_ctrl_tbl.info->detail[i].ref_cnt,
1288 g_mutex_ctrl_tbl.info->detail[i].thread_id,
1289 g_mutex_ctrl_tbl.info->detail[i].is_rel_fail,
1290 g_mutex_ctrl_tbl.info->detail[i].is_forbid_access,
1291 g_mutex_ctrl_tbl.handle[i],
1292 g_mutex_ctrl_tbl.ref_cnt[i]);
1293 strncat(reinterpret_cast<char *>(&buf_info[0]), reinterpret_cast<char *>(&buf_tmp[0]), \
1294 strlen(reinterpret_cast<char *>(&buf_tmp[0])));
1295 if (((i + 1) % 10) == 0) {
1297 memset(&buf[0], 0x00, sizeof(buf));
1298 snprintf(reinterpret_cast<char *>(&buf[0]), sizeof(buf),
1302 memcpy(p_buf, &buf[0], sizeof(buf));
1303 p_buf = reinterpret_cast<void *>((reinterpret_cast<uint8_t *>(p_buf)) + sizeof(buf));
1304 memset(&buf_info[0], 0x00, sizeof(buf_info));
1305 if (cnt >= *p_len) {
1311 if (buf_info[0] != 0x00) {
1313 memset(&buf[0], 0x00, sizeof(buf));
1314 snprintf(reinterpret_cast<char *>(&buf[0]), sizeof(buf),
1318 memcpy(p_buf, &buf[0], sizeof(buf));
1327 * Increment the Mutex using counter
1331 static void MutexIncUseCntOfCtrlInfo(void) {
1332 g_mutex_ctrl_tbl.info->use_cnt++;
1338 * Decrement Mutex using counter
1342 static void MutexDecUseCntOfCtrlInfo(void) {
1343 g_mutex_ctrl_tbl.info->use_cnt--;
1349 * Increment Mutex reserved counter
1353 static void MutexIncRsvCntOfCtrlInfo(void) {
1354 g_mutex_ctrl_tbl.info->rsv_cnt++;
1360 * Decrement Mutex reserved counter
1364 static void MutexDecRsvCntOfCtrlInfo(void) {
1365 g_mutex_ctrl_tbl.info->rsv_cnt--;
1371 * Determine resources ready (Mutex control data)
1376 * @retval TRUE : Normal
1377 * @retval FALSE : Error (Resource shortage)
1379 BOOL _pb_GetMutexResource(void) {
1385 /* Increment Mutex reserved counter */
1386 MutexIncRsvCntOfCtrlInfo();
1388 cnt = g_mutex_ctrl_tbl.info->use_cnt + g_mutex_ctrl_tbl.info->rsv_cnt;
1389 if (cnt >= FULL_CTRL_MUTEX_NUM) {
1391 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, \
1392 "Lack of resources [FATAL][use_cnt:%d rsv_cnt:%d]", g_mutex_ctrl_tbl.info->use_cnt, \
1393 g_mutex_ctrl_tbl.info->rsv_cnt);
1394 } else if (cnt >= WARN_CTRL_MUTEX_NUM) {
1395 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, \
1396 "Lack of resources [WARN][use_cnt:%d rsv_cnt:%d]", g_mutex_ctrl_tbl.info->use_cnt, \
1397 g_mutex_ctrl_tbl.info->rsv_cnt);
1407 * Release resources (Mutex control data)
1413 void _pb_ReleaseMutexResource(void) {
1416 /* Decrement Mutex reserved counter */
1417 MutexDecRsvCntOfCtrlInfo();
1423 #endif /* PT_PB_MUTEX_STUB__CWORD71_ */