07-07-2026
39 lines
1.4 kB
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* dongle_utils.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: mleitao <marvin@42.fr> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2026/07/07 01:51:14 by mleitao #+# #+# */
9/* Updated: 2026/07/07 01:52:55 by mleitao ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "codexion.h"
14#include "dongle.h"
15
16int take_dongles(t_coder *c)
17{
18 t_dongle *first;
19 t_dongle *second;
20
21 first = c->left;
22 second = c->right;
23 if (second->id < first->id)
24 {
25 first = c->right;
26 second = c->left;
27 }
28 if (dongle_acquire(c, first) != 0)
29 return (-1);
30 if (dongle_acquire(c, second) != 0)
31 return (dongle_release(c, first), -1);
32 return (0);
33}
34
35void put_dongles(t_coder *c)
36{
37 dongle_release(c, c->left);
38 dongle_release(c, c->right);
39}