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