start service tasks separately in-case platforms need to perform additional set-up...
[AROS.git] / rom / dos / attemptlockdoslist.c
blobf3e7badd5e43a84ffaf2cff1d4d057e7219e7709
1 /*
2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
8 #include <aros/debug.h>
9 #include <proto/exec.h>
10 #include "dos_intern.h"
12 /*****************************************************************************
14 NAME */
15 #include <proto/dos.h>
17 AROS_LH1(struct DosList *, AttemptLockDosList,
19 /* SYNOPSIS */
20 AROS_LHA(ULONG, flags, D1),
22 /* LOCATION */
23 struct DosLibrary *, DOSBase, 111, Dos)
25 /* FUNCTION
26 Tries to get a lock on some of the dos lists. If all went
27 well a handle is returned that can be used for FindDosEntry().
28 Don't try to busy wait until the lock can be granted - use
29 LockDosList() instead.
31 INPUTS
32 flags -- what lists to lock
34 RESULT
35 Handle to the dos list or NULL. This is not a direct pointer
36 to the first list element but to a pseudo element instead.
38 NOTES
40 EXAMPLE
42 BUGS
44 SEE ALSO
46 INTERNALS
48 *****************************************************************************/
50 AROS_LIBFUNC_INIT
52 struct DosInfo *di = BADDR(DOSBase->dl_Root->rn_Info);
53 struct DosList *dl = (struct DosList *)&di->di_DevInfo;
54 ULONG DevSem = FALSE, EntrySem = FALSE, DelSem = FALSE;
56 D(bug("AttemptLockDosList: flags = $%lx\n", flags));
58 if (((flags & (LDF_READ|LDF_WRITE)) != LDF_READ &&
59 (flags & (LDF_READ|LDF_WRITE)) != LDF_WRITE) ||
60 (flags & ~(LDF_READ|LDF_WRITE|LDF_DEVICES|LDF_VOLUMES|LDF_ASSIGNS|LDF_ENTRY|LDF_DELETE)))
61 return NULL;
63 if (flags & LDF_ALL)
65 if (flags & LDF_WRITE)
66 DevSem = AttemptSemaphore(&di->di_DevLock);
67 else
68 DevSem = AttemptSemaphoreShared(&di->di_DevLock);
69 if (!DevSem)
70 dl = NULL;
73 if (flags & LDF_ENTRY)
75 if (flags & LDF_WRITE)
76 EntrySem = AttemptSemaphore(&di->di_EntryLock);
77 else
78 EntrySem = AttemptSemaphoreShared(&di->di_EntryLock);
79 if (!EntrySem)
80 dl = NULL;
83 if (flags & LDF_DELETE)
85 if (flags & LDF_WRITE)
86 DelSem = AttemptSemaphore(&di->di_DeleteLock);
87 else
88 DelSem = AttemptSemaphoreShared(&di->di_DeleteLock);
89 if (!DelSem)
90 dl = NULL;
93 /* This came from MorphOS source code, however looks strange.
94 Commented out but left for reference.
95 if (dl)
96 Forbid(); */
97 if (!dl) {
98 if (DevSem)
99 ReleaseSemaphore(&di->di_DevLock);
100 if (EntrySem)
101 ReleaseSemaphore(&di->di_EntryLock);
102 if (DelSem)
103 ReleaseSemaphore(&di->di_DeleteLock);
106 D(bug("AttemptLockDosList: result = $%lx\n", dl));
108 return dl;
110 AROS_LIBFUNC_EXIT
111 } /* AttemptLockDosList */