本文整理汇总了C++中cw_mutex_lock函数的典型用法代码示例。如果您正苦于以下问题:C++ cw_mutex_lock函数的具体用法?C++ cw_mutex_lock怎么用?C++ cw_mutex_lock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cw_mutex_lock函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: config_load
static int config_load(void)
{
struct cw_config *cfg;
char *cat;
struct osp_provider *osp, *prev = NULL, *next;
cw_mutex_lock(&osplock);
osp = providers;
while(osp) {
osp->dead = 1;
osp = osp->next;
}
cw_mutex_unlock(&osplock);
cfg = cw_config_load("osp.conf");
if (cfg) {
if (!initialized) {
cat = cw_variable_retrieve(cfg, "general", "accelerate");
if (cat && cw_true(cat))
if (OSPPInit(1)) {
cw_log(LOG_WARNING, "Failed to enable hardware accelleration, falling back to software mode\n");
OSPPInit(0);
} else
hardware = 1;
else
OSPPInit(0);
initialized = 1;
}
cat = cw_variable_retrieve(cfg, "general", "tokenformat");
if (cat) {
if ((sscanf(cat, "%d", &tokenformat) != 1) || (tokenformat < TOKEN_ALGO_SIGNED) || (tokenformat > TOKEN_ALGO_BOTH)) {
tokenformat = TOKEN_ALGO_SIGNED;
cw_log(LOG_WARNING, "tokenformat should be an integer from 0 to 2, not '%s'\n", cat);
}
}
cat = cw_category_browse(cfg, NULL);
while(cat) {
if (strcasecmp(cat, "general"))
osp_build(cfg, cat);
cat = cw_category_browse(cfg, cat);
}
cw_config_destroy(cfg);
} else
cw_log(LOG_NOTICE, "No OSP configuration found. OSP support disabled\n");
cw_mutex_lock(&osplock);
osp = providers;
while(osp) {
next = osp->next;
if (osp->dead) {
if (prev)
prev->next = next;
else
providers = next;
/* XXX Cleanup OSP structure first XXX */
free(osp);
} else
prev = osp;
osp = next;
}
cw_mutex_unlock(&osplock);
return 0;
}
示例2:
/* locate a tone_zone_sound, given the tone_zone. if tone_zone == NULL, use the default tone_zone */
struct tone_zone_sound *cw_get_indication_tone(const struct tone_zone *zone, const char *indication)
{
struct tone_zone_sound *ts;
/* we need some tonezone, pick the first */
if (zone == NULL && current_tonezone)
zone = current_tonezone; /* default country? */
if (zone == NULL && tone_zones)
zone = tone_zones; /* any country? */
if (zone == NULL)
return 0; /* not a single country insight */
if (cw_mutex_lock(&tzlock))
{
cw_log(LOG_WARNING, "Unable to lock tone_zones list\n");
return 0;
}
for (ts = zone->tones; ts; ts = ts->next)
{
if (strcasecmp(indication, ts->name) == 0)
{
/* found indication! */
cw_mutex_unlock(&tzlock);
return ts;
}
}
/* nothing found, sorry */
cw_mutex_unlock(&tzlock);
return 0;
}
示例3: memset
static struct cw_filestream *g726_16_rewrite(FILE *f, const char *comment)
{
/* We don't have any header to read or anything really, but
if we did, it would go here. We also might want to check
and be sure it's a valid file. */
struct cw_filestream *tmp;
if ((tmp = malloc(sizeof(struct cw_filestream)))) {
memset(tmp, 0, sizeof(struct cw_filestream));
if (cw_mutex_lock(&g726_lock)) {
cw_log(LOG_WARNING, "Unable to lock g726 list.\n");
free(tmp);
return NULL;
}
tmp->f = f;
tmp->rate = RATE_16;
glistcnt++;
if (option_debug)
cw_log(LOG_DEBUG, "Created filestream G.726-%dk.\n",
40 - tmp->rate * 8);
cw_mutex_unlock(&g726_lock);
cw_update_use_count();
} else
cw_log(LOG_WARNING, "Out of memory\n");
return tmp;
}
示例4: cw_log
static struct cw_filestream *au_rewrite(FILE *f, const char *comment)
{
struct cw_filestream *tmp;
if ((tmp = malloc(sizeof(struct cw_filestream))) == NULL)
{
cw_log(LOG_ERROR, "Out of memory\n");
return NULL;
}
memset(tmp, 0, sizeof(struct cw_filestream));
if (write_header(f))
{
free(tmp);
return NULL;
}
if (cw_mutex_lock(&au_lock))
{
cw_log(LOG_WARNING, "Unable to lock au count\n");
free(tmp);
return NULL;
}
tmp->f = f;
localusecnt++;
cw_mutex_unlock(&au_lock);
cw_update_use_count();
return tmp;
}
示例5: show_osp
static int show_osp(int fd, int argc, char *argv[])
{
struct osp_provider *osp;
char *search = NULL;
int x;
int found = 0;
char *tokenalgo;
if ((argc < 2) || (argc > 3))
return RESULT_SHOWUSAGE;
if (argc > 2)
search = argv[2];
if (!search) {
switch (tokenformat) {
case TOKEN_ALGO_BOTH:
tokenalgo = "Both";
break;
case TOKEN_ALGO_UNSIGNED:
tokenalgo = "Unsigned";
break;
case TOKEN_ALGO_SIGNED:
default:
tokenalgo = "Signed";
break;
}
cw_cli(fd, "OSP: %s %s %s\n", initialized ? "Initialized" : "Uninitialized", hardware ? "Accelerated" : "Normal", tokenalgo);
}
cw_mutex_lock(&osplock);
osp = providers;
while(osp) {
if (!search || !strcasecmp(osp->name, search)) {
if (found)
cw_cli(fd, "\n");
cw_cli(fd, " == OSP Provider '%s' ==\n", osp->name);
cw_cli(fd, "Local Private Key: %s\n", osp->localpvtkey);
cw_cli(fd, "Local Certificate: %s\n", osp->localcert);
for (x=0;x<osp->cacount;x++)
cw_cli(fd, "CA Certificate %d: %s\n", x + 1, osp->cacerts[x]);
for (x=0;x<osp->spcount;x++)
cw_cli(fd, "Service Point %d: %s\n", x + 1, osp->servicepoints[x]);
cw_cli(fd, "Max Connections: %d\n", osp->maxconnections);
cw_cli(fd, "Retry Delay: %d seconds\n", osp->retrydelay);
cw_cli(fd, "Retry Limit: %d\n", osp->retrylimit);
cw_cli(fd, "Timeout: %d milliseconds\n", osp->timeout);
cw_cli(fd, "Source: %s\n", strlen(osp->source) ? osp->source : "<unspecified>");
cw_cli(fd, "OSP Handle: %d\n", osp->handle);
found++;
}
osp = osp->next;
}
cw_mutex_unlock(&osplock);
if (!found) {
if (search)
cw_cli(fd, "Unable to find OSP provider '%s'\n", search);
else
cw_cli(fd, "No OSP providers configured\n");
}
return RESULT_SUCCESS;
}
示例6: cw_mutex_lock
static void *database_queue_thread_main(void *data) {
cw_mutex_lock(&db_condition_lock);
for ( ;; ) {
if ( db_list_head ) {
//cw_log(LOG_ERROR,"DB DO SAVE OUR LIST\n");
database_flush_cache();
sleep( CACHE_COMMIT_INTERVAL );
}
else
{
cw_cond_wait(&db_condition_save, &db_condition_lock);
/*
//cw_log(LOG_ERROR,"DB SAVE CONDITION RECEIVED\n");
db_list_t *e = db_list_head;
cw_log(LOG_ERROR,"QUEUE NOW IS:\n");
while ( e ) {
if ( e->sql )
cw_log(LOG_ERROR,"ITEM: %s\n",e->sql);
e = e->next;
}
*/
}
}
cw_mutex_unlock(&db_condition_lock);
return NULL;
}
示例7: memset
static struct cw_filestream *pcm_rewrite(FILE *f, const char *comment)
{
/* We don't have any header to read or anything really, but
if we did, it would go here. We also might want to check
and be sure it's a valid file. */
struct cw_filestream *tmp;
if ((tmp = malloc(sizeof(struct cw_filestream))))
{
memset(tmp, 0, sizeof(struct cw_filestream));
if (cw_mutex_lock(&pcm_lock))
{
cw_log(LOG_WARNING, "Unable to lock pcm list\n");
free(tmp);
return NULL;
}
tmp->f = f;
glistcnt++;
cw_mutex_unlock(&pcm_lock);
cw_update_use_count();
}
else
{
cw_log(LOG_WARNING, "Out of memory\n");
}
return tmp;
}
示例8: cw_mutex_lock
static void *service_thread(void *data)
{
struct sched_context *con = data;
cw_mutex_lock(&con->lock);
pthread_cleanup_push((void (*)(void *))cw_mutex_unlock, &con->lock);
for (;;) {
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
if (con->schedq) {
struct timespec tick;
tick.tv_sec = con->schedq->when.tv_sec;
tick.tv_nsec = 1000 * con->schedq->when.tv_usec;
while (cw_cond_timedwait(&con->service, &con->lock, &tick) < 0 && errno == EINTR);
} else {
while (cw_cond_wait(&con->service, &con->lock) < 0 && errno == EINTR);
}
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
cw_sched_runq(con);
}
pthread_cleanup_pop(1);
return NULL;
}
示例9: cw_sched_add_variable
int cw_sched_add_variable(struct sched_context *con, int when, cw_sched_cb callback, void *data, int variable)
{
/*
* Schedule callback(data) to happen when ms into the future
*/
struct sched *tmp;
int res = -1;
#ifdef DEBUG_SCHED
DEBUG_LOG(cw_log(LOG_DEBUG, "cw_sched_add_variable()\n"));
#endif
cw_mutex_lock(&con->lock);
if ((tmp = sched_alloc(con))) {
if ((tmp->id = con->eventcnt++) < 0)
tmp->id = con->eventcnt = 0;
tmp->callback = callback;
tmp->data = data;
tmp->resched = when;
tmp->variable = variable;
tmp->when = cw_tvadd(cw_tvnow(), cw_samp2tv(when, 1000));
schedule(con, tmp);
res = tmp->id;
}
#ifdef DUMP_SCHEDULER
/* Dump contents of the context while we have the lock so nothing gets screwed up by accident. */
cw_sched_dump(con);
#endif
cw_mutex_unlock(&con->lock);
return res;
}
示例10: ogg_vorbis_close
/*!
* \brief Close a OGG/Vorbis filestream.
* \param s A OGG/Vorbis filestream.
*/
static void ogg_vorbis_close(struct cw_filestream *s)
{
if (cw_mutex_lock(&ogg_vorbis_lock)) {
cw_log(LOG_WARNING, "Unable to lock ogg_vorbis list\n");
return;
}
glistcnt--;
cw_mutex_unlock(&ogg_vorbis_lock);
cw_update_use_count();
if (s->writing) {
/* Tell the Vorbis encoder that the stream is finished
* and write out the rest of the data */
vorbis_analysis_wrote(&s->vd, 0);
write_stream(s);
}
ogg_stream_clear(&s->os);
vorbis_block_clear(&s->vb);
vorbis_dsp_clear(&s->vd);
vorbis_comment_clear(&s->vc);
vorbis_info_clear(&s->vi);
if (s->writing) {
ogg_sync_clear(&s->oy);
}
fclose(s->fp);
free(s);
}
示例11: cw_log
static struct cw_filestream *h263_open(FILE *f)
{
/* We don't have any header to read or anything really, but
if we did, it would go here. We also might want to check
and be sure it's a valid file. */
struct cw_filestream *tmp;
unsigned int ts;
int res;
if ((res = fread(&ts, 1, sizeof(ts), f)) < sizeof(ts))
{
cw_log(LOG_WARNING, "Empty file!\n");
return NULL;
}
if ((tmp = malloc(sizeof(struct cw_filestream))))
{
memset(tmp, 0, sizeof(struct cw_filestream));
if (cw_mutex_lock(&h263_lock))
{
cw_log(LOG_WARNING, "Unable to lock h263 list\n");
free(tmp);
return NULL;
}
tmp->f = f;
cw_fr_init_ex(&tmp->fr, CW_FRAME_VIDEO, CW_FORMAT_H263, name);
tmp->fr.data = tmp->h263;
/* datalen will vary for each frame */
glistcnt++;
cw_mutex_unlock(&h263_lock);
cw_update_use_count();
}
return tmp;
}
示例12: cw_autoservice_stop
int cw_autoservice_stop(struct cw_channel *chan)
{
int res = -1;
struct asent *as, *prev;
cw_mutex_lock(&autolock);
as = aslist;
prev = NULL;
while(as) {
if (as->chan == chan)
break;
prev = as;
as = as->next;
}
if (as) {
if (prev)
prev->next = as->next;
else
aslist = as->next;
free(as);
if (!chan->_softhangup)
res = 0;
}
if (asthread != CW_PTHREADT_NULL)
pthread_kill(asthread, SIGURG);
cw_mutex_unlock(&autolock);
/* Wait for it to un-block */
while(cw_test_flag(chan, CW_FLAG_BLOCKING))
usleep(1000);
return res;
}
示例13: sccp_pbx_write
static int sccp_pbx_write(struct cw_channel *ast, struct cw_frame *frame) {
sccp_channel_t * c = CS_CW_CHANNEL_PVT(ast);
if (!c)
return 0;
int res = 0;
if (frame->frametype != CW_FRAME_VOICE) {
if (frame->frametype == CW_FRAME_IMAGE)
return 0;
else {
cw_log(LOG_WARNING, "%s: Can't send %d type frames with SCCP write on channel %d\n", DEV_ID_LOG(c->device), frame->frametype, (c) ? c->callid : 0);
return 0;
}
} else {
if (!(frame->subclass & ast->nativeformats)) {
cw_log(LOG_WARNING, "%s: Asked to transmit frame type %d, while native formats is %d (read/write = %d/%d)\n",
DEV_ID_LOG(c->device), frame->subclass, ast->nativeformats, ast->readformat, ast->writeformat);
return -1;
}
}
if (c) {
cw_mutex_lock(&c->lock);
if (c->rtp) {
res = cw_rtp_write(c->rtp, frame);
}
cw_mutex_unlock(&c->lock);
}
return res;
}
示例14: cw_autoservice_start
int cw_autoservice_start(struct cw_channel *chan)
{
int res = -1;
struct asent *as;
int needstart;
cw_mutex_lock(&autolock);
needstart = (asthread == CW_PTHREADT_NULL) ? 1 : 0 /* aslist ? 0 : 1 */;
as = aslist;
while(as) {
if (as->chan == chan)
break;
as = as->next;
}
if (!as) {
as = malloc(sizeof(struct asent));
if (as) {
memset(as, 0, sizeof(struct asent));
as->chan = chan;
as->next = aslist;
aslist = as;
res = 0;
if (needstart) {
if (cw_pthread_create(&asthread, NULL, autoservice_run, NULL)) {
cw_log(LOG_WARNING, "Unable to create autoservice thread :(\n");
free(aslist);
aslist = NULL;
res = -1;
} else
pthread_kill(asthread, SIGURG);
}
}
}
cw_mutex_unlock(&autolock);
return res;
}
示例15: sched_context_destroy
void sched_context_destroy(struct sched_context *con)
{
struct sched *s, *sl;
if (!pthread_equal(con->tid, CW_PTHREADT_NULL)) {
pthread_cancel(con->tid);
pthread_join(con->tid, NULL);
cw_cond_destroy(&con->service);
}
cw_mutex_lock(&con->lock);
#ifdef SCHED_MAX_CACHE
/* Eliminate the cache */
s = con->schedc;
while(s) {
sl = s;
s = s->next;
free(sl);
}
#endif
/* And the queue */
s = con->schedq;
while(s) {
sl = s;
s = s->next;
free(sl);
}
/* And the context */
cw_mutex_unlock(&con->lock);
cw_mutex_destroy(&con->lock);
free(con);
}