# Operating System Abstraction (OSA)

## Attribute

Definitions for OSA attributes.

Enums

- enum sns\_osa\_mem\_type

    - Memory type.

*Values:*

- enumerator SNS\_OSA\_MEM\_TYPE\_NORMAL

    - Non island memory.

- enumerator SNS\_OSA\_MEM\_TYPE\_ISLAND

    - Island memory.

- enumerator SNS\_OSA\_MEM\_TYPE\_ISLAND\_SSC

    - Island SSC memory.

- enumerator SNS\_OSA\_MEM\_TYPE\_MAX

    -

## Interrupt service routine (ISR)

OS Abstraction layer for interrupt service routine for Sensors.

Functions

- sns\_rc sns\_osa\_isr\_register (int int\_num, char const \*thread\_name, sns\_mem\_heap\_id heap, sns\_osa\_isr\_func isr, sns\_osa\_isr\_func\_arg isr\_arg) \_\_attribute\_\_((nonnull(2

    - Registers ISR for the given interrupt number.

Note

New thread may be created if not found

- Parameters:

    - - **int\_num** – **[in]** Interrupt number.
- **thread\_name** – **[in]** Name of IST
- **heap** – **[in]** Which heap to allocate thread stack from
- **isr** – **[in]** The ISR to register.
- **isr\_arg** – **[in]** First argument passed to the ISR.

- Returns:

    - - SNS\_RC\_SUCCESS: Successfully registered the ISR for the interrupt.
- SNS\_RC\_INVALID\_VALUE: Invalid thread name
- SNS\_RC\_INVALID\_STATE: Interrupt is already registered.
- SNS\_RC\_NOT\_AVAILABLE: Interrupt not configured.
- SNS\_RC\_NOT\_SUPPORTED: This feature is disabled.

- sns\_rc sns\_rc sns\_osa\_isr\_deregister (int int\_num, char const \*thread\_name) \_\_attribute\_\_((nonnull(2)))

    - Deregisters the given interrupt number.

- Parameters:

    - - **int\_num** – **[in]** Interrupt number.
- **thread\_name** – **[in]** Name of IST given in [sns\_osa\_isr\_register()](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#sns__osa__isr_8h_1ac358bd7e23baf3e5139b2bbba6d4a3f6)

- Returns:

    - - SNS\_RC\_SUCCESS: Successfully deregistered the interrupt.
- SNS\_RC\_INVALID\_STATE: Interrupt is not registered.
- SNS\_RC\_NOT\_AVAILABLE: IST is processing an interrupt.

## Lock

OS Abstraction layer for locking mechanism used in Sensors.

- union sns\_osa\_lock

    - OS dependent locking mechanism.

Public Members

- char \_\_size[\_\_SIZEOF\_LOCK]

    - 

- long int \_\_alignment

    -

- union sns\_osa\_lock\_attr

    - OS dependent lock attributes.

Public Members

- char \_\_size[\_\_SIZEOF\_ATTR\_LOCK]

    - 

- long int \_\_alignment

    -

Functions

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_osa\_lock\_attr\_init([sns\_osa\_lock\_attr](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv417sns_osa_lock_attr) \*attrib) \_\_attribute\_\_((nonnull))

    - Initializes the given lock attribute structure with defaults.

- Parameters:

    - **attrib** – **[inout]** The attribute structure.

- Returns:

    - - SNS\_RC\_SUCCESS: Attribute structure initialized.
- SNS\_RC\_INVALID\_VALUE: Input parameter is invalid.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_osa\_lock\_attr\_set\_memory\_partition([sns\_osa\_lock\_attr](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv417sns_osa_lock_attr) \*attrib, [sns\_osa\_mem\_type](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv416sns_osa_mem_type) mem\_type) \_\_attribute\_\_((nonnull))

    - Specifies the memory type where the lock will be located.

- Parameters:

    - - **attrib** – **[inout]** The attribute structure.
- **mem\_type** – **[in]** The memory type.

- Returns:

    - - SNS\_RC\_SUCCESS: Memory partition attribute set.
- SNS\_RC\_NOT\_SUPPORTED: Memory partition attribute is not supported.
- SNS\_RC\_INVALID\_VALUE: One or more input parameters are invalid.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_osa\_lock\_create(const [sns\_osa\_lock\_attr](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv417sns_osa_lock_attr) \*attrib, [sns\_osa\_lock](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv412sns_osa_lock) \*\*lock) \_\_attribute\_\_((nonnull))

    - Allocates memory for a new lock and initializes it.

- Parameters:

    - - **attrib** – **[in]** The initialized attribute structure.
- **lock** – **[out]** Destination for the newly created lock.

- Returns:

    - - SNS\_RC\_SUCCESS: New lock successfully created.
- SNS\_RC\_NOT\_AVAILABLE: No memory.
- SNS\_RC\_INVALID\_VALUE: One or more input pointers are NULL.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_osa\_lock\_init(const [sns\_osa\_lock\_attr](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv417sns_osa_lock_attr) \*attrib, [sns\_osa\_lock](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv412sns_osa_lock) \*lock) \_\_attribute\_\_((nonnull))

    - Initializes the given lock.

- Parameters:

    - - **attrib** – **[in]** The initialized attribute structure.
- **lock** – **[inout]** The lock to initialize.

- Return values:

    - **SNS\_RC\_SUCCESS** – New lock successfully initialized.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_osa\_lock\_delete([sns\_osa\_lock](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv412sns_osa_lock) \*lock)

    - Deinit the given lock and free the memory.

- Parameters:

    - **lock** – **[in]** The lock to deinitialize.

- Returns:

    - - SNS\_RC\_SUCCESS: The given lock deleted.
- SNS\_RC\_INVALID\_VALUE: Not a valid lock.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_osa\_lock\_deinit([sns\_osa\_lock](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv412sns_osa_lock) \*lock)

    - Deinit the given lock.

- Parameters:

    - **lock** – **[in]** The lock to deinitialize.

- Returns:

    - - SNS\_RC\_SUCCESS: The given lock deleted
- SNS\_RC\_INVALID\_VALUE: Not a valid lock

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_osa\_lock\_acquire([sns\_osa\_lock](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv412sns_osa_lock) \*lock)

    - Acquires the given lock.

Note

Blocks until lock is acquired

- Parameters:

    - **lock** – **[in]** The lock.

- Returns:

    - - SNS\_RC\_SUCCESS: The given lock acquired
- SNS\_RC\_INVALID\_VALUE: Not a valid lock

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_osa\_lock\_try\_acquire([sns\_osa\_lock](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv412sns_osa_lock) \*lock)

    - Tries to acquires the given lock.

Note

Returns immediately if lock cannot be acquired.

- Parameters:

    - **lock** – **[in]** The lock.

- Returns:

    - - SNS\_RC\_SUCCESS: The given lock acquired.
- SNS\_RC\_NOT\_AVAILABLE: Unable to acquire lock.
- SNS\_RC\_INVALID\_VALUE: Not a valid lock.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_osa\_lock\_release([sns\_osa\_lock](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv412sns_osa_lock) \*lock)

    - Releases the given lock.

- Parameters:

    - **lock** – **[in]** The lock.

- Returns:

    - - SNS\_RC\_SUCCESS: The given lock released.
- SNS\_RC\_INVALID\_VALUE: Not a valid lock.

## Semaphore

OS Abstraction layer for semaphores used in Sensors.

- union sns\_osa\_sem\_attr

    - OS dependent semaphore attributes.

Public Members

- char \_\_size[\_\_SIZEOF\_ATTR\_SEM]

    - Size of the structure.

- long int \_\_alignment

    -

Functions

- void sns\_osa\_sem\_attr\_init([sns\_osa\_sem\_attr](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv416sns_osa_sem_attr) \*attrib) \_\_attribute\_\_((nonnull))

    - Creates a semaphore attribute structure initialized with defaults.

- Parameters:

    - **attrib** – **[inout]** The attribute structure.

- Returns:

    - - None.

- void sns\_osa\_sem\_attr\_set\_value([sns\_osa\_sem\_attr](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv416sns_osa_sem_attr) \*attrib, int32\_t value) \_\_attribute\_\_((nonnull))

    - Sets the semaphore initial value.

- Parameters:

    - - **attrib** – **[inout]** The attribute structure.
- **value** – **[in]** Initial value.

- Returns:

    - - None.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_osa\_sem\_attr\_set\_memory\_partition([sns\_osa\_sem\_attr](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv416sns_osa_sem_attr) \*attrib, [sns\_osa\_mem\_type](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv416sns_osa_mem_type) mem\_type) \_\_attribute\_\_((nonnull))

    - Specifies the memory type where the semaphore will be located.

- Parameters:

    - - **attrib** – **[inout]** The attribute structure.
- **mem\_type** – **[in]** The memory type.

- Returns:

    - - SNS\_RC\_SUCCESS: Memory partition attribute set.
- SNS\_RC\_NOT\_SUPPORTED: Memory partition attribute is not supported.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_osa\_sem\_create(const [sns\_osa\_sem\_attr](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv416sns_osa_sem_attr) \*attrib, sns\_osa\_sem \*\*sem) \_\_attribute\_\_((nonnull))

    - Creates a new semaphore.

- Parameters:

    - - **attrib** – **[in]** Semaphore attribute.
- **sem** – **[out]** Destination for the newly created semaphore.

- Returns:

    - - SNS\_RC\_SUCCESS: New semaphore successfully created.
- SNS\_RC\_NOT\_AVAILABLE: No memory available in the specified region.

- void sns\_osa\_sem\_delete(sns\_osa\_sem \*\*sem) \_\_attribute\_\_((nonnull))

    - Deletes the given semaphore.

- Parameters:

    - **sem** – **[inout]** The semaphore.

- Returns:

    - - None.

- void sns\_osa\_sem\_wait(sns\_osa\_sem \*sem) \_\_attribute\_\_((nonnull))

    - Waits on the given semaphore.

Note

Blocks until semaphore value is greater than or equal to 0.

- Parameters:

    - **sem** – **[in]** The semaphore.

- Returns:

    - - None.

- void sns\_osa\_sem\_post(sns\_osa\_sem \*sem) \_\_attribute\_\_((nonnull))

    - Increments value of the given semaphore and wakes any threads waiting on this semaphore.

- Parameters:

    - **sem** – **[in]** The semaphore.

- Returns:

    - - None.

- int32\_t sns\_osa\_sem\_get\_value(sns\_osa\_sem \*sem) \_\_attribute\_\_((nonnull))

    - Gets the semaphore count value.

- Parameters:

    - **sem** – **[in]** The semaphore

- Returns:

    - - int32\_t: Semaphore count value.
- -1: If given semaphore is invalid

## Thread

OS Abstraction layer for threads used in Sensors.

Defines

- SNS\_OSA\_THREAD\_NAME\_MAX\_LEN

    - Excluding terminating NULL.

- SNS\_OSA\_THREAD\_EXIT\_SIG

    - Reserved MSB for exit.

- union sns\_osa\_thread\_attr

    - Opaque structure for OS dependent thread attribute.

Public Members

- char \_\_size[\_\_SIZEOF\_ATTR\_THREAD]

    - Size of attr.

- long int \_\_alignment

    -

- struct sns\_thread\_map

    - Structure which stores worker thread id and maps it to array index.

Public Members

- int32\_t thread\_id

    - Thread identifier.

Functions

- void sns\_osa\_thread\_attr\_init([sns\_osa\_thread\_attr](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv419sns_osa_thread_attr) \*attrib) \_\_attribute\_\_((nonnull))

    - Creates a thread attribute structure initialized with defaults.

- Parameters:

    - **attrib** – **[inout]** The attribute structure.

- Returns:

    - - None.

- void sns\_osa\_thread\_attr\_set\_stack([sns\_osa\_thread\_attr](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv419sns_osa_thread_attr) \*attrib, uintptr\_t stack\_start, size\_t stack\_size) \_\_attribute\_\_((nonnull(1)))

    - Sets the thread stack.

- Parameters:

    - - **attrib** – **[inout]** The attribute structure.
- **stack\_start** – **[in]** Start of the preallocated stack; if NULL, stack will be allocated from heap
- **stack\_size** – **[in]** Stack size in bytes.

- Returns:

    - - None.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_osa\_thread\_attr\_set\_kernel\_stack\_size([sns\_osa\_thread\_attr](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv419sns_osa_thread_attr) \*attrib, size\_t kernel\_stack\_size) \_\_attribute\_\_((nonnull))

    - Sets the kernel stack size attribute for island threads.

Note

This has no effect on big-image threads. Default kernal stack size is 2k.

- Parameters:

    - - **attrib** – **[inout]** The attribute structure.
- **kernel\_stack\_size** – **[in]** Stack size in bytes.

- Returns:

    - - SNS\_RC\_SUCCESS: Stack attribute set.
- SNS\_RC\_NOT\_SUPPORTED: The current OS doesn’t support this.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_osa\_thread\_attr\_set\_priority([sns\_osa\_thread\_attr](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv419sns_osa_thread_attr) \*attrib, uint8\_t priority) \_\_attribute\_\_((nonnull))

    - Sets the thread priority attribute.

- Parameters:

    - - **attrib** – **[inout]** The attribute structure.
- **priority** – **[in]** Thread priority.

- Returns:

    - - SNS\_RC\_SUCCESS: Priority attribute set.
- SNS\_RC\_NOT\_SUPPORTED: Priority attribute is not supported.
- SNS\_RC\_INVALID\_VALUE: The given priority is invalid.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_osa\_thread\_attr\_set\_name([sns\_osa\_thread\_attr](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv419sns_osa_thread_attr) \*attrib, const char \*name) \_\_attribute\_\_((nonnull))

    - Sets the thread name attribute.

- Parameters:

    - - **attrib** – **[inout]** The attribute structure.
- **name** – **[in]** Name.

- Returns:

    - - SNS\_RC\_SUCCESS: Name attribute set.
- SNS\_RC\_INVALID\_VALUE: The given priority is invalid.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_osa\_thread\_attr\_set\_memory\_partition([sns\_osa\_thread\_attr](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv419sns_osa_thread_attr) \*attrib, [sns\_osa\_mem\_type](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv416sns_osa_mem_type) mem\_type) \_\_attribute\_\_((nonnull))

    - Specifies the memory type where the thread will be located.

- Parameters:

    - - **attrib** – **[inout]** The attribute structure.
- **mem\_type** – **[in]** The memory type.

- Returns:

    - - SNS\_RC\_SUCCESS: Memory partition attribute set.
- SNS\_RC\_NOT\_SUPPORTED: Memory partition attribute is not supported.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_osa\_thread\_attr\_set\_user\_info([sns\_osa\_thread\_attr](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv419sns_osa_thread_attr) \*attrib, void \*info) \_\_attribute\_\_((nonnull(1)))

    - Assigns user defined information to be stored with a thread.

- Parameters:

    - - **attrib** – **[inout]** The attribute structure.
- **info** – **[in]** The user defined info associated with thread.

- Returns:

    - - SNS\_RC\_SUCCESS: User data was set.
- SNS\_RC\_NOT\_SUPPORTED: User data attribute is not supported.

- sns\_rc sns\_osa\_thread\_create (sns\_osa\_thread\_func thread\_func, sns\_osa\_thread\_func\_arg thread\_func\_arg, const sns\_osa\_thread\_attr \*attrib, sns\_osa\_thread \*\*thread) \_\_attribute\_\_((nonnull(1

    - Creates a new thread.

- Parameters:

    - - **thread\_func** – **[in]** Thread main function.
- **thread\_func\_arg** – **[in]** Input parameter to thread\_func.
- **attrib** – **[in]** The initialized attribute structure.
- **thread** – **[out]** Destination for the newly created thread.

- Returns:

    - - SNS\_RC\_SUCCESS: New thread successfully created.
- SNS\_RC\_RESOURCE\_UNAVAIL: No memory.

- sns\_rc sns\_rc sns\_osa\_thread\_create\_v2 (char \*thread\_name, sns\_osa\_thread\_func thread\_func, sns\_osa\_thread\_func\_arg thread\_func\_arg, sns\_osa\_thread \*\*thread) \_\_attribute\_\_((nonnull(1

    - Creates a new thread.

Note

Prerequisite to call this API: Update thread configuration in

”/ssc/utils/osa/chipset/${CHIPSET}/sns\_thread\_table.c”

”/ssc/inc/internal/${CHIPSET}/sns\_thread\_table.h”

This API populates thread attribute configuration from the sns\_thread\_table.

- Parameters:

    - - **thread\_name** – **[in]** Name for the thread. (Up to SNS\_OSATHREAD\_NAME\_MAX\_LEN characters)
- **thread\_func** – **[in]** Thread main function.
- **thread\_func\_arg** – **[in]** Input parameter to thread\_func.
- **thread** – **[out]** Destination for the newly created thread.

- Returns:

    - - SNS\_RC\_SUCCESS: New thread successfully created.
- SNS\_RC\_NOT\_AVAILABLE: If thread entry missing in the sns\_thread\_table.

- sns\_rc sns\_rc sns\_rc sns\_osa\_thread\_delete (sns\_osa\_thread \*thread)

    - Deletes the given thread.

- Parameters:

    - **thread** – **[in]** The thread to delete.

- Returns:

    - - SNS\_RC\_SUCCESS: Given thread deleted.
- SNS\_RC\_INVALID\_VALUE: Given thread not found.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_osa\_thread\_sigs\_wait(sns\_osa\_thread\_sigs sigs\_mask, sns\_osa\_thread\_sigs \*sigs\_rcvd, sns\_osa\_thread \*thread)

    - Waits for the given signals in the given thread.

Note

The received signals are consumed.

- Parameters:

    - - **sigs\_mask** – **[in]** The signals for which to wait.
- **sigs\_rcvd** – **[out]** Destination for signals set when thread wokeup.
- **thread** – **[in]** Thread pointer of the thread calling this function.

- Returns:

    - - SNS\_RC\_SUCCESS: One or more signals received.
- SNS\_RC\_INVALID\_VALUE: One or more input parameters are invalid.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_osa\_thread\_sigs\_set(sns\_osa\_thread \*thread, sns\_osa\_thread\_sigs sigs)

    - Sets the given signals to wake up the given thread.

- Parameters:

    - - **thread** – **[in]** The thread.
- **sigs** – **[in]** The signals to set.

- Returns:

    - - SNS\_RC\_SUCCESS: Signals set.
- SNS\_RC\_INVALID\_VALUE: One or more input parameters are invalid.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_osa\_thread\_sigs\_check(sns\_osa\_thread\_sigs sigs\_mask, bool consume, sns\_osa\_thread\_sigs \*sigs\_rcvd)

    - Checks the currently running thread for any pending signals.

- Parameters:

    - - **sigs\_mask** – **[in]** The signals for which to check.
- **consume** – **[in]** Whether to consume/clear the signals.
- **sigs\_rcvd** – **[out]** Destination for pending signals.

- Returns:

    - - SNS\_RC\_SUCCESS: One or more signals received.
- SNS\_RC\_INVALID\_VALUE: One or more input parameters are invalid.

- uint8\_t sns\_osa\_thread\_get\_priority(void)

    - Returns the current thread’s priority.

- Returns:

    - - uint8\_t: The current thread’s priority.

- uint8\_t sns\_osa\_thread\_set\_priority(uint8\_t priority)

    - Sets the current thread’s priority to the given priority.

- Parameters:

    - **priority** – **[in]** The priority to set.

- Returns:

    - - uint8\_t: The priority before it was changed.

- void \*sns\_osa\_thread\_get\_user\_info(void)

    - Gets the user defined information that was stored with current thread.

- Returns:

    - - Pointer to user defined information if user information was set.
- NULL: Otherwise.

- int sns\_osa\_thread\_get\_thread\_id(void)

    - Gets the thread id of the currently running thread.

- Returns:

    - - int: Thread ID.

- int sns\_osa\_thread\_get\_thread\_id\_by\_name(char \*thread\_name) \_\_attribute\_\_((nonnull))

    - Gets the thread id of the thread whose name is *thread\_name*.

- Parameters:

    - **thread\_name** – **[in]** Name of the thread.

- Returns:

    - - int: Thread id if found.
- -1: Otherwise.

- int sns\_osa\_thread\_get\_process\_id(void)

    - Gets the process id of the current thread.

- Returns:

    - - int: Process ID.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_osa\_init(void)

    - Initializes all OSA global state.

- Returns:

    - - SNS\_RC\_SUCCESS: On success.
- SNS\_RC\_FAILED: Otherwise.

- void sns\_osa\_thread\_active(struct [sns\_watchdog\_voter](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv418sns_watchdog_voter) \*wd\_voter)

    - Marks the currently running thread as active.

- Parameters:

    - **wd\_voter** – **[in]** Watchdog voter.

- Returns:

    - - None.

- void sns\_osa\_thread\_idle(struct [sns\_watchdog\_voter](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv418sns_watchdog_voter) \*wd\_voter)

    - Marks the currently running thread as idle.

- Parameters:

    - **wd\_voter** – **[in]** Watchdog voter.

- Returns:

    - - None.

- uint64\_t sns\_osa\_thread\_get\_active\_to\_idle\_transitions\_count(void)

    - Returns count of how many times all threads went to idle.

- Returns:

    - - uint64\_t: Active-to-idle transition count.

- sns\_osa\_thread \*sns\_osa\_get\_current\_thread(void)

    - Gets the currently running thread.

- Returns:

    - - sns\_osa\_thread: The currently running thread.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_osa\_thread\_sigs\_wait\_wrapper(sns\_osa\_thread\_sigs sigs\_mask, sns\_osa\_thread\_sigs \*sigs\_rcvd, sns\_osa\_thread \*thread)

    - Wrapper function for [sns\_osa\_thread\_sigs\_wait()](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#sns__osa__thread_8h_1a58c4f05ce9a75133c961658be9e75587). This function calls [sns\_osa\_thread\_idle()](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#sns__osa__thread_8h_1a0b4dc15dbef75dbf9e6a1c7d4cd7ff9c) before waiting on signals and calls [sns\_osa\_thread\_active()](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#sns__osa__thread_8h_1a532b5b4b92599dad344364e15983fb05) once the signal wait is completed.

- Parameters:

    - - **sigs\_mask** – **[in]** The signals for which to wait.
- **sigs\_rcvd** – **[out]** Destination for signals set when thread woke up.
- **thread** – **[in]** The thread calling this function.

- Returns:

    - - SNS\_RC\_SUCCESS: One or more signals received.
- SNS\_RC\_INVALID\_VALUE: One or more input parameters are invalid.

- unsigned int sns\_osa\_thread\_anysignal\_wait\_wrapper([sns\_osa\_thread\_signal](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv421sns_osa_thread_signal) \*signal, unsigned int mask, struct [sns\_watchdog\_voter](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv418sns_watchdog_voter) \*wd\_voter)

    - Wrapper function for [sns\_osa\_thread\_signal\_wait()](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#sns__osa__thread__signal_8h_1a39a5605c62cffd344b4bfa67c5b09b43). This function calls [sns\_osa\_thread\_idle()](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#sns__osa__thread_8h_1a0b4dc15dbef75dbf9e6a1c7d4cd7ff9c) before waiting on signals and calls [sns\_osa\_thread\_active()](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#sns__osa__thread_8h_1a532b5b4b92599dad344364e15983fb05) once the signal wait is completed.

- Parameters:

    - - **signal** – **[in]** Pointer to the signal instance.
- **mask** – **[in]** The signals for which to wait.
- **wd\_voter** – **[in]** Watchdog voter.

- Returns:

    - - int: Received signals.

- struct [sns\_thread\_utilization](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv422sns_thread_utilization) \*sns\_osa\_thread\_get\_thread\_utilization\_item(sns\_osa\_thread \*thread)

    - Gets a pointer to the thread utilization item.

- Parameters:

    - **thread** – **[in]** The thread.

- Returns:

    - - [sns\_thread\_utilization](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structsns__thread__utilization): The thread utilization item.

- [sns\_rc](https://docs.qualcomm.com/doc/80-P9361-100/topic/sensor_api.html#_CPPv46sns_rc) sns\_osa\_thread\_update\_worker\_thread\_map(sns\_osa\_thread \*thread, uint8\_t index)

    - Adds a thread id to worker thread map.

Note

This function only works on low priority threads.

- Parameters:

    - - **thread** – **[in]** The thread.
- **index** – **[in]** The thread index for the thread.

- Returns:

    - - SNS\_RC\_SUCCESS: Thread id was added to map.
- SNS\_RC\_INVALID\_VALUE: Index parameter is invalid.

- int8\_t sns\_osa\_thread\_get\_worker\_thread\_index(void)

    - Gets the thread map index from current running thread.

- Returns:

    - - int8\_t: The thread map index.

- struct [sns\_watchdog\_voter](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#_CPPv418sns_watchdog_voter) \*sns\_osa\_thread\_get\_wd\_voter(sns\_osa\_thread \*thread)

    - Gets the watchdog voter for given thread.

- Parameters:

    - **thread** – **[in]** The thread.

- Returns:

    - - [sns\_watchdog\_voter](https://docs.qualcomm.com/doc/80-P9361-100/topic/fwutils.html#structsns__watchdog__voter): Pointer to the watchdog voter for the given thread.

- [sns\_osa\_thread\_signal](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv421sns_osa_thread_signal) \*sns\_osa\_thread\_get\_thread\_signal(sns\_osa\_thread \*thread)

    - Gets the thread signal for given thread.

- Parameters:

    - **thread** – **[in]** The thread.

- Returns:

    - - [sns\_osa\_thread\_signal](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#unionsns__osa__thread__signal): Pointer to the thread signal for the given thread.

- uint32\_t sns\_osa\_get\_active\_threads\_count(void)

    - Gets the count of currently active ssc threads.

- Returns:

    - - uint32\_t: Number of active ssc threads.

- void sns\_osa\_acquire\_active\_threads\_count\_lock(void)

    - Acquires active threads count lock.

- Returns:

    - - None.

- void sns\_osa\_release\_active\_threads\_count\_lock(void)

    - Releases active threads count lock.

- Returns:

    - - None.

- uint32\_t sns\_osa\_thread\_get\_hardware\_thread\_count(void)

    - Gets number of hardware threads.

- Returns:

    - Number of hardware threads. 0 if not supported.

This file contains the sensors thread stack size definitions.

Defines

- SNS\_THREAD\_DEFAULT\_KERNEL\_STACK\_SIZE

    - Default Stack size.

- SNS\_SIG\_THREAD\_STACK\_SIZE

    - Stack size for signal thread.

- SNS\_SIG\_THREAD\_KERNEL\_STACK\_SIZE

    - Stack size for signal thread kernel stack size.

- SNS\_SIG\_SENSOR\_THREAD\_STACK\_SIZE

    - Stack size for signal sensor thread.

- SNS\_SIG\_SENSOR\_THREAD\_KERNEL\_STACK\_SIZE

    - Stack size for signal sensor thread kernel stack size.

This file contains sensor thread configuration.

Defines

- SNS\_THREAD\_PRIO\_LO\_TIMEOUT\_SEC

    - Number of seconds low priority threads can run at a stretch.

- SNS\_THREAD\_PRIO\_HI\_TIMEOUT\_SEC

    - Number of seconds high priority threads can run at a stretch.

## Thread Signal

OS Abstraction layer for thread signaling mechanism.

- union sns\_osa\_thread\_signal

    - OS dependent signaling mechanism.

Public Members

- char \_\_size[\_\_SIZEOF\_SIGNAL]

    - Signal size.

- long int \_\_alignment

    -

Functions

- void sns\_osa\_thread\_signal\_init([sns\_osa\_thread\_signal](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv421sns_osa_thread_signal) \*sig) \_\_attribute\_\_((nonnull))

    - Initializes the given signal object.

- Parameters:

    - **sig** – **[out]** The signal object to be initialized.

- Returns:

    - - None.

- void sns\_osa\_thread\_signal\_deinit([sns\_osa\_thread\_signal](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv421sns_osa_thread_signal) \*sig) \_\_attribute\_\_((nonnull))

    - Deinit the given signal object.

- Parameters:

    - **sig** – **[in]** The signal object to deinitialize.

- Returns:

    - - None.

- void sns\_osa\_thread\_signal\_wait([sns\_osa\_thread\_signal](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv421sns_osa_thread_signal) \*sig, sns\_osa\_thread\_sigs mask, sns\_osa\_thread\_sigs \*curr\_signals) \_\_attribute\_\_((nonnull(1)))

    - Wait on the given signal object.

Note

Suspends the current thread until any one of the specified signals is set.

- Parameters:

    - - **sig** – **[in]** The signal object on which to wait.
- **mask** – **[in]** The mask of signal bits on which the signal is to wait.
- **curr\_signals** – **[out]** Destination for bitmask of current signal values, if provided.

- Returns:

    - - None.

- void sns\_osa\_thread\_signal\_wait\_timed([sns\_osa\_thread\_signal](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv421sns_osa_thread_signal) \*sig, uint64\_t duration, sns\_osa\_thread\_sigs mask, sns\_osa\_thread\_sigs \*curr\_signals) \_\_attribute\_\_((nonnull(1)))

    - Waits on the signal object up to.

Note

Suspends the current thread until any one of the specified signals is set, or timed out.

- Parameters:

    - - **sig** – **[in]** The signal object on which to wait.
- **duration** – **[in]** The wait duration.
- **mask** – **[in]** The mask of signal bits on which the signal is to wait.
- **curr\_signals** – **[out]** Destination for bitmask of current signal values, if provided.

- Returns:

    - - None.

- void sns\_osa\_thread\_signal\_set([sns\_osa\_thread\_signal](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv421sns_osa_thread_signal) \*sig, sns\_osa\_thread\_sigs mask, sns\_osa\_thread\_sigs \*old\_signals) \_\_attribute\_\_((nonnull(1)))

    - Sets signals on the signal object.

- Parameters:

    - - **sig** – **[in]** The signal object.
- **mask** – **[in]** The mask of signal bits on which the signal is to set.
- **old\_signals** – **[out]** Destination for bitmask of the old signal values, if provided.

- Returns:

    - - None.

- void sns\_osa\_thread\_signal\_get([sns\_osa\_thread\_signal](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv421sns_osa_thread_signal) \*sig, sns\_osa\_thread\_sigs \*curr\_signals) \_\_attribute\_\_((nonnull))

    - Gets signal values of the signal object.

- Parameters:

    - - **sig** – **[in]** The signal object.
- **curr\_signals** – **[out]** Destination for bitmask of the current signal. values.

- Returns:

    - - None.

- void sns\_osa\_thread\_signal\_clear([sns\_osa\_thread\_signal](https://docs.qualcomm.com/doc/80-P9361-100/topic/os_abstraction.html#_CPPv421sns_osa_thread_signal) \*sig, sns\_osa\_thread\_sigs mask, sns\_osa\_thread\_sigs \*old\_signals) \_\_attribute\_\_((nonnull(1)))

    - Clears the signal object.

- Parameters:

    - - **sig** – **[in]** The signal object.
- **mask** – **[in]** The mask of signal bits to clear.
- **old\_signals** – **[out]** Destination for bitmask of the old signal values, if provided.

- Returns:

    - - None.

Last Published: Jul 14, 2025

[Previous Topic
sessionFactory::getSensingHubIds()](https://docs.qualcomm.com/bundle/publicresource/80-P9361-100/topics/isession.md)