From 0074691a67f857c9b3f880fb581e0af1d5673337 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Thu, 31 Jul 1997 22:13:29 +0000 Subject: Merged very large and much appreciated patch from Chris Johns . This patch includes the ods68302 bsp, the RTEMS++ class library, and the rtems++ test. --- c/src/lib/librtems++/rtemsSemaphore.cc | 174 +++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 c/src/lib/librtems++/rtemsSemaphore.cc (limited to 'c/src/lib/librtems++/rtemsSemaphore.cc') diff --git a/c/src/lib/librtems++/rtemsSemaphore.cc b/c/src/lib/librtems++/rtemsSemaphore.cc new file mode 100644 index 0000000000..1e0d3de472 --- /dev/null +++ b/c/src/lib/librtems++/rtemsSemaphore.cc @@ -0,0 +1,174 @@ +/* + ------------------------------------------------------------------------ + $Id$ + ------------------------------------------------------------------------ + + COPYRIGHT (c) 1997 + Objective Design Systems Ltd Pty (ODS) + All rights reserved (R) Objective Design Systems Ltd Pty + + The license and distribution terms for this file may be found in the + file LICENSE in this distribution or at + http://www.OARcorp.com/rtems/license.html. + + ------------------------------------------------------------------------ + + See header file. + + ------------------------------------------------------------------------ +*/ + +#include + +/* ---- + rtemsSemaphore +*/ + +rtemsSemaphore::rtemsSemaphore(const char* sname, + const Scope scope, + const rtems_unsigned32 counter, + const WaitMode wait_mode, + const Type type, + const Priority priority, + const Ceiling ceiling, + const rtems_task_priority priority_ceiling) + : name(0), + owner(true), + id(0) +{ + strcpy(name_str, "NOID"); + create(sname, + scope, + counter, + wait_mode, + type, + priority, + ceiling, + priority_ceiling); +} + +rtemsSemaphore::rtemsSemaphore(const char *sname, const rtems_unsigned32 node) + : name(0), + owner(false), + id(0) +{ + strcpy(name_str, "NOID"); + connect(sname, node); +} + +rtemsSemaphore::rtemsSemaphore(const rtemsSemaphore& semaphore) + : name(0), + owner(false), + id(0) +{ + name = semaphore.name; + strcpy(name_str, semaphore.name_str); + id = semaphore.id; +} + +rtemsSemaphore::rtemsSemaphore() + : name(0), + owner(false), + id(0) +{ + strcpy(name_str, "NOID"); +} + +rtemsSemaphore::~rtemsSemaphore() +{ + destroy(); +} + +void rtemsSemaphore::make_invalid() +{ + strcpy(name_str, "NOID"); + name = 0; + id = 0; + owner = false; +} + +const rtems_status_code rtemsSemaphore::create(const char* sname, + const Scope scope, + const rtems_unsigned32 counter, + const WaitMode wait_mode, + const Type type, + const Priority priority, + const Ceiling ceiling, + const rtems_task_priority priority_ceiling) +{ + if (id) + return set_status_code(RTEMS_ILLEGAL_ON_SELF); + + owner = true; + + strcpy(name_str, " "); + for (int c = 0; (c < 4) && (sname[c] != '\0'); c++) + name_str[c] = sname[c]; + name = rtems_build_name(name_str[0], + name_str[1], + name_str[2], + name_str[3]); + + set_status_code(rtems_semaphore_create(name, + counter, + scope | wait_mode | type | priority | ceiling, + priority_ceiling, + &id)); + + if (unsuccessful()) + { + make_invalid(); + } + + return last_status_code(); +} + +const rtems_status_code rtemsSemaphore::destroy() +{ + if (id && owner) + { + set_status_code(rtems_semaphore_delete(id)); + make_invalid(); + } + else + set_status_code(RTEMS_NOT_OWNER_OF_RESOURCE); + + return last_status_code(); +} + +const rtemsSemaphore& rtemsSemaphore::operator=(const rtemsSemaphore& semaphore) +{ + if (!owner) + { + name = semaphore.name; + id = semaphore.id; + } + return *this; +} + +const rtems_status_code rtemsSemaphore::connect(const char *sname, + const rtems_unsigned32 node) +{ + if (id && owner) + return set_status_code(RTEMS_UNSATISFIED); + + // change state to not owner + owner = false; + + strcpy(name_str, " "); + for (int c = 0; (c < 4) && (sname[c] != '\0'); c++) + name_str[c] = sname[c]; + name = rtems_build_name(name_str[0], + name_str[1], + name_str[2], + name_str[3]); + + set_status_code(rtems_semaphore_ident(name, node, &id)); + + if (unsuccessful()) + { + make_invalid(); + } + + return last_status_code(); +} -- cgit v1.2.3