Commit 0dfc7602 authored by claes's avatar claes

NMpsCell lock added

parent 43421720
/*
* Proview $Id: nmps_appl.c,v 1.2 2006-06-08 04:28:12 claes Exp $
* Proview $Id: nmps_appl.c,v 1.3 2008-01-25 14:35:29 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -57,6 +57,7 @@
#include "co_cdh.h"
#include "rt_gdh.h"
#include "rt_errh.h"
#include "rt_nmps_lock.h"
#include "rt_gdh_msg.h"
#include "rt_hash_msg.h"
#include "rs_nmps_msg.h"
......@@ -113,6 +114,7 @@ typedef struct nmpsappl_s_basectx {
static nmpsappl_t_basectx nmpsappl_basectx = 0;
/*_Local functions________________________________________________________*/
static pwr_tStatus nmpsappl_data_db_create(
......@@ -411,6 +413,9 @@ nmpsappl_MirrorInit(
(nmpsappl_t_datainfo *) calloc( applctx->total_cellsize,
sizeof(nmpsappl_t_datainfo));
nmps_create_lock( &sts);
if ( EVEN(sts)) return sts;
applctx->options = options;
return NMPS__SUCCESS;
......@@ -509,8 +514,10 @@ nmpsappl_Mirror(
for ( i = 0; i < applctx->cellist_count; i++)
{
cellist_ptr = applctx->cellist[i];
nmps_Lock;
memcpy( cellist_ptr->tmp_cell, cellist_ptr->object_ptr,
cellist_ptr->tmp_size);
nmps_Unlock;
}
applctx->data_count = 0;
......
/*
* Proview $Id: nmps_plc.c,v 1.2 2006-01-26 08:15:11 claes Exp $
* Proview $Id: nmps_plc.c,v 1.3 2008-01-25 14:35:29 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
......@@ -34,6 +34,7 @@
#include "pwr_nmpsclasses.h"
#include "rt_gdh.h"
#include "rt_plc.h"
#include "rt_nmps_lock.h"
#include "nmps.h"
#define ODD(a) (((int)(a) & 1) != 0)
......@@ -59,8 +60,7 @@
/* NMpsCell
*/
void NMpsCell_init_time(object)
pwr_sClass_NMpsCell *object;
void NMpsCell_init_time( pwr_sClass_NMpsCell *object)
{
pwr_sAttrRef attrref;
plc_t_DataInfo *data_index;
......@@ -89,11 +89,13 @@ pwr_sClass_NMpsCell *object;
object->ReloadDone |= NMPS_CELL_INITIALIZED;
}
void NMpsCell_init(object)
pwr_sClass_NMpsCell *object;
void NMpsCell_init( pwr_sClass_NMpsCell *object)
{
plc_t_DataInfo *data_index;
int i;
pwr_tStatus sts;
nmps_create_lock( &sts);
if ( !(object->Function & NMPS_CELLFUNC_BACKUP))
NMpsCell_init_time( object);
......@@ -137,16 +139,18 @@ void NMpsCell_exec(
plc_t_DataInfo cpy_buf[NMPS_CELL_SIZE];
#endif
if ( object->InitTime)
{
if ( object->InitTime) {
if ( !(object->ReloadDone & NMPS_CELL_RELOADDONE))
return;
else
{
else {
nmps_Lock;
NMpsCell_init_time( object);
object->ReloadDone &= ~NMPS_CELL_RELOADDONE;
}
}
else
nmps_Lock;
if ( object->FrontNew) object->FrontNew = 0;
if ( object->RearNew) object->RearNew = 0;
......@@ -417,8 +421,10 @@ void NMpsCell_exec(
{
case NMPS_OPTYPE_FORWARD_FRONT:
/* Insert at front of object front of data */
if ( object->CellFull) return;
if ( object->CellFull) {
nmps_Unlock;
return;
}
if ( object->LastIndex > 0)
{
#if defined OS_LINUX
......@@ -452,6 +458,7 @@ void NMpsCell_exec(
{
/* This it not the correct object */
object->InFlag = 0;
nmps_Unlock;
return;
}
object->Data1_Back = 1;
......@@ -463,8 +470,10 @@ void NMpsCell_exec(
object->InFlag = 0;
break;
case NMPS_OPTYPE_FORWARD_UNIT:
if ( object->CellFull) return;
if ( object->CellFull) {
nmps_Unlock;
return;
}
if ( object->LastIndex > 0)
{
#if defined OS_LINUX
......@@ -494,8 +503,10 @@ void NMpsCell_exec(
break;
case NMPS_OPTYPE_REVERSE_BACK:
/* Insert at rear of object back of data */
if ( object->CellFull) return;
if ( object->CellFull) {
nmps_Unlock;
return;
}
data_last = (plc_t_DataInfo *) &object->Data1P;
data_last += object->LastIndex;
data_last->DataP = object->InPointer;
......@@ -513,8 +524,10 @@ void NMpsCell_exec(
break;
case NMPS_OPTYPE_REVERSE_UNIT:
/* Insert at rear of object all of data */
if ( object->CellFull) return;
if ( object->CellFull) {
nmps_Unlock;
return;
}
data_last = (plc_t_DataInfo *) &object->Data1P;
data_last += object->LastIndex;
data_last->DataP = object->InPointer;
......@@ -538,6 +551,7 @@ void NMpsCell_exec(
{
/* This it not the correct object */
object->InFlag = 0;
nmps_Unlock;
return;
}
data_last->Data_Front = 1;
......@@ -561,6 +575,7 @@ void NMpsCell_exec(
if ( object->LastIndex == 0)
{
object->OutRearFlag = 0;
nmps_Unlock;
return;
}
......@@ -606,6 +621,7 @@ void NMpsCell_exec(
if ( object->LastIndex == 0)
{
object->OutFrontFlag = 0;
nmps_Unlock;
return;
}
#if defined OS_LINUX
......@@ -648,15 +664,20 @@ void NMpsCell_exec(
if (object->Function & NMPS_CELLFUNC_BACKUP) object->BackupNow = 1;
}
object->NumberOfData = object->LastIndex;
nmps_Unlock;
}
/* NMpsStoreCell
*/
void NMpsStoreCell_init(object)
pwr_sClass_NMpsStoreCell *object;
void NMpsStoreCell_init( pwr_sClass_NMpsStoreCell *object)
{
plc_t_DataInfo *data_index;
int i;
pwr_tStatus sts;
nmps_create_lock( &sts);
if ( !(object->Function & NMPS_CELLFUNC_BACKUP))
NMpsCell_init_time( (pwr_sClass_NMpsCell *) object);
......@@ -707,10 +728,13 @@ void NMpsStoreCell_exec(
return;
else
{
NMpsCell_init_time( object);
nmps_Lock;
NMpsCell_init_time( (pwr_sClass_NMpsCell *)object);
object->ReloadDone &= ~NMPS_CELL_RELOADDONE;
}
}
else
nmps_Lock;
if ( object->FrontNew) object->FrontNew = 0;
if ( object->RearNew) object->RearNew = 0;
......@@ -1144,8 +1168,10 @@ void NMpsStoreCell_exec(
{
case NMPS_OPTYPE_FORWARD_FRONT:
/* Insert at front of object front of data */
if ( object->CellFull) return;
if ( object->CellFull) {
nmps_Unlock;
return;
}
if ( object->LastIndex > 0)
{
#if defined OS_LINUX
......@@ -1178,6 +1204,7 @@ void NMpsStoreCell_exec(
{
/* This it not the correct object */
object->InFlag = 0;
nmps_Unlock;
return;
}
object->Data1_Back = 1;
......@@ -1189,8 +1216,10 @@ void NMpsStoreCell_exec(
object->InFlag = 0;
break;
case NMPS_OPTYPE_FORWARD_UNIT:
if ( object->CellFull) return;
if ( object->CellFull) {
nmps_Unlock;
return;
}
if ( object->LastIndex > 0)
{
#if defined OS_LINUX
......@@ -1219,8 +1248,10 @@ void NMpsStoreCell_exec(
break;
case NMPS_OPTYPE_REVERSE_BACK:
/* Insert at rear of object back of data */
if ( object->CellFull) return;
if ( object->CellFull) {
nmps_Unlock;
return;
}
data_last = (plc_t_DataInfo *) &object->Data1P;
data_last += object->LastIndex;
data_last->DataP = object->InPointer;
......@@ -1235,8 +1266,10 @@ void NMpsStoreCell_exec(
break;
case NMPS_OPTYPE_REVERSE_UNIT:
/* Insert at rear of object all of data */
if ( object->CellFull) return;
if ( object->CellFull) {
nmps_Unlock;
return;
}
data_last = (plc_t_DataInfo *) &object->Data1P;
data_last += object->LastIndex;
data_last->DataP = object->InPointer;
......@@ -1257,6 +1290,7 @@ void NMpsStoreCell_exec(
{
/* This it not the correct object */
object->InFlag = 0;
nmps_Unlock;
return;
}
data_last->Data_Front = 1;
......@@ -1277,6 +1311,7 @@ void NMpsStoreCell_exec(
if ( object->LastIndex == 0)
{
object->OutRearFlag = 0;
nmps_Unlock;
return;
}
......@@ -1344,6 +1379,7 @@ void NMpsStoreCell_exec(
if ( object->LastIndex == 0)
{
object->OutFrontFlag = 0;
nmps_Unlock;
return;
}
......@@ -1410,6 +1446,8 @@ void NMpsStoreCell_exec(
if (object->Function & NMPS_CELLFUNC_BACKUP) object->BackupNow = 1;
}
object->NumberOfData = object->DataSelected;
nmps_Unlock;
}
/*_*
......
/*
* Proview $Id: rt_nmps_lock.c,v 1.1 2008-01-25 14:32:44 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <string.h>
#include <unistd.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include "pwr.h"
#include "rt_sect.h"
#include "rt_nmps_lock.h"
sect_sHead *nmps_locksect = 0;
void nmps_create_lock( pwr_tStatus *sts)
{
pwr_tBoolean created;
if ( !nmps_locksect) {
nmps_locksect = sect_Alloc( sts, &created, 0, sizeof(sect_sMutex),
nmps_cName_Lock);
if ( ODD(*sts) && created)
sect_InitLock( sts, nmps_locksect, (sect_sMutex *)nmps_locksect->base);
}
}
void nmps_unlink_lock( pwr_tStatus *sts)
{
if ( nmps_locksect) {
if ( shmdt( nmps_locksect) == -1)
*sts = 0;
else
*sts = 1;
}
}
void nmps_delete_lock( pwr_tStatus *sts)
{
if ( nmps_locksect) {
char segname[128];
char busid[8];
char *str = getenv(pwr_dEnvBusId);
key_t key;
int shm_id;
struct shmid_ds ds;
strncpy( busid, (str ? str : "XXX"), 3);
busid[3] = '\0';
sprintf(segname, "%s_%.3s", nmps_cName_Lock, busid);
key = ftok(segname, 'P');
shm_id = shmget(key, 0, 0660);
if ( shmdt( nmps_locksect->base) == -1)
printf( "Detach of nmps lock failed\n");
if ( shmctl(shm_id, IPC_RMID, &ds) == -1)
printf( "Remove of nmps lock failed\n");
unlink(segname);
sect_Free( sts, nmps_locksect);
}
}
/*
* Proview $Id: rt_nmps_lock.h,v 1.1 2008-01-25 14:32:44 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef rt_nmps_lock_h
#define rt_nmps_lock_h
#include "pwr.h"
#include "rt_sect.h"
#define nmps_cName_Lock "/tmp/pwr_nmps_lock"
#define nmps_Lock sect_Lock( NULL, nmps_locksect, (sect_sMutex *)nmps_locksect->base);
#define nmps_Unlock sect_Unlock( NULL, nmps_locksect, (sect_sMutex *)nmps_locksect->base);
extern sect_sHead *nmps_locksect;
void nmps_create_lock( pwr_tStatus *sts);
void nmps_delete_lock( pwr_tStatus *sts);
void nmps_unlink_lock( pwr_tStatus *sts);
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment