MQTT C Client Libraries Internals: Thread.c File Reference

| MQTT C Client Libraries Internals

Loading...
Searching...
No Matches
Macros | Functions
Thread.c File Reference

Threading related functions. More...

`#include "Thread.h"`
`#include "Log.h"`
`#include "StackTrace.h"`
`#include <errno.h>`
`#include <unistd.h>`
`#include <sys/time.h>`
`#include <fcntl.h>`
`#include <stdio.h>`
`#include <sys/stat.h>`
`#include <limits.h>`
`#include <stdlib.h>`
`#include "OsWrapper.h"`
Include dependency graph for Thread.c:

## Macros
#define | NSEC_PER_SEC 1000000000L
#define | USE_TRYWAIT

## Functions
void | Paho_thread_start (thread_fn fn, void *parameter)
| Start a new thread.
int | Thread_set_name (const char *thread_name)
mutex_type | Paho_thread_create_mutex (int *rc)
| Create a new mutex.
int | Paho_thread_lock_mutex (mutex_type mutex)
| Lock a mutex which has alrea.
int | Paho_thread_unlock_mutex (mutex_type mutex)
| Unlock a mutex which has already been locked.
int | Paho_thread_destroy_mutex (mutex_type mutex)
| Destroy a mutex which has already been created.
thread_id_type | Paho_thread_getid (void)
| Get the thread id of the thread from which this function is called.
sem_type | Thread_create_sem (int *rc)
| Create a new semaphore.
int | Thread_wait_sem (sem_type sem, int timeout)
| Wait for a semaphore to be posted, or timeout.
int | Thread_check_sem (sem_type sem)
| Check to see if a semaphore has been posted, without waiting The semaphore will be unchanged, if the return value is false.
int | Thread_post_sem (sem_type sem)
| Post a semaphore.
int | Thread_destroy_sem (sem_type sem)
| Destroy a semaphore which has already been created.
cond_type | Thread_create_cond (int *rc)
| Create a new condition variable.
int | Thread_signal_cond (cond_type condvar)
| Signal a condition variable.
int | Thread_wait_cond (cond_type condvar, int timeout_ms)
| Wait with a timeout (ms) for condition variable.
int | Thread_destroy_cond (cond_type condvar)
| Destroy a condition variable.

## Detailed Description

Threading related functions.

Used to create platform independent threading functions

## Function Documentation

## ◆ Paho_thread_create_mutex()

mutex_type Paho_thread_create_mutex | ( | int * | rc | ) |

Create a new mutex.

Parameters

  rc | return code: 0 for success, negative otherwise

Returns
  the new mutex

## ◆ Paho_thread_destroy_mutex()

int Paho_thread_destroy_mutex | ( | mutex_type | mutex | ) |

Destroy a mutex which has already been created.

Parameters

  mutex | the mutex

## ◆ Paho_thread_getid()

thread_id_type Paho_thread_getid | ( | void |  | ) |

Get the thread id of the thread from which this function is called.

Returns
  thread id, type varying according to OS

## ◆ Paho_thread_lock_mutex()

int Paho_thread_lock_mutex | ( | mutex_type | mutex | ) |

Lock a mutex which has alrea.

Returns
  completion code, 0 is success

## ◆ Paho_thread_start()

void Paho_thread_start | ( | thread_fn | fn,
|  | void * | parameter )

Start a new thread.

Parameters

  fn | the function to run, must be of the correct signature
  parameter | pointer to the function parameter, can be NULL

## ◆ Paho_thread_unlock_mutex()

int Paho_thread_unlock_mutex | ( | mutex_type | mutex | ) |

Unlock a mutex which has already been locked.

Parameters

  mutex | the mutex

Returns
  completion code, 0 is success

## ◆ Thread_check_sem()

int Thread_check_sem | ( | sem_type | sem | ) |

Check to see if a semaphore has been posted, without waiting The semaphore will be unchanged, if the return value is false.

The semaphore will have been decremented, if the return value is true.

Parameters

  sem | the semaphore

Returns
  0 (false) or 1 (true)

## ◆ Thread_create_cond()

cond_type Thread_create_cond | ( | int * | rc | ) |

Create a new condition variable.

Returns
  the condition variable struct

Here is the call graph for this function:

## ◆ Thread_create_sem()

sem_type Thread_create_sem | ( | int * | rc | ) |

Create a new semaphore.

Parameters

  rc | return code: 0 for success, negative otherwise

Returns
  the new condition variable

## ◆ Thread_destroy_cond()

int Thread_destroy_cond | ( | cond_type | condvar | ) |

Destroy a condition variable.

Returns
  completion code

## ◆ Thread_destroy_sem()

int Thread_destroy_sem | ( | sem_type | sem | ) |

Destroy a semaphore which has already been created.

Parameters

  sem | the semaphore

## ◆ Thread_post_sem()

int Thread_post_sem | ( | sem_type | sem | ) |

Post a semaphore.

Parameters

  sem | the semaphore

Returns
  0 on success

## ◆ Thread_signal_cond()

int Thread_signal_cond | ( | cond_type | condvar | ) |

Signal a condition variable.

Returns
  completion code

## ◆ Thread_wait_cond()

int Thread_wait_cond | ( | cond_type | condvar,
|  | int | timeout_ms )

Wait with a timeout (ms) for condition variable.

Returns
  0 for success, ETIMEDOUT otherwise

## ◆ Thread_wait_sem()

int Thread_wait_sem | ( | sem_type | sem,
|  | int | timeout )

Wait for a semaphore to be posted, or timeout.

Parameters

  sem | the semaphore
  timeout | the maximum time to wait, in milliseconds

Returns
  completion code