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
52 extern "C" {
53 #endif
54 #if 0
55 /* Fool Emacs. */
56 }
57 #endif
58 
62 typedef struct sbthread_s sbthread_t;
63 
67 typedef struct sbmsgq_s sbmsgq_t;
68 
72 typedef struct sbmtx_s sbmtx_t;
73 
77 typedef struct sbevent_s sbevent_t;
78 
82 typedef int (*sbthread_main)(sbthread_t *th);
83 
87 SPHINXBASE_EXPORT
88 sbthread_t *sbthread_start(cmd_ln_t *config, sbthread_main func, void *arg);
89 
93 SPHINXBASE_EXPORT
94 int sbthread_wait(sbthread_t *th);
95 
99 SPHINXBASE_EXPORT
100 void sbthread_free(sbthread_t *th);
101 
105 SPHINXBASE_EXPORT
107 
111 SPHINXBASE_EXPORT
112 void *sbthread_arg(sbthread_t *th);
113 
117 SPHINXBASE_EXPORT
119 
123 SPHINXBASE_EXPORT
124 int sbthread_wait(sbthread_t *th);
125 
132 SPHINXBASE_EXPORT
133 int sbthread_send(sbthread_t *th, size_t len, void const *data);
134 
140 SPHINXBASE_EXPORT
141 sbmsgq_t *sbmsgq_init(size_t depth);
142 
146 SPHINXBASE_EXPORT
147 void sbmsgq_free(sbmsgq_t *q);
148 
152 SPHINXBASE_EXPORT
153 int sbmsgq_send(sbmsgq_t *q, size_t len, void const *data);
154 
158 SPHINXBASE_EXPORT
159 void *sbmsgq_wait(sbmsgq_t *q, size_t *out_len, int sec, int nsec);
160 
164 SPHINXBASE_EXPORT
165 sbmtx_t *sbmtx_init(void);
166 
170 SPHINXBASE_EXPORT
171 int sbmtx_trylock(sbmtx_t *mtx);
172 
176 SPHINXBASE_EXPORT
177 int sbmtx_lock(sbmtx_t *mtx);
178 
182 SPHINXBASE_EXPORT
183 int sbmtx_unlock(sbmtx_t *mtx);
184 
188 SPHINXBASE_EXPORT
189 void sbmtx_free(sbmtx_t *mtx);
190 
194 SPHINXBASE_EXPORT
195 sbevent_t *sbevent_init(void);
196 
200 SPHINXBASE_EXPORT
201 void sbevent_free(sbevent_t *evt);
202 
206 SPHINXBASE_EXPORT
207 int sbevent_signal(sbevent_t *evt);
208 
212 SPHINXBASE_EXPORT
213 int 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 sbevent_signal(sbevent_t *evt)
Signal an event.
Definition: sbthread.c:640
SPHINXBASE_EXPORT sbmsgq_t * sbthread_msgq(sbthread_t *th)
Get message queue from a thread.
Definition: sbthread.c:722
SPHINXBASE_EXPORT void sbmsgq_free(sbmsgq_t *q)
Free a message queue.
Definition: sbthread.c:465
SPHINXBASE_EXPORT int sbmtx_lock(sbmtx_t *mtx)
Acquire a mutex.
Definition: sbthread.c:690
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
int(* sbthread_main)(sbthread_t *th)
Entry point for a thread.
Definition: sbthread.h:82
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 sbmtx_t * sbmtx_init(void)
Create a mutex.
Definition: sbthread.c:671
SPHINXBASE_EXPORT sbmsgq_t * sbmsgq_init(size_t depth)
Create a message queue.
Definition: sbthread.c:444
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
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 int sbmtx_unlock(sbmtx_t *mtx)
Release a mutex.
Definition: sbthread.c:696
SPHINXBASE_EXPORT sbevent_t * sbevent_init(void)
Initialize an event.
Definition: sbthread.c:611
SPHINXBASE_EXPORT int sbmsgq_send(sbmsgq_t *q, size_t len, void const *data)
Post a message to a queue.
Definition: sbthread.c:475
Opaque structure used to hold the results of command-line parsing.
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 void sbmtx_free(sbmtx_t *mtx)
Dispose of a mutex.
Definition: sbthread.c:702
SPHINXBASE_EXPORT int sbthread_wait(sbthread_t *th)
Wait for a thread to complete.
Definition: sbthread.c:425
SPHINXBASE_EXPORT void sbthread_free(sbthread_t *th)
Free a thread object.
Definition: sbthread.c:734
SPHINXBASE_EXPORT void * sbthread_arg(sbthread_t *th)
Get argument pointer from a thread.
Definition: sbthread.c:716