4371605d479b35f3badd5433058552b5b5425216
[platform/upstream/dldt.git] / inference-engine / thirdparty / movidius / XLink / shared / src / XLinkStream.c
1 // Copyright (C) 2018-2020 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 #include <string.h>
6
7 #include "XLinkStream.h"
8 #include "XLinkErrorUtils.h"
9
10 #ifdef MVLOG_UNIT_NAME
11 #undef MVLOG_UNIT_NAME
12 #define MVLOG_UNIT_NAME xLink
13 #endif
14
15 #include "XLinkLog.h"
16 #include "XLinkStringUtils.h"
17
18 XLinkError_t XLinkStreamInitialize(
19     streamDesc_t* stream, streamId_t id, const char* name) {
20     mvLog(MVLOG_DEBUG, "name: %s, id: %ld\n", name, id);
21     ASSERT_XLINK(stream);
22
23     memset(stream, 0, sizeof(*stream));
24
25     if (sem_init(&stream->sem, 0, 0)) {
26         mvLog(MVLOG_ERROR, "Cannot initialize semaphore\n");
27         return X_LINK_ERROR;
28     }
29
30     stream->id = id;
31     mv_strncpy(stream->name, MAX_STREAM_NAME_LENGTH,
32                name, MAX_STREAM_NAME_LENGTH - 1);
33
34     return X_LINK_SUCCESS;
35 }
36
37 void XLinkStreamReset(streamDesc_t* stream) {
38     if(stream == NULL) {
39         return;
40     }
41
42     if(sem_destroy(&stream->sem)) {
43         mvLog(MVLOG_DEBUG, "Cannot destroy semaphore\n");
44     }
45
46     memset(stream, 0, sizeof(*stream));
47     stream->id = INVALID_STREAM_ID;
48 }