| 1 |
/* |
| 2 |
* Copyright (C) 2006 by Latchesar Ionkov <[email protected]> |
| 3 |
* Copyright (C) 2010-2014 by Lawrence Livermore National Security, LLC. |
| 4 |
* |
| 5 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 6 |
* copy of this software and associated documentation files (the "Software"), |
| 7 |
* to deal in the Software without restriction, including without limitation |
| 8 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 10 |
* Software is furnished to do so, subject to the following conditions: |
| 11 |
* |
| 12 |
* The above copyright notice and this permission notice (including the next |
| 13 |
* paragraph) shall be included in all copies or substantial portions of the |
| 14 |
* Software. |
| 15 |
* |
| 16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 |
* PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 20 |
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 21 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 |
* DEALINGS IN THE SOFTWARE. |
| 23 |
*/ |
| 24 |
|
| 25 |
typedef int (*RpcFun)(Npcfsys *fs, Npfcall *tc, Npfcall **rc); |
| 26 |
typedef void (*RefFun)(Npcfsys *fs); |
| 27 |
typedef void (*DiscFun)(Npcfsys *fs); |
| 28 |
|
| 29 |
typedef struct Npcreq Npcreq; |
| 30 |
typedef struct Npcpool Npcpool; |
| 31 |
|
| 32 |
struct Npcreq { |
| 33 |
Npcfsys* fsys; |
| 34 |
|
| 35 |
u16 tag; |
| 36 |
Npfcall* tc; |
| 37 |
Npfcall* rc; |
| 38 |
|
| 39 |
int ecode; |
| 40 |
|
| 41 |
void (*cb)(Npcreq *, void *); |
| 42 |
void* cba; |
| 43 |
|
| 44 |
int flushed; |
| 45 |
Npcreq* next; |
| 46 |
Npcreq* prev; |
| 47 |
}; |
| 48 |
|
| 49 |
struct Npcpool { |
| 50 |
pthread_mutex_t lock; |
| 51 |
pthread_cond_t cond; |
| 52 |
u32 maxid; |
| 53 |
int msize; |
| 54 |
u8* map; |
| 55 |
}; |
| 56 |
|
| 57 |
struct Npcfsys { |
| 58 |
pthread_mutex_t lock; |
| 59 |
|
| 60 |
int flags; |
| 61 |
u32 msize; |
| 62 |
Nptrans* trans; |
| 63 |
|
| 64 |
int refcount; |
| 65 |
Npcpool* tagpool; |
| 66 |
Npcpool* fidpool; |
| 67 |
|
| 68 |
RpcFun rpc; |
| 69 |
RefFun incref; |
| 70 |
RefFun decref; |
| 71 |
DiscFun disconnect; |
| 72 |
|
| 73 |
/* mtfsys only */ |
| 74 |
pthread_cond_t cond; |
| 75 |
|
| 76 |
Npcreq* unsent_first; |
| 77 |
Npcreq* unsent_last; |
| 78 |
Npcreq* pend_first; |
| 79 |
|
| 80 |
pthread_t readproc; |
| 81 |
pthread_t writeproc; |
| 82 |
|
| 83 |
int rfd; |
| 84 |
int wfd; |
| 85 |
}; |
| 86 |
|
| 87 |
Npcfsys *npc_create_fsys(int rfd, int wfd, int msize, int flags); |
| 88 |
Npcfsys *npc_create_mtfsys(int rfd, int wfd, int msize, int flags); |
| 89 |
|
| 90 |
Npcpool *npc_create_pool(u32 maxid); |
| 91 |
void npc_destroy_pool(Npcpool *p); |
| 92 |
u32 npc_get_id(Npcpool *p); |
| 93 |
void npc_put_id(Npcpool *p, u32 id); |
| 94 |
|
| 95 |
Npcfid *npc_fid_alloc(Npcfsys *fs); |
| 96 |
void npc_fid_free(Npcfid *fid); |