diff --git a/include/core/internal/nCache.h b/include/core/internal/nCache.h new file mode 100644 index 0000000..186ec77 --- /dev/null +++ b/include/core/internal/nCache.h @@ -0,0 +1,102 @@ +/**************************************************************************** + | + | (C) Copyright 1985, 1991, 1993, 1996 Novell, Inc. + | All Rights Reserved. + | + | This program is free software; you can redistribute it and/or + | modify it under the terms of version 2 of the GNU General Public + | License as published by the Free Software Foundation. + | + | 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 this program; if not, contact Novell, Inc. + | + | To contact Novell about this file by physical or electronic mail, + | you may find current contact information at www.novell.com + | + |*************************************************************************** + | + | NetWare Advance File Services (NSS) Initialization module + | + |--------------------------------------------------------------------------- + | + | $Author: taysom $ + | $Date: 2004-12-31 01:10:58 +0530 (Fri, 31 Dec 2004) $ + | + | $RCSfile$ + | $Revision: 465 $ + | + |--------------------------------------------------------------------------- + | This module is used to: + | Definitions used by caching. + | + | WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! + | + | This header file should ONLY be used for NSS internal development. + | This includes Semantic Agents (SA) and Loadable Storage Services (LSS). + | Any other use may cause conflicts which NSS will NOT fix. + +-------------------------------------------------------------------------*/ +#ifndef _NCACHE_H_ +#define _NCACHE_H_ + +#ifndef _XCACHE_H_ +# include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/*------------------------------------------------------------------------- + * Initialization routines + *-------------------------------------------------------------------------*/ +extern STATUS CACHE_Startup(void); +extern void CACHE_Shutdown(void); + +extern STATUS fsmStart(void); +extern void fsmStop(void); + +extern STATUS SLAB_Startup(void); +extern void SLAB_Shutdown(void); + +extern STATUS MSG_Startup(void); +extern void MSG_Shutdown(void); + +extern STATUS BOND_Startup(void); +extern void BOND_Shutdown(void); + +extern STATUS ASYNCIO_Startup(void); +extern void ASYNCIO_Shutdown(void); + +extern STATUS WORK_Startup(void); +extern void WORK_Shutdown(void); + + +/*------------------------------------------------------------------------- + * Macros for translating INTERNAL names to EXTERNAL names + *-------------------------------------------------------------------------*/ +#define defaultSignal LB_defaultSignal +#define defaultFlush(a1) LB_defaultFlush(a1) +#define defaultFlushWait(a1) LB_defaultFlushWait(a1) +#define lazyFlush(a1) LB_lazyFlush(a1) +#define continueFlush(f1) LB_continueFlush(f1) + +#define initBind(p1,p2,p3) LB_initBind(p1,p2,p3) +#define bind(p1,p2) LB_bind(p1,p2) +#define freeBond(p1) LB_freeBond(p1) + +#define freeAsyncio(p1) LB_freeAsyncio(p1) +#define freeAsyncioRA(p1) LB_freeAsyncioRA(p1) +#define getAsyncio() LB_getAsyncio() +#define getAsyncioNoWait() LB_getAsyncioNoWait() +#define getAsyncioNoWaitRA() LB_getAsyncioNoWaitRA() + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 28664c9..9546814 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -143,6 +143,7 @@ add_library(nwcore SHARED library/os/alarm.c library/os/config.c nss/cache/control.c + nss/cache/asyncio.c library/fsm/fsmnw.c library/latch/intlatch.c library/latch/latch.c diff --git a/src/core/nss/cache/asyncio.c b/src/core/nss/cache/asyncio.c new file mode 100644 index 0000000..1ab9e64 --- /dev/null +++ b/src/core/nss/cache/asyncio.c @@ -0,0 +1,146 @@ +/**************************************************************************** + | + | (C) Copyright 1985, 1991, 1993, 1996 Novell, Inc. + | All Rights Reserved. + | + | This program is free software; you can redistribute it and/or + | modify it under the terms of version 2 of the GNU General Public + | License as published by the Free Software Foundation. + | + | 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 this program; if not, contact Novell, Inc. + | + | To contact Novell about this file by physical or electronic mail, + | you may find current contact information at www.novell.com + | + |*************************************************************************** + | + | NetWare Advance File Services (NSS) Initialization module + | + |--------------------------------------------------------------------------- + | + | $Author: vandana $ + | $Date: 2005-08-10 01:03:51 +0530 (Wed, 10 Aug 2005) $ + | + | $RCSfile$ + | $Revision: 1177 $ + | + |--------------------------------------------------------------------------- + | This module is used to: + | Routines for allocating and managing structures for asynchronous + | requests. + +-------------------------------------------------------------------------*/ +#include +#include +#include +#include + +/* + * Set up the system pool of async IO control structures + */ + +ControlStore_s AsyncioControl; +ControlStore_s AsyncioControlRA; + +void ASYNCIO_Init (DefaultAsyncio_s *asyncio) +{ + static int instance = 0; + ASSERT_MPKNSS_LOCK(); + + FSM_INIT( &asyncio->io.fsm, asyncio->io.stack, + MAX_IO_FSM_DEPTH, MSGNot("Asyncio"), instance) + ++instance; +} + +STATUS ASYNCIO_Startup (void) +{ + STATUS status; + ASSERT_MPKNSS_LOCK(); + + status = CONTROL_Startup( &AsyncioControl, Config.cache.numAsyncios, + sizeof(DefaultAsyncio_s), (voidfunc_t)ASYNCIO_Init); + if (status != zOK) + { + return status; + } + status = CONTROL_Startup( &AsyncioControlRA, Config.cache.numAsyncios, + sizeof(DefaultAsyncio_s), (voidfunc_t)ASYNCIO_Init); + + return status; +} + +void ASYNCIO_Shutdown (void) +{ + ASSERT_MPKNSS_LOCK(); + CONTROL_Shutdown( &AsyncioControlRA); + CONTROL_Shutdown( &AsyncioControl); +} + + /* + * Get asyncio structure does not use the standard control routines + * because we don't want to use cache buffers for asyncio structures. + */ +Asyncio_s *LB_getAsyncio (void) +{ + Asyncio_s *asyncio; + ASSERT_MPKNSS_LOCK(); + + asyncio = CONTROL_getNoAlloc( &AsyncioControl); + zASSERT(asyncio != NULL); + + return asyncio; +} + + /* + * Get asyncio structure does not use the standard control routines + * because we don't want to use cache buffers for asyncio structures. + * If no Asyncio's available do not wait for one. (Read Ahead case) + */ +Asyncio_s *LB_getAsyncioNoWait (void) +{ + Asyncio_s *asyncio; + ASSERT_MPKNSS_LOCK(); + + asyncio = CONTROL_getNoAllocNoWait( &AsyncioControl); + + return asyncio; +} + +Asyncio_s *LB_getAsyncioNoWaitRA (void) +{ + Asyncio_s *asyncio; + ASSERT_MPKNSS_LOCK(); + + asyncio = CONTROL_getNoAllocNoWait( &AsyncioControlRA); + + return asyncio; +} +/**************************************************************************** + * Free asyncio structure + *****************************************************************************/ +void LB_freeAsyncio (Asyncio_s *asyncio) +{ + ASSERT_MPKNSS_LOCK(); + +#if NSS_DEBUG IS_ENABLED + zASSERT(asyncio->fsm.sp[-1] == FSM_STACK_BOUNDARY); + asyncio->mycache = NULL; +#endif + CONTROL_FREE(asyncio); +} + +void LB_freeAsyncioRA (Asyncio_s *asyncio) +{ + ASSERT_MPKNSS_LOCK(); + +#if NSS_DEBUG IS_ENABLED + zASSERT(asyncio->fsm.sp[-1] == FSM_STACK_BOUNDARY); + asyncio->mycache = NULL; +#endif + CONTROL_FREE(asyncio); +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 15d41b0..3a3666b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -27,6 +27,7 @@ if(MARS_NWE_BUILD_NWFS_TESTS) add_subdirectory(core/worktodo) add_subdirectory(core/alarm) add_subdirectory(core/control) + add_subdirectory(core/asyncio) add_subdirectory(core/config) add_subdirectory(core/parse) add_subdirectory(core/fsm) diff --git a/tests/core/CMakeLists.txt b/tests/core/CMakeLists.txt index 76b961e..f043c47 100644 --- a/tests/core/CMakeLists.txt +++ b/tests/core/CMakeLists.txt @@ -13,6 +13,7 @@ add_subdirectory(schedule) add_subdirectory(worktodo) add_subdirectory(alarm) add_subdirectory(control) +add_subdirectory(asyncio) add_subdirectory(config) add_subdirectory(parse) add_subdirectory(fsm) diff --git a/tests/core/asyncio/CMakeLists.txt b/tests/core/asyncio/CMakeLists.txt new file mode 100644 index 0000000..8d3f96a --- /dev/null +++ b/tests/core/asyncio/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable(test_nwcore_asyncio test_nwcore_asyncio.c) +target_link_libraries(test_nwcore_asyncio PRIVATE mars_nwe::core) +add_test(NAME nwcore.asyncio COMMAND test_nwcore_asyncio) diff --git a/tests/core/asyncio/test_nwcore_asyncio.c b/tests/core/asyncio/test_nwcore_asyncio.c new file mode 100644 index 0000000..079cda0 --- /dev/null +++ b/tests/core/asyncio/test_nwcore_asyncio.c @@ -0,0 +1,45 @@ +#include +#include +#include +#include + +#include + +#define CHECK(expr) \ + do { \ + if (!(expr)) { \ + fprintf(stderr, "CHECK failed: %s:%d: %s\n", __FILE__, __LINE__, #expr); \ + return 1; \ + } \ + } while (0) + +int main(void) +{ + configStartup(); + Config.cache.numAsyncios = 2; + + MPKNSS_LOCK(); + CHECK(ASYNCIO_Startup() == zOK); + + Asyncio_s *first = LB_getAsyncioNoWait(); + Asyncio_s *second = LB_getAsyncioNoWait(); + CHECK(first != NULL); + CHECK(second != NULL); + CHECK(first != second); + CHECK(LB_getAsyncioNoWait() == NULL); + CHECK(first->status == zOK); + CHECK(second->status == zOK); + + LB_freeAsyncio(first); + CHECK(LB_getAsyncioNoWait() == first); + LB_freeAsyncio(first); + LB_freeAsyncio(second); + + Asyncio_s *ra = LB_getAsyncioNoWaitRA(); + CHECK(ra != NULL); + LB_freeAsyncioRA(ra); + + ASYNCIO_Shutdown(); + MPKNSS_UNLOCK(); + return 0; +}