SphinxBase 5prealpha
sbthread.h
Go to the documentation of this file.
1/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/* ====================================================================
3 * Copyright (c) 2008 Carnegie Mellon University. All rights
4 * reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 *
18 * This work was supported in part by funding from the Defense Advanced
19 * Research Projects Agency and the National Science Foundation of the
20 * United States of America, and the CMU Sphinx Speech Consortium.
21 *
22 * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
23 * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
26 * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 * ====================================================================
35 *
36 */
43#ifndef __SBTHREAD_H__
44#define __SBTHREAD_H__
45
46#include <sphinx_config.h>
47
48#include <sphinxbase/sphinxbase_export.h>
49#include <sphinxbase/cmd_ln.h>
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54#if 0
55/* Fool Emacs. */
56}
57#endif
58
62typedef struct sbthread_s sbthread_t;
63
67typedef struct sbmsgq_s sbmsgq_t;
68
72typedef struct sbmtx_s sbmtx_t;
73
77typedef struct sbevent_s sbevent_t;
78
82typedef int (*sbthread_main)(sbthread_t *th);
83
87SPHINXBASE_EXPORT
88sbthread_t *sbthread_start(cmd_ln_t *config, sbthread_main func, void *arg);
89
93SPHINXBASE_EXPORT
95
99SPHINXBASE_EXPORT
100void sbthread_free(sbthread_t *th);
101
105SPHINXBASE_EXPORT
107
111SPHINXBASE_EXPORT
112void *sbthread_arg(sbthread_t *th);
113
117SPHINXBASE_EXPORT
119
123SPHINXBASE_EXPORT
125
132SPHINXBASE_EXPORT
133int sbthread_send(sbthread_t *th, size_t len, void const *data);
134
140SPHINXBASE_EXPORT
141sbmsgq_t *sbmsgq_init(size_t depth);
142
146SPHINXBASE_EXPORT
147void sbmsgq_free(sbmsgq_t *q);
148
152SPHINXBASE_EXPORT
153int sbmsgq_send(sbmsgq_t *q, size_t len, void const *data);
154
158SPHINXBASE_EXPORT
159void *sbmsgq_wait(sbmsgq_t *q, size_t *out_len, int sec, int nsec);
160
164SPHINXBASE_EXPORT
165sbmtx_t *sbmtx_init(void);
166
170SPHINXBASE_EXPORT
171int sbmtx_trylock(sbmtx_t *mtx);
172
176SPHINXBASE_EXPORT
177int sbmtx_lock(sbmtx_t *mtx);
178
182SPHINXBASE_EXPORT
183int sbmtx_unlock(sbmtx_t *mtx);
184
188SPHINXBASE_EXPORT
189void sbmtx_free(sbmtx_t *mtx);
190
194SPHINXBASE_EXPORT
196
200SPHINXBASE_EXPORT
201void sbevent_free(sbevent_t *evt);
202
206SPHINXBASE_EXPORT
207int sbevent_signal(sbevent_t *evt);
208
212SPHINXBASE_EXPORT
213int sbevent_wait(sbevent_t *evt, int sec, int nsec);
214
215
216#ifdef __cplusplus
217}
218#endif
219
220
221#endif /* __SBTHREAD_H__ */
Command-line and other configurationparsing and handling.
SPHINXBASE_EXPORT int sbthread_wait(sbthread_t *th)
Wait for a thread to complete.
Definition sbthread.c:425
int(* sbthread_main)(sbthread_t *th)
Entry point for a thread.
Definition sbthread.h:82
SPHINXBASE_EXPORT void * sbthread_arg(sbthread_t *th)
Get argument pointer from a thread.
Definition sbthread.c:716
SPHINXBASE_EXPORT sbevent_t * sbevent_init(void)
Initialize an event.
Definition sbthread.c:611
SPHINXBASE_EXPORT sbthread_t * sbthread_start(cmd_ln_t *config, sbthread_main func, void *arg)
Start a new thread.
Definition sbthread.c:406
SPHINXBASE_EXPORT int sbmtx_trylock(sbmtx_t *mtx)
Try to acquire a mutex.
Definition sbthread.c:684
SPHINXBASE_EXPORT sbmtx_t * sbmtx_init(void)
Create a mutex.
Definition sbthread.c:671
SPHINXBASE_EXPORT int sbmtx_lock(sbmtx_t *mtx)
Acquire a mutex.
Definition sbthread.c:690
SPHINXBASE_EXPORT int sbevent_signal(sbevent_t *evt)
Signal an event.
Definition sbthread.c:640
SPHINXBASE_EXPORT int sbthread_send(sbthread_t *th, size_t len, void const *data)
Send an asynchronous message to a thread.
Definition sbthread.c:728
SPHINXBASE_EXPORT void sbmtx_free(sbmtx_t *mtx)
Dispose of a mutex.
Definition sbthread.c:702
SPHINXBASE_EXPORT void sbthread_free(sbthread_t *th)
Free a thread object.
Definition sbthread.c:734
SPHINXBASE_EXPORT int sbmsgq_send(sbmsgq_t *q, size_t len, void const *data)
Post a message to a queue.
Definition sbthread.c:475
SPHINXBASE_EXPORT void sbmsgq_free(sbmsgq_t *q)
Free a message queue.
Definition sbthread.c:465
SPHINXBASE_EXPORT sbmsgq_t * sbmsgq_init(size_t depth)
Create a message queue.
Definition sbthread.c:444
SPHINXBASE_EXPORT int sbevent_wait(sbevent_t *evt, int sec, int nsec)
Wait for an event to be signalled.
Definition sbthread.c:652
SPHINXBASE_EXPORT void * sbmsgq_wait(sbmsgq_t *q, size_t *out_len, int sec, int nsec)
Wait for a message from a queue.
Definition sbthread.c:555
SPHINXBASE_EXPORT sbmsgq_t * sbthread_msgq(sbthread_t *th)
Get message queue from a thread.
Definition sbthread.c:722
SPHINXBASE_EXPORT int sbmtx_unlock(sbmtx_t *mtx)
Release a mutex.
Definition sbthread.c:696
SPHINXBASE_EXPORT cmd_ln_t * sbthread_config(sbthread_t *th)
Get configuration object from a thread.
Definition sbthread.c:710
SPHINXBASE_EXPORT void sbevent_free(sbevent_t *evt)
Free an event.
Definition sbthread.c:632
Opaque structure used to hold the results of command-line parsing.