xref: /freebsd/sys/dev/qat/qat_api/qat_utils/src/QatUtilsSpinLock.c (revision 71625ec9ad2a9bc8c09784fbd23b759830e0ee5f)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright(c) 2007-2022 Intel Corporation */
3 #include "qat_utils.h"
4 #include <sys/sx.h>
5 
6 CpaStatus
qatUtilsLockInit(struct mtx * pLock)7 qatUtilsLockInit(struct mtx *pLock)
8 {
9 	if (!pLock)
10 		return CPA_STATUS_FAIL;
11 	memset(pLock, 0, sizeof(*pLock));
12 	mtx_init(pLock, "qat spin", NULL, MTX_DEF | MTX_DUPOK);
13 
14 	return CPA_STATUS_SUCCESS;
15 }
16 
17 CpaStatus
qatUtilsLock(struct mtx * pLock)18 qatUtilsLock(struct mtx *pLock)
19 {
20 	if (!pLock)
21 		return CPA_STATUS_FAIL;
22 	mtx_lock(pLock);
23 
24 	return CPA_STATUS_SUCCESS;
25 }
26 
27 CpaStatus
qatUtilsUnlock(struct mtx * pLock)28 qatUtilsUnlock(struct mtx *pLock)
29 {
30 	if (!pLock)
31 		return CPA_STATUS_FAIL;
32 	mtx_unlock(pLock);
33 
34 	return CPA_STATUS_SUCCESS;
35 }
36 
37 CpaStatus
qatUtilsLockDestroy(struct mtx * pLock)38 qatUtilsLockDestroy(struct mtx *pLock)
39 {
40 	if (!pLock)
41 		return CPA_STATUS_FAIL;
42 	mtx_destroy(pLock);
43 	return CPA_STATUS_SUCCESS;
44 }
45