xref: /freebsd/sys/dev/qat/qat_api/qat_utils/src/QatUtilsSpinLock.c (revision 2e3507c25e42292b45a5482e116d278f5515d04d)
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
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
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
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
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