ThingWorx C SDK
Classes | Typedefs | Functions
twThreads.h File Reference

Wrappers for OS-specific threading functionality. More...

#include <stdint.h>
#include <stdlib.h>
#include <time.h>
#include "twDefinitions.h"
#include "twOSPort.h"
#include "twTasker.h"

Go to the source code of this file.

Classes

struct  twThread
 twThread structure definition. More...
 

Typedefs

typedef struct twThread twThread
 twThread structure definition. More...
 

Functions

twThreadtwThread_Create (twTaskFunction func, uint32_t rate, void *opaquePtr, char autoStart)
 Creates a new twThread. More...
 
void twThread_Delete (void *t)
 Frees all memory associated with a twThread and all of its owned substructures. More...
 
int twThread_Start (twThread *t)
 Starts a twThread. More...
 
int twThread_Stop (twThread *t, int32_t waitTime)
 Stops a twThread. More...
 
int twThread_Pause (twThread *t)
 Pauses a twThread. More...
 
int twThread_Resume (twThread *t)
 Resumes a twThread. More...
 
char twThread_IsRunning (twThread *t)
 Checks if a twThread is running via twThread::isRunning of t. More...
 
char twThread_IsPaused (twThread *t)
 Checks if a twThread is paused via twThread::isPaused of t. More...
 
char twThread_IsStopped (twThread *t)
 Checks if a twThread has stopped via twThread::hasStopped of t. More...
 
TW_THREAD_ID twThread_GetThreadId (twThread *t)
 Gets the id of a thread via twThread::id of t. More...
 

Detailed Description

Wrappers for OS-specific threading functionality.

Typedef Documentation

typedef struct twThread twThread

twThread structure definition.

Note
This is a very simple threading facility designed to allow the use to execute twTaskFunctions to be run in separate threads rather than using the built-in tasker

Function Documentation

twThread* twThread_Create ( twTaskFunction  func,
uint32_t  rate,
void *  opaquePtr,
char  autoStart 
)

Creates a new twThread.

Parameters
[in]funcThe twTaskFunction of the thread.
[in]rateTBD
[in]opaquePtrAn opaque pointer passed into the thread for any user purpose.
[in]autoStart#TRUE has new thread start automatically.
Returns
A pointer to the newly allocated twThread.
Note
The calling function gains ownership of the returned twThread and is responsible for freeing it via twThread_Delete().
void twThread_Delete ( void *  t)

Frees all memory associated with a twThread and all of its owned substructures.

Parameters
[in]tA pointer to the twThread to be deleted.
Returns
Nothing.
Note
if twThread::hasStopped is #FALSE, the thread will be twThread_Stop()'d before it is deleted.
TW_THREAD_ID twThread_GetThreadId ( twThread t)

Gets the id of a thread via twThread::id of t.

Parameters
[in]tThe twThread to get the id of.
Returns
The twThread::id of t. 0 if t was NULL.
char twThread_IsPaused ( twThread t)

Checks if a twThread is paused via twThread::isPaused of t.

Parameters
[in]tThe twThread to check.
Returns
#TRUE if the thread is paused, #FALSE if it is not.
char twThread_IsRunning ( twThread t)

Checks if a twThread is running via twThread::isRunning of t.

Parameters
[in]tThe twThread to check.
Returns
#TRUE if the thread is running, #FALSE if it is not.
char twThread_IsStopped ( twThread t)

Checks if a twThread has stopped via twThread::hasStopped of t.

Parameters
[in]tThe twThread to check.
Returns
#TRUE if the thread has stopped, #FALSE if it has not.
int twThread_Pause ( twThread t)

Pauses a twThread.

[in] t A pointer to the twThread to pause.

Returns
#TW_OK if successful, positive integral on error code (see twErrors.h) if an error was encountered.
int twThread_Resume ( twThread t)

Resumes a twThread.

[in] t A pointer to the twThread to resume.

Returns
#TW_OK if successful, positive integral on error code (see twErrors.h) if an error was encountered.
int twThread_Start ( twThread t)

Starts a twThread.

[in] t A pointer to the twThread to start.

Returns
#TW_OK if successful, positive integral on error code (see twErrors.h) if an error was encountered.
int twThread_Stop ( twThread t,
int32_t  waitTime 
)

Stops a twThread.

[in] t A pointer to the twThread to stop.

Parameters
[in]waitTimeHow long to wait for the twThread to stop after a shutdown request is set.
Returns
#TW_OK if successful, positive integral on error code (see twErrors.h) if an error was encountered.
Note
If the twThread has not stopped after waitTime, the thread is canceled.