fix mutex locking in Windows and take back boost 10ms polling, is needed for now

git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@933 a93c3328-9c30-0410-af19-c9cd2b2d52af
This commit is contained in:
Moises Silva 2009-12-09 20:35:53 +00:00
parent 15c93b5c0d
commit 39974a3536
3 changed files with 18 additions and 15 deletions

View File

@ -377,7 +377,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request)
OUTBOUND_REQUESTS[r].span = span;
if (sangomabc_connection_write(&sangoma_boost_data->mcon, &event) <= 0) {
zap_log(ZAP_LOG_CRIT, "Failed to tx on ISUP socket [%s]\n", strerror(errno));
zap_log(ZAP_LOG_CRIT, "Failed to tx boost event [%s]\n", strerror(errno));
status = ZAP_FAIL;
*zchan = NULL;
goto done;
@ -1416,7 +1416,7 @@ static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj)
zap_span_t *span = (zap_span_t *) obj;
sangomabc_connection_t *mcon, *pcon;
uint32_t ms = 10;
zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data;
zap_sangoma_boost_data_t *sangoma_boost_data = span->signal_data;
mcon = &sangoma_boost_data->mcon;
pcon = &sangoma_boost_data->pcon;
@ -1466,7 +1466,7 @@ static void *zap_sangoma_boost_run(zap_thread_t *me, void *obj)
break;
}
if ((activity = zap_boost_wait_event(span, -1)) < 0) {
if ((activity = zap_boost_wait_event(span, ms)) < 0) {
zap_log(ZAP_LOG_ERROR, "zap_boost_wait_event failed\n");
goto error;
}

View File

@ -41,7 +41,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="../../../src/include;../../../src/isdn/include;&quot;C:\Program Files\Sangoma&quot;"
AdditionalIncludeDirectories="../../../src/include;../../../src/isdn/include;&quot;C:\Program Files\Sangoma\include&quot;"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;"
MinimalRebuild="true"
BasicRuntimeChecks="3"
@ -64,7 +64,7 @@
Name="VCLinkerTool"
AdditionalDependencies="openzap.lib libsangoma.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;$(OutDir)&quot;;C:\wanpipe\lib"
AdditionalLibraryDirectories="&quot;$(OutDir)&quot;;&quot;C:\Program Files\Sangoma\lib&quot;"
GenerateDebugInformation="true"
SubSystem="1"
RandomizedBaseAddress="1"

View File

@ -38,10 +38,6 @@ struct zap_mutex {
CRITICAL_SECTION mutex;
};
struct zap_condition {
HANDLE condition;
};
#else
#include <pthread.h>
@ -52,12 +48,17 @@ struct zap_mutex {
pthread_mutex_t mutex;
};
#endif
struct zap_condition {
#ifdef WIN32
HANDLE condition;
#else
pthread_cond_t condition;
pthread_mutex_t *mutex;
#endif
zap_mutex_t *mutex;
};
#endif
struct zap_thread {
#ifdef WIN32
@ -250,13 +251,13 @@ OZ_DECLARE(zap_status_t) zap_condition_create(zap_condition_t **incondition, zap
return ZAP_FAIL;
}
condition->mutex = mutex;
#ifdef WIN32
condition->condition = CreateEvent(NULL, FALSE, FALSE, NULL);
if (!condition->condition) {
goto failed;
}
#else
condition->mutex = &mutex->mutex;
if (pthread_cond_init(&condition->condition, NULL)) {
goto failed;
}
@ -279,7 +280,9 @@ OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms)
#endif
zap_assert_return(condition != NULL, ZAP_FAIL, "Condition is null!\n");
#ifdef WIN32
zap_mutex_unlock(condition->mutex);
res = WaitForSingleObject(condition->condition, ms > 0 ? ms : INFINITE);
zap_mutex_lock(condition->mutex);
switch (res) {
case WAIT_ABANDONED:
case WAIT_TIMEOUT:
@ -298,9 +301,9 @@ OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms)
struct timespec waitms;
waitms.tv_sec = time(NULL) + ( ms / 1000 );
waitms.tv_nsec = 1000 * 1000 * ( ms % 1000 );
res = pthread_cond_timedwait(&condition->condition, condition->mutex, &waitms);
res = pthread_cond_timedwait(&condition->condition, condition->mutex->mutex, &waitms);
} else {
res = pthread_cond_wait(&condition->condition, condition->mutex);
res = pthread_cond_wait(&condition->condition, condition->mutex->mutex);
}
if (res != 0) {
if (res == ETIMEDOUT) {
@ -340,8 +343,8 @@ OZ_DECLARE(zap_status_t) zap_condition_destroy(zap_condition_t **incondition)
if (pthread_cond_destroy(&condition->condition)) {
return ZAP_FAIL;
}
zap_safe_free(condition);
#endif
zap_safe_free(condition);
*incondition = NULL;
return ZAP_SUCCESS;
}