summaryrefslogtreecommitdiff
path: root/test/regression/interoperability_test/test_frame/tls_test_semaphore_create.c
blob: eee9b35bbb2dc2338778081787e50d95918ebc9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/***************************************************************************/
/* Copyright (c) 2024 Microsoft Corporation                                */
/* Copyright (c) 2026 Eclipse ThreadX contributors                         */
/*                                                                         */
/* This program and the accompanying materials are made available under    */
/* the terms of the MIT License which is available at                      */
/* https://opensource.org/licenses/MIT.                                    */
/*                                                                         */
/* SPDX-License-Identifier: MIT                                            */
/***************************************************************************/

#include "tls_test_frame.h"

/* Create semaphore. */
INT tls_test_semaphore_create( TLS_TEST_SEMAPHORE** semaphore_ptr_ptr, UINT initial_value)
{
    INT status;
    TLS_TEST_SEMAPHORE* semaphore_ptr = *semaphore_ptr_ptr;
    semaphore_ptr = mmap( NULL, sizeof(TLS_TEST_SEMAPHORE), PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, 0, 0);
    return_value_if_fail( NULL != semaphore_ptr, TLS_TEST_UNABLE_TO_CREATE_SHARED_MEMORY);

    status = sem_init( semaphore_ptr, 1, initial_value);
    if ( -1 == status)
    {
        munmap( semaphore_ptr, sizeof(TLS_TEST_SEMAPHORE));
    }
    return_value_if_fail( -1 != status, TLS_TEST_SYSTEM_CALL_FAILED);

    *semaphore_ptr_ptr = semaphore_ptr;
    return TLS_TEST_SUCCESS;
}