Rename pthread_takesemaphore, pthread_givesemaphore to pthread_sem_take, pthread_sem_give
authorjc_.kim <jc_.kim@samsung.com>
Wed, 31 May 2017 02:40:48 +0000 (11:40 +0900)
committerjc_.kim <jc_.kim@samsung.com>
Wed, 31 May 2017 02:40:48 +0000 (11:40 +0900)
os/kernel/pthread/pthread.h
os/kernel/pthread/pthread_completejoin.c
os/kernel/pthread/pthread_condbroadcast.c
os/kernel/pthread/pthread_condsignal.c
os/kernel/pthread/pthread_condwait.c
os/kernel/pthread/pthread_create.c
os/kernel/pthread/pthread_detach.c
os/kernel/pthread/pthread_initialize.c
os/kernel/pthread/pthread_join.c
os/kernel/pthread/pthread_mutex.c
os/kernel/pthread/pthread_mutexinconsistent.c

index eda3bea..38fadba 100644 (file)
@@ -121,11 +121,11 @@ int pthread_completejoin(pid_t pid, FAR void *exit_value);
 void pthread_destroyjoin(FAR struct task_group_s *group, FAR struct join_s *pjoin);
 FAR struct join_s *pthread_findjoininfo(FAR struct task_group_s *group, pid_t pid);
 void pthread_release(FAR struct task_group_s *group);
-int pthread_takesemaphore(sem_t *sem, bool intr);
+int pthread_sem_take(sem_t *sem, bool intr);
 #ifdef CONFIG_PTHREAD_MUTEX_UNSAFE
 int pthread_sem_trytake(sem_t *sem);
 #endif
-int pthread_givesemaphore(sem_t *sem);
+int pthread_sem_give(sem_t *sem);
 
 #ifndef CONFIG_PTHREAD_MUTEX_UNSAFE
 int pthread_mutex_take(FAR struct pthread_mutex_s *mutex, bool intr);
@@ -133,9 +133,9 @@ int pthread_mutex_trytake(FAR struct pthread_mutex_s *mutex);
 int pthread_mutex_give(FAR struct pthread_mutex_s *mutex);
 void pthread_mutex_inconsistent(FAR struct pthread_tcb_s *tcb);
 #else
-#define pthread_mutex_take(m,i) pthread_takesemaphore(&(m)->sem,(i))
+#define pthread_mutex_take(m,i) pthread_sem_take(&(m)->sem,(i))
 #define pthread_mutex_trytake(m) pthread_sem_trytake(&(m)->sem)
-#define pthread_mutex_give(m)   pthread_givesemaphore(&(m)->sem)
+#define pthread_mutex_give(m)   pthread_sem_give(&(m)->sem)
 #endif
 
 #if defined(CONFIG_CANCELLATION_POINTS) && !defined(CONFIG_PTHREAD_MUTEX_UNSAFE)
index c171913..78c7843 100644 (file)
@@ -118,7 +118,7 @@ static bool pthread_notifywaiters(FAR struct join_s *pjoin)
                 */
 
                do {
-                       status = pthread_givesemaphore(&pjoin->exit_sem);
+                       status = pthread_sem_give(&pjoin->exit_sem);
                        if (status == OK) {
                                status = sem_getvalue(&pjoin->exit_sem, &ntasks_waiting);
                        }
@@ -128,7 +128,7 @@ static bool pthread_notifywaiters(FAR struct join_s *pjoin)
                 * value.
                 */
 
-               (void)pthread_takesemaphore(&pjoin->data_sem, false);
+               (void)pthread_sem_take(&pjoin->data_sem, false);
                return true;
        }
 
@@ -230,11 +230,11 @@ int pthread_completejoin(pid_t pid, FAR void *exit_value)
 
        /* First, find thread's structure in the private data set. */
 
-       (void)pthread_takesemaphore(&group->tg_joinsem, false);
+       (void)pthread_sem_take(&group->tg_joinsem, false);
        pjoin = pthread_findjoininfo(group, pid);
        if (!pjoin) {
                sdbg("Could not find join info, pid=%d\n", pid);
-               (void)pthread_givesemaphore(&group->tg_joinsem);
+               (void)pthread_sem_give(&group->tg_joinsem);
                return ERROR;
        } else {
                bool waiters;
@@ -262,7 +262,7 @@ int pthread_completejoin(pid_t pid, FAR void *exit_value)
                 * to call pthread_destroyjoin.
                 */
 
-               (void)pthread_givesemaphore(&group->tg_joinsem);
+               (void)pthread_sem_give(&group->tg_joinsem);
        }
 
        return OK;
index 7028688..5d99596 100644 (file)
@@ -133,7 +133,7 @@ int pthread_cond_broadcast(FAR pthread_cond_t *cond)
                                 * Only the highest priority waiting thread will get to execute
                                 */
 
-                               ret = pthread_givesemaphore((sem_t *)&cond->sem);
+                               ret = pthread_sem_give((sem_t *)&cond->sem);
 
                                /* Increment the semaphore count (as was done by the
                                 * above post).
index 19811cb..491c2a9 100644 (file)
@@ -136,7 +136,7 @@ int pthread_cond_signal(FAR pthread_cond_t *cond)
                        svdbg("sval=%d\n", sval);
                        if (sval < 0) {
                                svdbg("Signalling...\n");
-                               ret = pthread_givesemaphore((sem_t *)&cond->sem);
+                               ret = pthread_sem_give((sem_t *)&cond->sem);
                        }
                }
        }
index d9fb7e7..be946a8 100644 (file)
@@ -118,7 +118,7 @@ int pthread_cond_wait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex)
 
                /* Take the semaphore */
 
-               status = pthread_takesemaphore((FAR sem_t *)&cond->sem, false);
+               status = pthread_sem_take((FAR sem_t *)&cond->sem, false);
                if (ret == OK) {
                        /* Report the first failure that occurs */
 
index a41b7e6..6a1637f 100644 (file)
@@ -189,14 +189,14 @@ static void pthread_start(void)
 
        /* Sucessfully spawned, add the pjoin to our data set. */
 
-       (void)pthread_takesemaphore(&group->tg_joinsem, false);
+       (void)pthread_sem_take(&group->tg_joinsem, false);
        pthread_addjoininfo(group, pjoin);
-       (void)pthread_givesemaphore(&group->tg_joinsem);
+       (void)pthread_sem_give(&group->tg_joinsem);
 
        /* Report to the spawner that we successfully started. */
 
        pjoin->started = true;
-       (void)pthread_givesemaphore(&pjoin->data_sem);
+       (void)pthread_sem_give(&pjoin->data_sem);
 
        /* Pass control to the thread entry point. In the kernel build this has to
         * be handled differently if we are starting a user-space pthread; we have
@@ -429,7 +429,7 @@ int pthread_create(FAR pthread_t *thread, FAR const pthread_attr_t *attr, pthrea
                 * its join structure.
                 */
 
-               (void)pthread_takesemaphore(&pjoin->data_sem, false);
+               (void)pthread_sem_take(&pjoin->data_sem, false);
 
                /* Return the thread information to the caller */
 
index 6f91b48..49f5598 100644 (file)
@@ -126,7 +126,7 @@ int pthread_detach(pthread_t thread)
 
        /* Find the entry associated with this pthread. */
 
-       (void)pthread_takesemaphore(&group->tg_joinsem, false);
+       (void)pthread_sem_take(&group->tg_joinsem, false);
        pjoin = pthread_findjoininfo(group, (pid_t)thread);
        if (!pjoin) {
                sdbg("Could not find thread entry\n");
@@ -152,7 +152,7 @@ int pthread_detach(pthread_t thread)
                ret = OK;
        }
 
-       (void)pthread_givesemaphore(&group->tg_joinsem);
+       (void)pthread_sem_give(&group->tg_joinsem);
 
        svdbg("Returning %d\n", ret);
        trace_end(TTRACE_TAG_TASK);
index a5faf40..519779c 100644 (file)
@@ -112,11 +112,18 @@ void pthread_initialize(void)
 }
 
 /****************************************************************************
- * Name: pthread_takesemaphore and pthread_givesemaphore
+ * Name: pthread_sem_take, pthread_sem_trytake, and
+ *     pthread_sem_give
  *
  * Description:
  *   Support managed access to the private data sets.
  *
+ *   REVISIT : These functions really do nothing more than match the return
+ *   value of the semaphore functions (0 or -1 with errno set) to the
+ *   return value of more pthread functions (0 or errno).  A better solution
+ *   would be to use an internal version of the semaphore functions that
+ *   return the error value in the correct form.
+ *
  * Parameters:
  *  sem  - The semaphore to lock or unlock
  *  intr - false: ignore EINTR errors when locking; true tread EINTR as
@@ -127,9 +134,9 @@ void pthread_initialize(void)
  *
  ****************************************************************************/
 
-int pthread_takesemaphore(sem_t *sem, bool intr)
+int pthread_sem_take(sem_t *sem, bool intr)
 {
-       trace_begin(TTRACE_TAG_IPC, "pthread_takesemaphore");
+       trace_begin(TTRACE_TAG_IPC, "pthread_sem_take");
        /* Verify input parameters */
 
        DEBUGASSERT(sem != NULL);
@@ -176,7 +183,7 @@ int pthread_sem_trytake(sem_t *sem)
 }
 #endif
 
-int pthread_givesemaphore(sem_t *sem)
+int pthread_sem_give(sem_t *sem)
 {
        /* Verify input parameters */
 
index 4f15888..2076055 100644 (file)
@@ -150,7 +150,7 @@ int pthread_join(pthread_t thread, FAR pthread_addr_t *pexit_value)
         * because it will also attempt to get this semaphore.
         */
 
-       (void)pthread_takesemaphore(&group->tg_joinsem, false);
+       (void)pthread_sem_take(&group->tg_joinsem, false);
 
        /* Find the join information associated with this thread.
         * This can fail for one of three reasons:  (1) There is no
@@ -181,7 +181,7 @@ int pthread_join(pthread_t thread, FAR pthread_addr_t *pexit_value)
                        ret = EINVAL;
                }
 
-               (void)pthread_givesemaphore(&group->tg_joinsem);
+               (void)pthread_sem_give(&group->tg_joinsem);
        } else {
                /* We found the join info structure.  Increment for the reference
                 * to the join structure that we have.  This will keep things
@@ -216,7 +216,7 @@ int pthread_join(pthread_t thread, FAR pthread_addr_t *pexit_value)
                         * semaphore.
                         */
 
-                       (void)pthread_givesemaphore(&group->tg_joinsem);
+                       (void)pthread_sem_give(&group->tg_joinsem);
 
                        /* Take the thread's thread exit semaphore.  We will sleep here
                         * until the thread exits.  We need to exercise caution because
@@ -224,7 +224,7 @@ int pthread_join(pthread_t thread, FAR pthread_addr_t *pexit_value)
                         * pthread to exit.
                         */
 
-                       (void)pthread_takesemaphore(&pjoin->exit_sem, false);
+                       (void)pthread_sem_take(&pjoin->exit_sem, false);
 
                        /* The thread has exited! Get the thread exit value */
 
@@ -237,13 +237,13 @@ int pthread_join(pthread_t thread, FAR pthread_addr_t *pexit_value)
                         * will know that we have received the data.
                         */
 
-                       (void)pthread_givesemaphore(&pjoin->data_sem);
+                       (void)pthread_sem_give(&pjoin->data_sem);
 
                        /* Retake the join semaphore, we need to hold this when
                         * pthread_destroyjoin is called.
                         */
 
-                       (void)pthread_takesemaphore(&group->tg_joinsem, false);
+                       (void)pthread_sem_take(&group->tg_joinsem, false);
                }
 
                /* Pre-emption is okay now. The logic still cannot be re-entered
@@ -260,7 +260,7 @@ int pthread_join(pthread_t thread, FAR pthread_addr_t *pexit_value)
                        (void)pthread_destroyjoin(group, pjoin);
                }
 
-               (void)pthread_givesemaphore(&group->tg_joinsem);
+               (void)pthread_sem_give(&group->tg_joinsem);
                ret = OK;
        }
 
index a13f2ac..b178716 100644 (file)
@@ -138,11 +138,11 @@ int pthread_mutex_take(FAR struct pthread_mutex_s *mutex, bool intr)
                if ((mutex->flags & _PTHREAD_MFLAGS_INCONSISTENT) != 0) {
                        ret = EOWNERDEAD;
                } else {
-                       /* Take semaphore underlying the mutex.  pthread_takesemaphore
+                       /* Take semaphore underlying the mutex.  pthread_sem_take
                         * returns zero on success and a positive errno value on failure.
                         */
 
-                       ret = pthread_takesemaphore(&mutex->sem, intr);
+                       ret = pthread_sem_take(&mutex->sem, intr);
                        if (ret == OK) {
                                /* Check if the holder of the mutex has terminated without
                                 * releasing.  In that case, the state of the mutex is
@@ -270,7 +270,7 @@ int pthread_mutex_give(FAR struct pthread_mutex_s *mutex)
 
                /* Now release the underlying semaphore */
 
-               ret = pthread_givesemaphore(&mutex->sem);
+               ret = pthread_sem_give(&mutex->sem);
        }
 
        return ret;
index 98d263e..085a811 100644 (file)
@@ -111,7 +111,7 @@ void pthread_mutex_inconsistent(FAR struct pthread_tcb_s *tcb)
                /* Mark the mutex as INCONSISTENT and wake up any waiting thread */
 
                mutex->flags |= _PTHREAD_MFLAGS_INCONSISTENT;
-               (void)pthread_givesemaphore(&mutex->sem);
+               (void)pthread_sem_give(&mutex->sem);
        }
 
        sched_unlock();