Changeset 0a593c2d in rtems


Ignore:
Timestamp:
Jan 3, 2018, 5:24:59 AM (19 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
d9800ac
Parents:
a59a6182
git-author:
Sebastian Huber <sebastian.huber@…> (01/03/18 05:24:59)
git-committer:
Sebastian Huber <sebastian.huber@…> (02/07/18 07:58:30)
Message:

ftpd: Use self-contained synchronization objects

Update #2843.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ftpd/ftpd.c

    ra59a6182 r0a593c2d  
    206206#include <rtems/ftpd.h>
    207207#include <rtems/libio.h>
     208#include <rtems/thread.h>
    208209#include <rtems/userenv.h>
    209210#include <syslog.h>
     
    275276typedef struct
    276277{
    277   FTPD_SessionInfo_t    *info;
    278   FTPD_SessionInfo_t    **queue;
    279   int                   count;
    280   int                   head;
    281   int                   tail;
    282   rtems_id              mutex;
    283   rtems_id              sem;
     278  FTPD_SessionInfo_t       *info;
     279  FTPD_SessionInfo_t       **queue;
     280  int                      count;
     281  int                      head;
     282  int                      tail;
     283  rtems_mutex              mutex;
     284  rtems_counting_semaphore sem;
    284285} FTPD_TaskPool_t;
    285286
     
    364365  if(task_pool.queue)
    365366    free(task_pool.queue);
    366   if(task_pool.mutex != (rtems_id)-1)
    367     rtems_semaphore_delete(task_pool.mutex);
    368   if(task_pool.sem != (rtems_id)-1)
    369     rtems_semaphore_delete(task_pool.sem);
     367  rtems_mutex_destroy(&task_pool.mutex);
     368  rtems_counting_semaphore_destroy(&task_pool.sem);
    370369  task_pool.info = 0;
    371370  task_pool.queue = 0;
    372371  task_pool.count = 0;
    373   task_pool.sem = -1;
    374   task_pool.mutex = -1;
    375372}
    376373
     
    399396  task_pool.count = 0;
    400397  task_pool.head = task_pool.tail = 0;
    401   task_pool.mutex = (rtems_id)-1;
    402   task_pool.sem   = (rtems_id)-1;
    403 
    404   sc = rtems_semaphore_create(
    405     rtems_build_name('F', 'T', 'P', 'M'),
    406     1,
    407     RTEMS_DEFAULT_ATTRIBUTES
    408     | RTEMS_BINARY_SEMAPHORE
    409     | RTEMS_INHERIT_PRIORITY
    410     | RTEMS_PRIORITY,
    411     RTEMS_NO_PRIORITY,
    412     &task_pool.mutex);
    413 
    414   if(sc == RTEMS_SUCCESSFUL)
    415     sc = rtems_semaphore_create(
    416       rtems_build_name('F', 'T', 'P', 'S'),
    417       count,
    418       RTEMS_DEFAULT_ATTRIBUTES,
    419       RTEMS_NO_PRIORITY,
    420       &task_pool.sem);
    421 
    422   if(sc != RTEMS_SUCCESSFUL) {
    423     task_pool_done(0);
    424     syslog(LOG_ERR, "ftpd: Can not create semaphores");
    425     return 0;
    426   }
     398
     399  rtems_mutex_init(&task_pool.mutex, "FTPD");
     400  rtems_counting_semaphore_init(&task_pool.sem, "FTPD", (unsigned int) count);
    427401
    428402  task_pool.info = (FTPD_SessionInfo_t*)
     
    486460{
    487461  FTPD_SessionInfo_t* info = 0;
    488   rtems_status_code sc;
    489   sc = rtems_semaphore_obtain(task_pool.sem, RTEMS_NO_WAIT, RTEMS_NO_TIMEOUT);
    490   if (sc == RTEMS_SUCCESSFUL)
    491   {
    492     rtems_semaphore_obtain(task_pool.mutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
    493     info = task_pool.queue[task_pool.head];
    494     if(++task_pool.head >= task_pool.count)
    495       task_pool.head = 0;
    496     rtems_semaphore_release(task_pool.mutex);
    497   }
     462  rtems_counting_semaphore_wait(&task_pool.sem);
     463  rtems_mutex_lock(&task_pool.mutex);
     464  info = task_pool.queue[task_pool.head];
     465  if(++task_pool.head >= task_pool.count)
     466    task_pool.head = 0;
     467  rtems_mutex_unlock(&task_pool.mutex);
    498468  return info;
    499469}
     
    514484task_pool_release(FTPD_SessionInfo_t* info)
    515485{
    516   rtems_semaphore_obtain(task_pool.mutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
     486  rtems_mutex_lock(&task_pool.mutex);
    517487  task_pool.queue[task_pool.tail] = info;
    518488  if(++task_pool.tail >= task_pool.count)
    519489    task_pool.tail = 0;
    520   rtems_semaphore_release(task_pool.mutex);
    521   rtems_semaphore_release(task_pool.sem);
     490  rtems_mutex_unlock(&task_pool.mutex);
     491  rtems_counting_semaphore_post(&task_pool.sem);
    522492}
    523493
Note: See TracChangeset for help on using the changeset viewer.