xref: /haiku/src/tools/fs_shell/sem.cpp (revision adb0d19d561947362090081e81d90dde59142026)
1 /*
2  * Copyright 2007, Ingo Weinhold, bonefish@cs.tu-berlin.de.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 #include "compatibility.h"
7 
8 #include <string.h>
9 
10 #include <OS.h>
11 
12 #include "fssh_errors.h"
13 #include "fssh_os.h"
14 
15 
16 static void
17 copy_sem_info(fssh_sem_info* info, const sem_info* systemInfo)
18 {
19 	info->sem = systemInfo->sem;
20 	info->team = systemInfo->team;
21 	strcpy(info->name, systemInfo->name);
22 	info->count = systemInfo->count;
23 	info->latest_holder = systemInfo->latest_holder;
24 }
25 
26 
27 // #pragma mark -
28 
29 
30 fssh_sem_id
31 fssh_create_sem(int32_t count, const char *name)
32 {
33 	return create_sem(count, name);
34 }
35 
36 
37 fssh_status_t
38 fssh_delete_sem(fssh_sem_id id)
39 {
40 	return delete_sem(id);
41 }
42 
43 
44 fssh_status_t
45 fssh_acquire_sem(fssh_sem_id id)
46 {
47 	return acquire_sem(id);
48 }
49 
50 
51 fssh_status_t
52 fssh_acquire_sem_etc(fssh_sem_id id, int32_t count, uint32_t flags,
53 	fssh_bigtime_t timeout)
54 {
55 	return acquire_sem_etc(id, count, flags, timeout);
56 }
57 
58 
59 fssh_status_t
60 fssh_release_sem(fssh_sem_id id)
61 {
62 	return release_sem(id);
63 }
64 
65 
66 fssh_status_t
67 fssh_release_sem_etc(fssh_sem_id id, int32_t count, uint32_t flags)
68 {
69 	return release_sem_etc(id, count, flags);
70 }
71 
72 
73 fssh_status_t
74 fssh_get_sem_count(fssh_sem_id id, int32_t *threadCount)
75 {
76 	return get_sem_count(id, (int32*)threadCount);
77 }
78 
79 
80 fssh_status_t
81 fssh_set_sem_owner(fssh_sem_id id, fssh_team_id team)
82 {
83 	// return set_sem_owner(id, team);
84 	// The FS shell is the kernel and no other teams exist.
85 	return FSSH_B_OK;
86 }
87 
88 
89 fssh_status_t
90 _fssh_get_sem_info(fssh_sem_id id, struct fssh_sem_info *info,
91 	fssh_size_t infoSize)
92 {
93 	sem_info systemInfo;
94 	status_t result = get_sem_info(id, &systemInfo);
95 	if (result != B_OK)
96 		return result;
97 
98 	copy_sem_info(info, &systemInfo);
99 
100 	return FSSH_B_OK;
101 }
102 
103 
104 fssh_status_t
105 _fssh_get_next_sem_info(fssh_team_id team, int32_t *cookie,
106 	struct fssh_sem_info *info, fssh_size_t infoSize)
107 {
108 	sem_info systemInfo;
109 	status_t result = get_next_sem_info(team, (int32*)cookie, &systemInfo);
110 	if (result != B_OK)
111 		return result;
112 
113 	copy_sem_info(info, &systemInfo);
114 
115 	return FSSH_B_OK;
116 }
117 
118