diff options
author | David M. Lee <dlee@digium.com> | 2015-01-26 14:50:40 +0000 |
---|---|---|
committer | David M. Lee <dlee@digium.com> | 2015-01-26 14:50:40 +0000 |
commit | 965777ccfc61067d1dc79f79c12d52f794fa3983 (patch) | |
tree | fc931f38e9acc6885ca0df5fdbc1e14bac437495 /main | |
parent | a8ae5a7bcb3c102b1a196d109a1d06507dd3dd1e (diff) |
Various fixes for OS X
This patch addresses compilation errors on OS X. It's been a while, so
there's quite a few things.
* Fixed __attribute__ decls in route.h to be portable.
* Fixed htonll and ntohll to work when they are defined as macros.
* Replaced sem_t usage with our ast_sem wrapper.
* Added ast_sem_timedwait to our ast_sem wrapper.
* Fixed some GCC 4.9 warnings using sig*set() functions.
* Fixed some format strings for portability.
* Fixed compilation issues with res_timing_kqueue (although tests still fail
on OS X).
* Fixed menuconfig /sbin/launchd detection, which disables res_timing_kqueue
on OS X).
ASTERISK-24539 #close
Reported by: George Joseph
ASTERISK-24544 #close
Reported by: George Joseph
Review: https://reviewboard.asterisk.org/r/4327/
........
Merged revisions 431092 from http://svn.asterisk.org/svn/asterisk/branches/13
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@431093 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main')
-rw-r--r-- | main/app.c | 4 | ||||
-rw-r--r-- | main/asterisk.c | 14 | ||||
-rw-r--r-- | main/bridge_channel.c | 12 | ||||
-rw-r--r-- | main/rtp_engine.c | 2 | ||||
-rw-r--r-- | main/sem.c | 33 |
5 files changed, 50 insertions, 15 deletions
diff --git a/main/app.c b/main/app.c index 53987d8cd..cd7078ea1 100644 --- a/main/app.c +++ b/main/app.c @@ -2911,7 +2911,9 @@ int ast_safe_fork(int stop_reaper) ast_replace_sigchld(); } - sigfillset(&signal_set); + /* GCC 4.9 gives a bogus "right-hand operand of comma expression has + * no effect" warning */ + (void) sigfillset(&signal_set); pthread_sigmask(SIG_BLOCK, &signal_set, &old_set); pid = fork(); diff --git a/main/asterisk.c b/main/asterisk.c index 7378d2271..1e5829616 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -4366,12 +4366,14 @@ int main(int argc, char *argv[]) } ast_makesocket(); - sigemptyset(&sigs); - sigaddset(&sigs, SIGHUP); - sigaddset(&sigs, SIGTERM); - sigaddset(&sigs, SIGINT); - sigaddset(&sigs, SIGPIPE); - sigaddset(&sigs, SIGWINCH); + /* GCC 4.9 gives a bogus "right-hand operand of comma expression has + * no effect" warning */ + (void) sigemptyset(&sigs); + (void) sigaddset(&sigs, SIGHUP); + (void) sigaddset(&sigs, SIGTERM); + (void) sigaddset(&sigs, SIGINT); + (void) sigaddset(&sigs, SIGPIPE); + (void) sigaddset(&sigs, SIGWINCH); pthread_sigmask(SIG_BLOCK, &sigs, NULL); sigaction(SIGURG, &urg_handler, NULL); signal(SIGINT, __quit_handler); diff --git a/main/bridge_channel.c b/main/bridge_channel.c index ff72c57bb..25a1a5153 100644 --- a/main/bridge_channel.c +++ b/main/bridge_channel.c @@ -35,7 +35,6 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include <signal.h> -#include <semaphore.h> #include "asterisk/heap.h" #include "asterisk/astobj2.h" @@ -56,6 +55,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/parking.h" #include "asterisk/causes.h" #include "asterisk/test.h" +#include "asterisk/sem.h" /*! * \brief Used to queue an action frame onto a bridge channel and write an action frame into a bridge. @@ -101,7 +101,7 @@ struct bridge_sync { /*! Unique ID of this synchronization object. Corresponds with ID in synchronous frame payload */ unsigned int id; /*! Semaphore used for synchronization */ - sem_t sem; + struct ast_sem sem; /*! Pointer to next entry in the list */ AST_LIST_ENTRY(bridge_sync) list; }; @@ -124,7 +124,7 @@ static void bridge_sync_init(struct bridge_sync *sync_struct, unsigned int id) { memset(sync_struct, 0, sizeof(*sync_struct)); sync_struct->id = id; - sem_init(&sync_struct->sem, 0, 0); + ast_sem_init(&sync_struct->sem, 0, 0); AST_RWLIST_WRLOCK(&sync_structs); AST_RWLIST_INSERT_TAIL(&sync_structs, sync_struct, list); @@ -157,7 +157,7 @@ static void bridge_sync_cleanup(struct bridge_sync *sync_struct) AST_LIST_TRAVERSE_SAFE_END; AST_RWLIST_UNLOCK(&sync_structs); - sem_destroy(&sync_struct->sem); + ast_sem_destroy(&sync_struct->sem); } /*! @@ -189,7 +189,7 @@ static void bridge_sync_wait(struct bridge_sync *sync_struct) .tv_nsec = timeout_val.tv_usec * 1000, }; - sem_timedwait(&sync_struct->sem, &timeout_spec); + ast_sem_timedwait(&sync_struct->sem, &timeout_spec); } /*! @@ -204,7 +204,7 @@ static void bridge_sync_wait(struct bridge_sync *sync_struct) */ static void bridge_sync_signal(struct bridge_sync *sync_struct) { - sem_post(&sync_struct->sem); + ast_sem_post(&sync_struct->sem); } void ast_bridge_channel_lock_bridge(struct ast_bridge_channel *bridge_channel) diff --git a/main/rtp_engine.c b/main/rtp_engine.c index 962899b57..7326adf65 100644 --- a/main/rtp_engine.c +++ b/main/rtp_engine.c @@ -1948,7 +1948,7 @@ static struct ast_json *rtcp_report_to_json(struct stasis_message *msg, char sec[32]; char usec[32]; snprintf(sec, sizeof(sec), "%lu", payload->report->sender_information.ntp_timestamp.tv_sec); - snprintf(usec, sizeof(usec), "%lu", payload->report->sender_information.ntp_timestamp.tv_usec); + snprintf(usec, sizeof(usec), "%lu", (unsigned long)payload->report->sender_information.ntp_timestamp.tv_usec); json_rtcp_sender_info = ast_json_pack("{s: s, s: s, s: i, s: i, s: i}", "ntp_timestamp_sec", sec, "ntp_timestamp_usec", usec, diff --git a/main/sem.c b/main/sem.c index e67d9c72e..7315165d7 100644 --- a/main/sem.c +++ b/main/sem.c @@ -85,6 +85,7 @@ int ast_sem_post(struct ast_sem *sem) int ast_sem_wait(struct ast_sem *sem) { + int res; SCOPED_MUTEX(lock, &sem->mutex); ast_assert(sem->count >= 0); @@ -92,7 +93,37 @@ int ast_sem_wait(struct ast_sem *sem) /* Wait for a non-zero count */ ++sem->waiters; while (sem->count == 0) { - ast_cond_wait(&sem->cond, &sem->mutex); + res = ast_cond_wait(&sem->cond, &sem->mutex); + /* Give up on error */ + if (res != 0) { + --sem->waiters; + return res; + } + } + --sem->waiters; + + /* Take it! */ + --sem->count; + + return 0; +} + +int ast_sem_timedwait(struct ast_sem *sem, const struct timespec *abs_timeout) +{ + int res; + SCOPED_MUTEX(lock, &sem->mutex); + + ast_assert(sem->count >= 0); + + /* Wait for a non-zero count */ + ++sem->waiters; + while (sem->count == 0) { + res = ast_cond_timedwait(&sem->cond, &sem->mutex, abs_timeout); + /* Give up on error */ + if (res != 0) { + --sem->waiters; + return res; + } } --sem->waiters; |