/*********************************************************************** * Code listing from "Advanced Linux Programming," by CodeSourcery LLC * * Copyright (C) 2001 by New Riders Publishing * * See COPYRIGHT for license information. * ***********************************************************************/ #include #include #include /* We must define union semun ourselves. */ union semun { int val; struct semid_ds *buf; unsigned short int *array; struct seminfo *__buf; }; /* Initialize a binary semaphore with a value of one. */ int binary_semaphore_initialize (int semid) { union semun argument; unsigned short values[1]; values[0] = 1; argument.array = values; return semctl (semid, 0, SETALL, argument); }