[T106][ZXW-22]7520V3SCV2.01.01.02P42U09_VEC_V0.8_AP_VEC origin source commit
Change-Id: Ic6e05d89ecd62fc34f82b23dcf306c93764aec4b
diff --git a/ap/app/goahead/interface5.0/zte_web_sem.c b/ap/app/goahead/interface5.0/zte_web_sem.c
new file mode 100755
index 0000000..e4e7ea5
--- /dev/null
+++ b/ap/app/goahead/interface5.0/zte_web_sem.c
@@ -0,0 +1,94 @@
+#include <sys/sem.h>
+#include <sys/ipc.h>
+#include <errno.h>
+#include "softap_log.h"
+
+//´Ë´¦È¡ÖµÓëFLUXSTATÎļþÖеÄȡֵÊÇÒ»ÖµÄ
+//ÓÃÓÚ²»Í¬µÄ½ø³Ì¼äͬ²½
+#define TIME_SEM_KEY 0x0666
+
+extern int init_sem(int sem_id, int init_value);
+extern int del_sem(int sem_id);
+extern int sem_p(int sem_id);
+extern int sem_v(int sem_id);
+extern int get_sem(key_t sem_key);
+
+
+union semun {
+ int val;
+ struct semid_ds *buf;
+ unsigned short *array;
+};
+
+int get_sem(key_t sem_key)
+{
+ int sem_id = -1;
+
+ sem_id = semget(sem_key, 1, 0666 | IPC_CREAT | IPC_EXCL);
+ if (sem_id < 0) {
+ //printf("[goahead]semget errno=%d\n", errno);
+ if (errno == EEXIST) {
+ //printf("[goahead]semget already exist==\n");
+ return semget(sem_key, 1, 0666 | IPC_CREAT);
+ }
+ slog(MISC_PRINT, SLOG_ERR,"[goahead]semget == -1, return fail\n");
+ return -1;
+ }
+
+ union semun sem_union;
+ sem_union.val = 1;
+ if (semctl(sem_id, 0, SETVAL, sem_union) == -1) {
+ return -1;
+ }
+ //printf("[goahead]semget sem_id= %d, get sem success\n",sem_id);;
+ return sem_id;
+}
+
+
+// ½«ÐźÅÁ¿sem_idÉèÖÃΪinit_value
+int init_sem(int sem_id, int init_value)
+{
+ union semun sem_union;
+ sem_union.val = init_value;
+ if (semctl(sem_id, 0, SETVAL, sem_union) == -1) {
+ return -1;
+ }
+ return 0;
+}
+
+// ɾ³ýsem_idÐźÅÁ¿
+int del_sem(int sem_id)
+{
+ union semun sem_union = {0}; //cov h
+ if (semctl(sem_id, 0, IPC_RMID, sem_union) == -1) {
+ return -1;
+ }
+ return 0;
+}
+
+// ¶Ôsem_idÖ´ÐÐp²Ù×÷
+int sem_p(int sem_id)
+{
+ struct sembuf sem_buf;
+ sem_buf.sem_num = 0; //ÐźÅÁ¿±àºÅ
+ sem_buf.sem_op = -1; //P²Ù×÷
+ sem_buf.sem_flg = SEM_UNDO; //ϵͳÍ˳öǰδÊÍ·ÅÐźÅÁ¿£¬ÏµÍ³×Ô¶¯ÊÍ·Å
+ if (semop(sem_id, &sem_buf, 1) == -1) {
+ return -1;
+ }
+ return 0;
+}
+
+// ¶Ôsem_idÖ´ÐÐV²Ù×÷
+int sem_v(int sem_id)
+{
+ struct sembuf sem_buf;
+ sem_buf.sem_num = 0;
+ sem_buf.sem_op = 1; //V²Ù×÷
+ sem_buf.sem_flg = SEM_UNDO;
+ if (semop(sem_id, &sem_buf, 1) == -1) {
+ return -1;
+ }
+ return 0;
+}
+