summaryrefslogtreecommitdiff
path: root/pjlib
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2006-01-05 23:35:46 +0000
committerBenny Prijono <bennylp@teluu.com>2006-01-05 23:35:46 +0000
commit67d6a30732fd1e1fae2f98f646d97356b2eaa8c9 (patch)
tree599de20e4a6554656db42030cdce7c1f2ccdb655 /pjlib
parent944562492d0c16b9e44ec4e1cc97657846d82cd0 (diff)
Added loop transport to test transaction
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@107 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib')
-rw-r--r--pjlib/include/pj/compat/socket.h2
-rw-r--r--pjlib/include/pj/list.h27
-rw-r--r--pjlib/src/pj/os_core_win32.c33
3 files changed, 52 insertions, 10 deletions
diff --git a/pjlib/include/pj/compat/socket.h b/pjlib/include/pj/compat/socket.h
index c45cd3f2..1ef7fff3 100644
--- a/pjlib/include/pj/compat/socket.h
+++ b/pjlib/include/pj/compat/socket.h
@@ -79,9 +79,11 @@
#ifdef PJ_WIN32
# define OSERR_EWOULDBLOCK WSAEWOULDBLOCK
# define OSERR_EINPROGRESS WSAEINPROGRESS
+# define OSERR_ECONNRESET WSAECONNRESET
#else
# define OSERR_EWOULDBLOCK EWOULDBLOCK
# define OSERR_EINPROGRESS EINPROGRESS
+# define OSERR_ECONNRESET ECONNRESET
#endif
diff --git a/pjlib/include/pj/list.h b/pjlib/include/pj/list.h
index fc0223cc..4f2e5145 100644
--- a/pjlib/include/pj/list.h
+++ b/pjlib/include/pj/list.h
@@ -117,6 +117,19 @@ PJ_IDECL(void) pj_list_insert_before(pj_list_type *pos, pj_list_type *node);
/**
+ * Insert the node to the back of the list. This is just an alias for
+ * #pj_list_insert_before().
+ *
+ * @param list The list.
+ * @param node The element to be inserted.
+ */
+PJ_INLINE(void) pj_list_push_back(pj_list_type *list, pj_list_type *node)
+{
+ pj_list_insert_before(list, node);
+}
+
+
+/**
* Inserts all nodes in \a nodes to the target list.
*
* @param lst The target list.
@@ -136,6 +149,20 @@ PJ_IDECL(void) pj_list_insert_nodes_before(pj_list_type *lst,
*/
PJ_IDECL(void) pj_list_insert_after(pj_list_type *pos, pj_list_type *node);
+
+/**
+ * Insert the node to the front of the list. This is just an alias for
+ * #pj_list_insert_after().
+ *
+ * @param list The list.
+ * @param node The element to be inserted.
+ */
+PJ_INLINE(void) pj_list_push_front(pj_list_type *list, pj_list_type *node)
+{
+ pj_list_insert_after(list, node);
+}
+
+
/**
* Insert all nodes in \a nodes to the target list.
*
diff --git a/pjlib/src/pj/os_core_win32.c b/pjlib/src/pj/os_core_win32.c
index eac778f6..7633e7b0 100644
--- a/pjlib/src/pj/os_core_win32.c
+++ b/pjlib/src/pj/os_core_win32.c
@@ -862,8 +862,13 @@ PJ_DEF(pj_bool_t) pj_mutex_is_locked(pj_mutex_t *mutex)
struct pj_rwmutex_t
{
- pj_mutex_t *read_lock, *write_lock;
- int reader_count;
+ pj_mutex_t *read_lock;
+ /* write_lock must use semaphore, because write_lock may be released
+ * by thread other than the thread that acquire the write_lock in the
+ * first place.
+ */
+ pj_sem_t *write_lock;
+ pj_int32_t reader_count;
};
/*
@@ -885,7 +890,7 @@ PJ_DEF(pj_status_t) pj_rwmutex_create(pj_pool_t *pool, const char *name,
if (status != PJ_SUCCESS)
return status;
- status = pj_mutex_create_recursive(pool, name, &rwmutex->write_lock);
+ status = pj_sem_create(pool, name, 1, 1, &rwmutex->write_lock);
if (status != PJ_SUCCESS) {
pj_mutex_destroy(rwmutex->read_lock);
return status;
@@ -907,12 +912,17 @@ PJ_DEF(pj_status_t) pj_rwmutex_lock_read(pj_rwmutex_t *mutex)
PJ_ASSERT_RETURN(mutex, PJ_EINVAL);
status = pj_mutex_lock(mutex->read_lock);
- if (status != PJ_SUCCESS)
+ if (status != PJ_SUCCESS) {
+ pj_assert(!"This pretty much is unexpected");
return status;
+ }
mutex->reader_count++;
+
+ pj_assert(mutex->reader_count < 0x7FFFFFF0L);
+
if (mutex->reader_count == 1)
- pj_mutex_lock(mutex->write_lock);
+ pj_sem_wait(mutex->write_lock);
status = pj_mutex_unlock(mutex->read_lock);
return status;
@@ -925,7 +935,7 @@ PJ_DEF(pj_status_t) pj_rwmutex_lock_read(pj_rwmutex_t *mutex)
PJ_DEF(pj_status_t) pj_rwmutex_lock_write(pj_rwmutex_t *mutex)
{
PJ_ASSERT_RETURN(mutex, PJ_EINVAL);
- return pj_mutex_lock(mutex->write_lock);
+ return pj_sem_wait(mutex->write_lock);
}
/*
@@ -939,14 +949,16 @@ PJ_DEF(pj_status_t) pj_rwmutex_unlock_read(pj_rwmutex_t *mutex)
PJ_ASSERT_RETURN(mutex, PJ_EINVAL);
status = pj_mutex_lock(mutex->read_lock);
- if (status != PJ_SUCCESS)
+ if (status != PJ_SUCCESS) {
+ pj_assert(!"This pretty much is unexpected");
return status;
+ }
pj_assert(mutex->reader_count >= 1);
--mutex->reader_count;
if (mutex->reader_count == 0)
- pj_mutex_unlock(mutex->write_lock);
+ pj_sem_post(mutex->write_lock);
status = pj_mutex_unlock(mutex->read_lock);
return status;
@@ -959,7 +971,8 @@ PJ_DEF(pj_status_t) pj_rwmutex_unlock_read(pj_rwmutex_t *mutex)
PJ_DEF(pj_status_t) pj_rwmutex_unlock_write(pj_rwmutex_t *mutex)
{
PJ_ASSERT_RETURN(mutex, PJ_EINVAL);
- return pj_mutex_unlock(mutex->write_lock);
+ pj_assert(mutex->reader_count <= 1);
+ return pj_sem_post(mutex->write_lock);
}
@@ -971,7 +984,7 @@ PJ_DEF(pj_status_t) pj_rwmutex_destroy(pj_rwmutex_t *mutex)
{
PJ_ASSERT_RETURN(mutex, PJ_EINVAL);
pj_mutex_destroy(mutex->read_lock);
- pj_mutex_destroy(mutex->write_lock);
+ pj_sem_destroy(mutex->write_lock);
return PJ_SUCCESS;
}