ReactOS  0.4.13-dev-464-g6b95727
sys.h File Reference
#include "lwip/opt.h"
#include "lwip/err.h"
#include "arch/sys_arch.h"
Include dependency graph for sys.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SYS_ARCH_TIMEOUT   0xffffffffUL
 
#define SYS_MBOX_EMPTY   SYS_ARCH_TIMEOUT
 
#define sys_sem_wait(sem)   sys_arch_sem_wait(sem, 0)
 
#define sys_mbox_tryfetch(mbox, msg)   sys_arch_mbox_tryfetch(mbox, msg)
 
#define sys_mbox_fetch(mbox, msg)   sys_arch_mbox_fetch(mbox, msg, 0)
 
#define SYS_ARCH_DECL_PROTECT(lev)
 
#define SYS_ARCH_PROTECT(lev)
 
#define SYS_ARCH_UNPROTECT(lev)
 
#define SYS_ARCH_INC(var, val)
 
#define SYS_ARCH_DEC(var, val)
 
#define SYS_ARCH_GET(var, ret)
 
#define SYS_ARCH_SET(var, val)
 

Typedefs

typedef void(* lwip_thread_fn) (void *arg)
 

Functions

err_t sys_mutex_new (sys_mutex_t *mutex)
 
void sys_mutex_lock (sys_mutex_t *mutex)
 
void sys_mutex_unlock (sys_mutex_t *mutex)
 
void sys_mutex_free (sys_mutex_t *mutex)
 
int sys_mutex_valid (sys_mutex_t *mutex)
 
void sys_mutex_set_invalid (sys_mutex_t *mutex)
 
err_t sys_sem_new (sys_sem_t *sem, u8_t count)
 
void sys_sem_signal (sys_sem_t *sem)
 
u32_t sys_arch_sem_wait (sys_sem_t *sem, u32_t timeout)
 
void sys_sem_free (sys_sem_t *sem)
 
int sys_sem_valid (sys_sem_t *sem)
 
void sys_sem_set_invalid (sys_sem_t *sem)
 
void sys_msleep (u32_t ms)
 
err_t sys_mbox_new (sys_mbox_t *mbox, int size)
 
void sys_mbox_post (sys_mbox_t *mbox, void *msg)
 
err_t sys_mbox_trypost (sys_mbox_t *mbox, void *msg)
 
u32_t sys_arch_mbox_fetch (sys_mbox_t *mbox, void **msg, u32_t timeout)
 
u32_t sys_arch_mbox_tryfetch (sys_mbox_t *mbox, void **msg)
 
void sys_mbox_free (sys_mbox_t *mbox)
 
int sys_mbox_valid (sys_mbox_t *mbox)
 
void sys_mbox_set_invalid (sys_mbox_t *mbox)
 
sys_thread_t sys_thread_new (const char *name, lwip_thread_fn thread, void *arg, int stacksize, int prio)
 
void sys_init (void)
 
u32_t sys_jiffies (void)
 
u32_t sys_now (void)
 

Macro Definition Documentation

◆ SYS_ARCH_DEC

#define SYS_ARCH_DEC (   var,
  val 
)
Value:
do { \
SYS_ARCH_DECL_PROTECT(old_level); \
SYS_ARCH_PROTECT(old_level); \
var -= val; \
SYS_ARCH_UNPROTECT(old_level); \
} while(0)
GLuint GLfloat * val
Definition: glext.h:7180

Definition at line 306 of file sys.h.

◆ SYS_ARCH_DECL_PROTECT

#define SYS_ARCH_DECL_PROTECT (   lev)

SYS_LIGHTWEIGHT_PROT define SYS_LIGHTWEIGHT_PROT in lwipopts.h if you want inter-task protection for certain critical regions during buffer allocation, deallocation and memory allocation and deallocation.

Definition at line 283 of file sys.h.

◆ SYS_ARCH_GET

#define SYS_ARCH_GET (   var,
  ret 
)
Value:
do { \
SYS_ARCH_DECL_PROTECT(old_level); \
SYS_ARCH_PROTECT(old_level); \
ret = var; \
SYS_ARCH_UNPROTECT(old_level); \
} while(0)

Definition at line 315 of file sys.h.

◆ SYS_ARCH_INC

#define SYS_ARCH_INC (   var,
  val 
)
Value:
do { \
SYS_ARCH_DECL_PROTECT(old_level); \
SYS_ARCH_PROTECT(old_level); \
var += val; \
SYS_ARCH_UNPROTECT(old_level); \
} while(0)
GLuint GLfloat * val
Definition: glext.h:7180

Definition at line 297 of file sys.h.

◆ SYS_ARCH_PROTECT

#define SYS_ARCH_PROTECT (   lev)

Definition at line 284 of file sys.h.

◆ SYS_ARCH_SET

#define SYS_ARCH_SET (   var,
  val 
)
Value:
do { \
SYS_ARCH_DECL_PROTECT(old_level); \
SYS_ARCH_PROTECT(old_level); \
var = val; \
SYS_ARCH_UNPROTECT(old_level); \
} while(0)
GLuint GLfloat * val
Definition: glext.h:7180

Definition at line 324 of file sys.h.

◆ SYS_ARCH_TIMEOUT

#define SYS_ARCH_TIMEOUT   0xffffffffUL

Return code for timeouts from sys_arch_mbox_fetch and sys_arch_sem_wait

Definition at line 78 of file sys.h.

◆ SYS_ARCH_UNPROTECT

#define SYS_ARCH_UNPROTECT (   lev)

Definition at line 285 of file sys.h.

◆ SYS_MBOX_EMPTY

#define SYS_MBOX_EMPTY   SYS_ARCH_TIMEOUT

sys_mbox_tryfetch() returns SYS_MBOX_EMPTY if appropriate. For now we use the same magic value, but we allow this to change in future.

Definition at line 83 of file sys.h.

◆ sys_mbox_fetch

#define sys_mbox_fetch (   mbox,
  msg 
)    sys_arch_mbox_fetch(mbox, msg, 0)

Definition at line 207 of file sys.h.

◆ sys_mbox_tryfetch

#define sys_mbox_tryfetch (   mbox,
  msg 
)    sys_arch_mbox_tryfetch(mbox, msg)

For now, we map straight to sys_arch implementation.

Definition at line 203 of file sys.h.

◆ sys_sem_wait

#define sys_sem_wait (   sem)    sys_arch_sem_wait(sem, 0)

Wait for a semaphore - forever/no timeout

Definition at line 153 of file sys.h.

Typedef Documentation

◆ lwip_thread_fn

typedef void(* lwip_thread_fn) (void *arg)

Function prototype for thread functions

Definition at line 89 of file sys.h.

Function Documentation

◆ sys_arch_mbox_fetch()

u32_t sys_arch_mbox_fetch ( sys_mbox_t mbox,
void **  msg,
u32_t  timeout 
)

Wait for a new message to arrive in the mbox

Parameters
mboxmbox to get a message from
msgpointer where the message is stored
timeoutmaximum time (in milliseconds) to wait for a message
Returns
time (in milliseconds) waited for a message, may be 0 if not waited or SYS_ARCH_TIMEOUT on timeout The returned time has to be accurate to prevent timer jitter!

Definition at line 182 of file sys_arch.c.

183 {
184  LARGE_INTEGER LargeTimeout, PreWaitTime, PostWaitTime;
185  UINT64 TimeDiff;
187  PVOID Message;
188  PLWIP_MESSAGE_CONTAINER Container;
190  KIRQL OldIrql;
191  PVOID WaitObjects[] = {&mbox->Event, &TerminationEvent};
192 
193  LargeTimeout.QuadPart = Int32x32To64(timeout, -10000);
194 
195  KeQuerySystemTime(&PreWaitTime);
196 
198  WaitObjects,
199  WaitAny,
200  Executive,
201  KernelMode,
202  FALSE,
203  timeout != 0 ? &LargeTimeout : NULL,
204  NULL);
205 
206  if (Status == STATUS_WAIT_0)
207  {
210  ASSERT(Entry);
211  if (IsListEmpty(&mbox->ListHead))
214 
215  Container = CONTAINING_RECORD(Entry, LWIP_MESSAGE_CONTAINER, ListEntry);
216  Message = Container->Message;
217  ExFreePool(Container);
218 
219  if (msg)
220  *msg = Message;
221 
222  KeQuerySystemTime(&PostWaitTime);
223  TimeDiff = PostWaitTime.QuadPart - PreWaitTime.QuadPart;
224  TimeDiff /= 10000;
225 
226  return TimeDiff;
227  }
228  else if (Status == STATUS_WAIT_1)
229  {
230  /* DON'T remove ourselves from the thread list! */
232 
233  /* We should never get here! */
234  ASSERT(FALSE);
235 
236  return 0;
237  }
238 
239  return SYS_ARCH_TIMEOUT;
240 }
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
KEVENT Event
Definition: sys_arch.h:14
LIST_ENTRY ListHead
Definition: sys_arch.h:13
struct _Entry Entry
Definition: kefuncs.h:640
LONG NTSTATUS
Definition: precomp.h:26
#define SYS_ARCH_TIMEOUT
Definition: sys.h:78
Definition: dhcpd.h:245
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define STATUS_WAIT_1
Definition: ntstatus.h:71
#define STATUS_WAIT_0
Definition: ntstatus.h:223
smooth NULL
Definition: ftsmooth.c:416
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
KEVENT TerminationEvent
Definition: sys_arch.c:14
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
NTSTATUS NTAPI KeWaitForMultipleObjects(IN ULONG Count, IN PVOID Object[], IN WAIT_TYPE WaitType, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL, OUT PKWAIT_BLOCK WaitBlockArray OPTIONAL)
Definition: wait.c:586
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
CHAR Message[80]
Definition: alive.c:5
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI PsTerminateSystemThread(IN NTSTATUS ExitStatus)
Definition: kill.c:1144
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define msg(x)
Definition: auth_time.c:54
unsigned long long UINT64
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
return STATUS_SUCCESS
Definition: btrfs.c:2777
static sys_mbox_t mbox
Definition: tcpip.c:56
base of all file and directory entries
Definition: entries.h:82
#define Int32x32To64(a, b)
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
KSPIN_LOCK Lock
Definition: sys_arch.h:12
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by sys_arch_mbox_tryfetch().

◆ sys_arch_mbox_tryfetch()

u32_t sys_arch_mbox_tryfetch ( sys_mbox_t mbox,
void **  msg 
)

Wait for a new message to arrive in the mbox

Parameters
mboxmbox to get a message from
msgpointer where the message is stored
timeoutmaximum time (in milliseconds) to wait for a message
Returns
0 (milliseconds) if a message has been received or SYS_MBOX_EMPTY if the mailbox is empty

Definition at line 243 of file sys_arch.c.

244 {
246  return 0;
247  else
248  return SYS_MBOX_EMPTY;
249 }
#define SYS_ARCH_TIMEOUT
Definition: sys.h:78
u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout)
Definition: sys_arch.c:182
#define SYS_MBOX_EMPTY
Definition: sys.h:83
#define msg(x)
Definition: auth_time.c:54
static sys_mbox_t mbox
Definition: tcpip.c:56

◆ sys_arch_sem_wait()

u32_t sys_arch_sem_wait ( sys_sem_t sem,
u32_t  timeout 
)

Wait for a semaphore for the specified timeout

Parameters
semthe semaphore to wait for
timeouttimeout in milliseconds to wait (0 = wait forever)
Returns
time (in milliseconds) waited for the semaphore or SYS_ARCH_TIMEOUT on timeout

Definition at line 91 of file sys_arch.c.

92 {
93  LARGE_INTEGER LargeTimeout, PreWaitTime, PostWaitTime;
94  UINT64 TimeDiff;
96  PVOID WaitObjects[] = {&sem->Event, &TerminationEvent};
97 
98  LargeTimeout.QuadPart = Int32x32To64(timeout, -10000);
99 
100  KeQuerySystemTime(&PreWaitTime);
101 
103  WaitObjects,
104  WaitAny,
105  Executive,
106  KernelMode,
107  FALSE,
108  timeout != 0 ? &LargeTimeout : NULL,
109  NULL);
110  if (Status == STATUS_WAIT_0)
111  {
112  KeQuerySystemTime(&PostWaitTime);
113  TimeDiff = PostWaitTime.QuadPart - PreWaitTime.QuadPart;
114  TimeDiff /= 10000;
115 
116  return TimeDiff;
117  }
118  else if (Status == STATUS_WAIT_1)
119  {
120  /* DON'T remove ourselves from the thread list! */
122 
123  /* We should never get here! */
124  ASSERT(FALSE);
125 
126  return 0;
127  }
128 
129  return SYS_ARCH_TIMEOUT;
130 }
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
LONG NTSTATUS
Definition: precomp.h:26
#define SYS_ARCH_TIMEOUT
Definition: sys.h:78
Definition: dhcpd.h:245
#define STATUS_WAIT_1
Definition: ntstatus.h:71
#define STATUS_WAIT_0
Definition: ntstatus.h:223
smooth NULL
Definition: ftsmooth.c:416
KEVENT TerminationEvent
Definition: sys_arch.c:14
NTSTATUS NTAPI KeWaitForMultipleObjects(IN ULONG Count, IN PVOID Object[], IN WAIT_TYPE WaitType, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL, OUT PKWAIT_BLOCK WaitBlockArray OPTIONAL)
Definition: wait.c:586
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
static HANDLE sem
Definition: sync.c:677
NTSTATUS NTAPI PsTerminateSystemThread(IN NTSTATUS ExitStatus)
Definition: kill.c:1144
unsigned long long UINT64
return STATUS_SUCCESS
Definition: btrfs.c:2777
#define Int32x32To64(a, b)
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by sys_msleep().

◆ sys_init()

void sys_init ( void  )

Definition at line 310 of file sys_arch.c.

311 {
314 
316 
318 
320  NULL,
321  NULL,
322  0,
323  sizeof(struct lwip_callback_msg),
325  0);
326 
328  NULL,
329  NULL,
330  0,
331  sizeof(QUEUE_ENTRY),
333  0);
334 }
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
NPAGED_LOOKASIDE_LIST MessageLookasideList
Definition: sys_arch.c:15
#define LWIP_QUEUE_TAG
Definition: rosip.h:12
static LARGE_INTEGER StartTime
Definition: sys_arch.c:18
Definition: rosip.h:17
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
smooth NULL
Definition: ftsmooth.c:416
KEVENT TerminationEvent
Definition: sys_arch.c:14
VOID NTAPI ExInitializeNPagedLookasideList(IN PNPAGED_LOOKASIDE_LIST Lookaside, IN PALLOCATE_FUNCTION Allocate OPTIONAL, IN PFREE_FUNCTION Free OPTIONAL, IN ULONG Flags, IN SIZE_T Size, IN ULONG Tag, IN USHORT Depth)
Definition: lookas.c:222
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define LWIP_MESSAGE_TAG
Definition: rosip.h:11
NPAGED_LOOKASIDE_LIST QueueEntryLookasideList
Definition: sys_arch.c:16
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
static KSPIN_LOCK ThreadListLock
Definition: sys_arch.c:12
static LIST_ENTRY ThreadListHead
Definition: sys_arch.c:11

Referenced by lwip_init().

◆ sys_jiffies()

u32_t sys_jiffies ( void  )

Ticks/jiffies since power up.

◆ sys_mbox_free()

void sys_mbox_free ( sys_mbox_t mbox)

Delete an mbox

Parameters
mboxmbox to delete

Definition at line 157 of file sys_arch.c.

158 {
160 
162 }
LIST_ENTRY ListHead
Definition: sys_arch.h:13
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
void sys_mbox_set_invalid(sys_mbox_t *mbox)
Definition: sys_arch.c:151
static sys_mbox_t mbox
Definition: tcpip.c:56

◆ sys_mbox_new()

err_t sys_mbox_new ( sys_mbox_t mbox,
int  size 
)

Create a new mbox of specified size

Parameters
mboxpointer to the mbox to create
size(miminum) number of messages in this mbox
Returns
ERR_OK if successful, another err_t otherwise

Definition at line 133 of file sys_arch.c.

134 {
136 
138 
140 
141  mbox->Valid = 1;
142 
143  return ERR_OK;
144 }
KEVENT Event
Definition: sys_arch.h:14
LIST_ENTRY ListHead
Definition: sys_arch.h:13
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
#define ERR_OK
Definition: err.h:52
int Valid
Definition: sys_arch.h:15
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
static sys_mbox_t mbox
Definition: tcpip.c:56
KSPIN_LOCK Lock
Definition: sys_arch.h:12

Referenced by tcpip_init().

◆ sys_mbox_post()

void sys_mbox_post ( sys_mbox_t mbox,
void msg 
)

Post a message to an mbox - may not fail -> blocks if full, only used from tasks not from ISR

Parameters
mboxmbox to posts the message
msgmessage to post (ATTENTION: can be NULL)

Definition at line 165 of file sys_arch.c.

166 {
167  PLWIP_MESSAGE_CONTAINER Container;
168 
169  Container = ExAllocatePool(NonPagedPool, sizeof(*Container));
170  ASSERT(Container);
171 
172  Container->Message = msg;
173 
175  &Container->ListEntry,
176  &mbox->Lock);
177 
179 }
KEVENT Event
Definition: sys_arch.h:14
LIST_ENTRY ListEntry
Definition: sys_arch.h:25
LIST_ENTRY ListHead
Definition: sys_arch.h:13
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define msg(x)
Definition: auth_time.c:54
#define IO_NO_INCREMENT
Definition: iotypes.h:565
static sys_mbox_t mbox
Definition: tcpip.c:56
KSPIN_LOCK Lock
Definition: sys_arch.h:12

Referenced by sys_mbox_trypost(), and tcpip_callback_with_block().

◆ sys_mbox_set_invalid()

void sys_mbox_set_invalid ( sys_mbox_t mbox)

Set an mbox invalid so that sys_mbox_valid returns 0

Definition at line 151 of file sys_arch.c.

152 {
153  mbox->Valid = 0;
154 }
int Valid
Definition: sys_arch.h:15
static sys_mbox_t mbox
Definition: tcpip.c:56

Referenced by sys_mbox_free().

◆ sys_mbox_trypost()

err_t sys_mbox_trypost ( sys_mbox_t mbox,
void msg 
)

Try to post a message to an mbox - may fail if full or ISR

Parameters
mboxmbox to posts the message
msgmessage to post (ATTENTION: can be NULL)

Definition at line 252 of file sys_arch.c.

253 {
255 
256  return ERR_OK;
257 }
#define ERR_OK
Definition: err.h:52
void sys_mbox_post(sys_mbox_t *mbox, void *msg)
Definition: sys_arch.c:165
#define msg(x)
Definition: auth_time.c:54
static sys_mbox_t mbox
Definition: tcpip.c:56

Referenced by tcpip_callback_with_block(), tcpip_input(), and tcpip_trycallback().

◆ sys_mbox_valid()

int sys_mbox_valid ( sys_mbox_t mbox)

Check if an mbox is valid/allocated: return 1 for valid, 0 for invalid

Definition at line 146 of file sys_arch.c.

147 {
148  return mbox->Valid;
149 }
int Valid
Definition: sys_arch.h:15
static sys_mbox_t mbox
Definition: tcpip.c:56

Referenced by tcpip_callback_with_block(), tcpip_input(), and tcpip_trycallback().

◆ sys_msleep()

void sys_msleep ( u32_t  ms)

Sleep for some ms. Timeouts are NOT processed while sleeping.

Parameters
msnumber of milliseconds to sleep

Definition at line 55 of file sys.c.

56 {
57  if (ms > 0) {
58  sys_sem_t delaysem;
59  err_t err = sys_sem_new(&delaysem, 0);
60  if (err == ERR_OK) {
61  sys_arch_sem_wait(&delaysem, ms);
62  sys_sem_free(&delaysem);
63  }
64  }
65 }
void sys_sem_free(sys_sem_t *sem)
Definition: sys_arch.c:77
err_t sys_sem_new(sys_sem_t *sem, u8_t count)
Definition: sys_arch.c:51
s8_t err_t
Definition: err.h:47
#define ERR_OK
Definition: err.h:52
#define err(...)
u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout)
Definition: sys_arch.c:91

◆ sys_mutex_free()

void sys_mutex_free ( sys_mutex_t *  mutex)

Delete a semaphore

Parameters
mutexthe mutex to delete

◆ sys_mutex_lock()

void sys_mutex_lock ( sys_mutex_t *  mutex)

Lock a mutex

Parameters
mutexthe mutex to lock

Referenced by mem_malloc().

◆ sys_mutex_new()

err_t sys_mutex_new ( sys_mutex_t *  mutex)

Define LWIP_COMPAT_MUTEX if the port has no mutexes and binary semaphores should be used instead Create a new mutex

Parameters
mutexpointer to the mutex to create
Returns
a new mutex

Referenced by mem_init(), and tcpip_init().

◆ sys_mutex_set_invalid()

void sys_mutex_set_invalid ( sys_mutex_t *  mutex)

Set a mutex invalid so that sys_mutex_valid returns 0

◆ sys_mutex_unlock()

void sys_mutex_unlock ( sys_mutex_t *  mutex)

Unlock a mutex

Parameters
mutexthe mutex to unlock

Referenced by mem_malloc().

◆ sys_mutex_valid()

int sys_mutex_valid ( sys_mutex_t *  mutex)

Check if a mutex is valid/allocated: return 1 for valid, 0 for invalid

◆ sys_now()

u32_t sys_now ( void  )

Returns the current time in milliseconds, may be the same as sys_jiffies or at least based on it.

Definition at line 28 of file sys_arch.c.

29 {
30  LARGE_INTEGER CurrentTime;
31 
32  KeQuerySystemTime(&CurrentTime);
33 
34  return (CurrentTime.QuadPart - StartTime.QuadPart) / 10000;
35 }
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
static LARGE_INTEGER StartTime
Definition: sys_arch.c:18
LONGLONG QuadPart
Definition: typedefs.h:112

◆ sys_sem_free()

void sys_sem_free ( sys_sem_t sem)

Delete a semaphore

Parameters
semsemaphore to delete

Definition at line 77 of file sys_arch.c.

78 {
79  /* No op (allocated in stack) */
80 
82 }
void sys_sem_set_invalid(sys_sem_t *sem)
Definition: sys_arch.c:71
static HANDLE sem
Definition: sync.c:677

Referenced by sys_msleep().

◆ sys_sem_new()

err_t sys_sem_new ( sys_sem_t sem,
u8_t  count 
)

Create a new semaphore

Parameters
sempointer to the semaphore to create
countinitial count of the semaphore
Returns
ERR_OK if successful, another err_t otherwise

Definition at line 51 of file sys_arch.c.

52 {
53  ASSERT(count == 0 || count == 1);
54 
55  /* It seems lwIP uses the semaphore implementation as either a completion event or a lock
56  * so I optimize for this case by using a synchronization event and setting its initial state
57  * to signalled for a lock and non-signalled for a completion event */
58 
60 
61  sem->Valid = 1;
62 
63  return ERR_OK;
64 }
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define ERR_OK
Definition: err.h:52
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
static HANDLE sem
Definition: sync.c:677

Referenced by sys_msleep().

◆ sys_sem_set_invalid()

void sys_sem_set_invalid ( sys_sem_t sem)

Set a semaphore invalid so that sys_sem_valid returns 0

Definition at line 71 of file sys_arch.c.

72 {
73  sem->Valid = 0;
74 }
static HANDLE sem
Definition: sync.c:677

Referenced by sys_sem_free().

◆ sys_sem_signal()

void sys_sem_signal ( sys_sem_t sem)

Signals a semaphore

Parameters
semthe semaphore to signal

Definition at line 85 of file sys_arch.c.

86 {
88 }
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
static HANDLE sem
Definition: sync.c:677
#define IO_NO_INCREMENT
Definition: iotypes.h:565

◆ sys_sem_valid()

int sys_sem_valid ( sys_sem_t sem)

Check if a sempahore is valid/allocated: return 1 for valid, 0 for invalid

Definition at line 66 of file sys_arch.c.

67 {
68  return sem->Valid;
69 }
static HANDLE sem
Definition: sync.c:677

◆ sys_thread_new()

sys_thread_t sys_thread_new ( const char name,
lwip_thread_fn  thread,
void arg,
int  stacksize,
int  prio 
)

The only thread function: Creates a new thread

Parameters
namehuman-readable name for the thread (used for debugging purposes)
threadthread-function
argparameter passed to 'thread'
stacksizestack size in bytes for the new thread (may be ignored by ports)
priopriority of the new thread (may be ignored by ports)

Definition at line 280 of file sys_arch.c.

281 {
282  thread_t Container;
284 
285  Container = ExAllocatePool(NonPagedPool, sizeof(*Container));
286  if (!Container)
287  return 0;
288 
289  Container->ThreadFunction = thread;
290  Container->ThreadContext = arg;
291 
292  Status = PsCreateSystemThread(&Container->Handle,
294  NULL,
295  NULL,
296  NULL,
298  Container);
299 
300  if (!NT_SUCCESS(Status))
301  {
302  ExFreePool(Container);
303  return 0;
304  }
305 
306  return 0;
307 }
HANDLE Handle
Definition: sys_arch.c:22
#define THREAD_ALL_ACCESS
Definition: nt_native.h:1339
void * ThreadContext
Definition: sys_arch.c:24
LONG NTSTATUS
Definition: precomp.h:26
void * arg
Definition: msvc.h:12
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static HANDLE thread
Definition: service.c:33
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI PsCreateSystemThread(OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE ProcessHandle, IN PCLIENT_ID ClientId, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext)
Definition: thread.c:602
void(* ThreadFunction)(void *arg)
Definition: sys_arch.c:23
VOID NTAPI LwipThreadMain(PVOID Context)
Definition: sys_arch.c:261
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by tcpip_init().